diff options
author | Max Kellermann <max@musicpd.org> | 2017-08-10 19:25:02 +0200 |
---|---|---|
committer | Max Kellermann <max@musicpd.org> | 2017-08-10 19:25:02 +0200 |
commit | 1f47dc990d8ffc948f3f931aff496dfcc9b0c569 (patch) | |
tree | 6219655f2f4352cfdb29dfdf4b9677fdd45104bc /src/net | |
parent | 9a5bcc6db0c58459b63d25fede1945b7ebef67a8 (diff) |
net/SocketDescriptor: add method SetKeepAlive()
Diffstat (limited to 'src/net')
-rw-r--r-- | src/net/SocketDescriptor.cxx | 6 | ||||
-rw-r--r-- | src/net/SocketDescriptor.hxx | 1 | ||||
-rw-r--r-- | src/net/SocketUtil.cxx | 9 | ||||
-rw-r--r-- | src/net/SocketUtil.hxx | 3 |
4 files changed, 7 insertions, 12 deletions
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 |