Commit 1f47dc99 authored by Max Kellermann's avatar Max Kellermann

net/SocketDescriptor: add method SetKeepAlive()

parent 9a5bcc6d
......@@ -158,7 +158,7 @@ OneServerSocket::Accept() noexcept
return;
}
if (socket_keepalive(peer_fd.Get())) {
if (!peer_fd.SetKeepAlive()) {
const SocketErrorMessage msg;
FormatError(server_socket_domain,
"Could not set TCP keepalive option: %s",
......
......@@ -207,6 +207,12 @@ SocketDescriptor::SetOption(int level, int name,
}
bool
SocketDescriptor::SetKeepAlive(bool value)
{
return SetBoolOption(SOL_SOCKET, SO_KEEPALIVE, value);
}
bool
SocketDescriptor::SetReuseAddress(bool value)
{
return SetBoolOption(SOL_SOCKET, SO_REUSEADDR, value);
......
......@@ -141,6 +141,7 @@ public:
return SetOption(level, name, &value, sizeof(value));
}
bool SetKeepAlive(bool value=true);
bool SetReuseAddress(bool value=true);
#ifdef __linux__
......
......@@ -49,12 +49,3 @@ socket_bind_listen(int domain, int type, int protocol,
return fd;
}
int
socket_keepalive(int fd)
{
const int reuse = 1;
return setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE,
(const char *)&reuse, sizeof(reuse));
}
......@@ -49,7 +49,4 @@ socket_bind_listen(int domain, int type, int protocol,
SocketAddress address,
int backlog);
int
socket_keepalive(int fd);
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment