15 #include <arpa/inet.h> 16 #include <netinet/in.h> 17 #include <netinet/tcp.h> 26 int sockoptflag = (activate ? 1 : 0);
30 &sockoptflag,
sizeof(sockoptflag)) != 0)
32 LOG <<
"Cannot set SO_KEEPALIVE on socket fd " <<
fd_ 33 <<
": " << strerror(errno);
40 int sockoptflag = (activate ? 1 : 0);
45 &sockoptflag,
sizeof(sockoptflag)) != 0)
47 LOG <<
"Cannot set SO_REUSEPORT on socket fd " <<
fd_ 48 <<
": " << strerror(errno);
52 &sockoptflag,
sizeof(sockoptflag)) != 0)
54 LOG <<
"Cannot set SO_REUSEADDR on socket fd " <<
fd_ 55 <<
": " << strerror(errno);
63 #if __linux__ || __FreeBSD__ || __APPLE__ 64 int sockoptflag = (activate ? 1 : 0);
73 &sockoptflag,
sizeof(sockoptflag)) != 0)
75 LOG <<
"Cannot set TCP_NODELAY on socket fd " <<
fd_ 76 <<
": " << strerror(errno);
84 #if __linux__ || __FreeBSD__ || __APPLE__ 86 int sockoptflag =
static_cast<int>(size);
98 &sockoptflag,
sizeof(sockoptflag)) != 0)
100 LOG <<
"Cannot set SO_SNDBUF on socket fd " <<
fd_ 101 <<
": " << strerror(errno);
109 #if __linux__ || __FreeBSD__ || __APPLE__ 111 int sockoptflag =
static_cast<int>(size);
123 &sockoptflag,
sizeof(sockoptflag)) != 0)
125 LOG <<
"Cannot set SO_RCVBUF on socket fd " <<
fd_ 126 <<
": " << strerror(errno);
void SetRcvBuf(size_t size)
Set SO_RCVBUF socket option.
int fd_
the file descriptor of the socket.
void SetKeepAlive(bool activate=true)
Enable sending of keep-alive messages on connection-oriented sockets.
void SetReuseAddr(bool activate=true)
void SetSndBuf(size_t size)
Set SO_SNDBUF socket option.
void SetNoDelay(bool activate=true)
#define LOG
Default logging method: output if the local debug variable is true.
int setsockopt(int level, int optname, const void *optval, socklen_t optlen)
Perform raw setsockopt() operation on socket.
bool IsValid() const
Check whether the contained file descriptor is valid.