17#include <netinet/tcp.h>
20#include <netinet/in.h>
25template <
typename Option>
27SetSocketOption(
const int fd,
const int level,
const int optName,
const Option &optValue)
29 static_assert(std::is_trivially_copyable<Option>::value,
"setsockopt() expects POD-like options");
30 static_assert(!std::is_same<Option, bool>::value,
"setsockopt() uses int to represent boolean options");
31 if (
xsetsockopt(fd, level, optName, &optValue,
sizeof(optValue)) < 0) {
32 const auto xerrno = errno;
44 const int optValue = enable ? 1 :0;
54#if defined(TCP_KEEPCNT)
60#if defined(TCP_KEEPIDLE)
66#if defined(TCP_KEEPINTVL)
static bool SetSocketOption(const int fd, const int level, const int optName, const Option &optValue)
xsetsockopt(2) wrapper
static bool SetBooleanSocketOption(const int fd, const int level, const int optName, const bool enable)
setsockopt(2) wrapper for setting typical on/off options
Configuration settings for the TCP keep-alive feature.
#define debugs(SECTION, LEVEL, CONTENT)
void ApplyTcpKeepAlive(int fd, const TcpKeepAlive &)
apply configured TCP keep-alive settings to the given FD socket
int xsetsockopt(int socketFd, int level, int option, const void *value, socklen_t valueLength)
POSIX setsockopt(2) equivalent.
const char * xstrerr(int error)