Signed-off-by: Dan McGee <d...@archlinux.org> --- src/server_socket.c | 2 +- src/socket_util.c | 6 ++++-- src/socket_util.h | 10 +++++++++- 3 files changed, 14 insertions(+), 4 deletions(-)
diff --git a/src/server_socket.c b/src/server_socket.c index fc8dbd1..e68b595 100644 --- a/src/server_socket.c +++ b/src/server_socket.c @@ -161,7 +161,7 @@ server_socket_in_event(G_GNUC_UNUSED GIOChannel *source, int fd = accept_cloexec_nonblock(s->fd, (struct sockaddr*)&address, &address_length); if (fd >= 0) { - if (socket_keepalive(fd)) + if (!socket_keepalive(fd)) g_warning("Could not set TCP keepalive option: %s", g_strerror(errno)); s->parent->callback(fd, (const struct sockaddr*)&address, diff --git a/src/socket_util.c b/src/socket_util.c index aa0a44e..d64d0eb 100644 --- a/src/socket_util.c +++ b/src/socket_util.c @@ -149,10 +149,11 @@ socket_bind_listen(int domain, int type, int protocol, return fd; } -int +bool socket_keepalive(int fd) { const int reuse = 1; + int ret; #ifdef WIN32 const char *optval = (const char *)&reuse; @@ -160,6 +161,7 @@ socket_keepalive(int fd) const void *optval = &reuse; #endif - return setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, + ret = setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, optval, sizeof(reuse)); + return ret == 0 ? true : false; } diff --git a/src/socket_util.h b/src/socket_util.h index f27751a..518213f 100644 --- a/src/socket_util.h +++ b/src/socket_util.h @@ -28,6 +28,8 @@ #include <glib.h> +#include <stdbool.h> + struct sockaddr; /** @@ -63,7 +65,13 @@ socket_bind_listen(int domain, int type, int protocol, int backlog, GError **error); -int +/** + * Attempt to set the socket keepalive option on the given fd. + * + * @param fd the fd for an accepted incoming connection + * @return true on success, false on failure + */ +bool socket_keepalive(int fd); #endif -- 1.7.6.1 ------------------------------------------------------------------------------ BlackBerry® DevCon Americas, Oct. 18-20, San Francisco, CA Learn about the latest advances in developing for the BlackBerry® mobile platform with sessions, labs & more. See new tools and technologies. Register for BlackBerry® DevCon today! http://p.sf.net/sfu/rim-devcon-copy1 _______________________________________________ Musicpd-dev-team mailing list Musicpd-dev-team@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/musicpd-dev-team