33 lines
460 B
C++
33 lines
460 B
C++
/*
|
||
* socket.cpp
|
||
*
|
||
* Created on: 5 сент. 2022 г.
|
||
* Author: alexander
|
||
*/
|
||
|
||
#include <socket.hpp>
|
||
#include <unistd.h>
|
||
|
||
namespace zh {
|
||
|
||
Socket::Socket(const int domain, const int type, const int protocol)
|
||
{
|
||
if ((_sockfd = socket(domain, type, protocol)) < 0)
|
||
{
|
||
perror("socket creation failed");
|
||
exit(EXIT_FAILURE);
|
||
}
|
||
}
|
||
|
||
Socket::operator int() const
|
||
{
|
||
return _sockfd;
|
||
}
|
||
|
||
Socket::~Socket()
|
||
{
|
||
::close(_sockfd);
|
||
}
|
||
|
||
}
|