summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Kellermann <max@musicpd.org>2017-08-10 19:25:02 +0200
committerMax Kellermann <max@musicpd.org>2017-08-10 19:25:02 +0200
commit1f47dc990d8ffc948f3f931aff496dfcc9b0c569 (patch)
tree6219655f2f4352cfdb29dfdf4b9677fdd45104bc
parent9a5bcc6db0c58459b63d25fede1945b7ebef67a8 (diff)
net/SocketDescriptor: add method SetKeepAlive()
-rw-r--r--src/event/ServerSocket.cxx2
-rw-r--r--src/net/SocketDescriptor.cxx6
-rw-r--r--src/net/SocketDescriptor.hxx1
-rw-r--r--src/net/SocketUtil.cxx9
-rw-r--r--src/net/SocketUtil.hxx3
5 files changed, 8 insertions, 13 deletions
diff --git a/src/event/ServerSocket.cxx b/src/event/ServerSocket.cxx
index 85cf93dbe..55000318f 100644
--- a/src/event/ServerSocket.cxx
+++ b/src/event/ServerSocket.cxx
@@ -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",
diff --git a/src/net/SocketDescriptor.cxx b/src/net/SocketDescriptor.cxx
index 9a3b97c9d..6c31616b2 100644
--- a/src/net/SocketDescriptor.cxx
+++ b/src/net/SocketDescriptor.cxx
@@ -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);
diff --git a/src/net/SocketDescriptor.hxx b/src/net/SocketDescriptor.hxx
index 6b2c6bdfa..bc2d86d16 100644
--- a/src/net/SocketDescriptor.hxx
+++ b/src/net/SocketDescriptor.hxx
@@ -141,6 +141,7 @@ public:
return SetOption(level, name, &value, sizeof(value));
}
+ bool SetKeepAlive(bool value=true);
bool SetReuseAddress(bool value=true);
#ifdef __linux__
diff --git a/src/net/SocketUtil.cxx b/src/net/SocketUtil.cxx
index ab029cdea..aaf7e1351 100644
--- a/src/net/SocketUtil.cxx
+++ b/src/net/SocketUtil.cxx
@@ -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));
-}
diff --git a/src/net/SocketUtil.hxx b/src/net/SocketUtil.hxx
index 55d3bb621..a8ae998a4 100644
--- a/src/net/SocketUtil.hxx
+++ b/src/net/SocketUtil.hxx
@@ -49,7 +49,4 @@ socket_bind_listen(int domain, int type, int protocol,
SocketAddress address,
int backlog);
-int
-socket_keepalive(int fd);
-
#endif