net/SocketDescriptor: add method SetKeepAlive()
This commit is contained in:
parent
9a5bcc6db0
commit
1f47dc990d
@ -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",
|
||||
|
@ -206,6 +206,12 @@ SocketDescriptor::SetOption(int level, int name,
|
||||
return setsockopt(fd, level, name, (const char *)value, size) == 0;
|
||||
}
|
||||
|
||||
bool
|
||||
SocketDescriptor::SetKeepAlive(bool value)
|
||||
{
|
||||
return SetBoolOption(SOL_SOCKET, SO_KEEPALIVE, value);
|
||||
}
|
||||
|
||||
bool
|
||||
SocketDescriptor::SetReuseAddress(bool 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
|
||||
|
Loading…
Reference in New Issue
Block a user