From 46deb7ca8298084b6169ac6349b24797e35623a7 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 19 Sep 2011 21:02:29 +0200 Subject: fd_util: include check.h, verify config.h was included --- src/fd_util.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/fd_util.h') diff --git a/src/fd_util.h b/src/fd_util.h index 5b80df2c..647860a9 100644 --- a/src/fd_util.h +++ b/src/fd_util.h @@ -36,6 +36,8 @@ #ifndef FD_UTIL_H #define FD_UTIL_H +#include "check.h" + #include #include -- cgit v1.2.3 From 77a56c7c5a1ab6bc0d76e0cf55f24071be7c4b5f Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 19 Sep 2011 21:03:08 +0200 Subject: fd_util: check HAVE_INOTIFY_INIT in header Don't provide the prototype if inotify_init() was not detected. --- src/fd_util.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/fd_util.h') diff --git a/src/fd_util.h b/src/fd_util.h index 647860a9..3d465b20 100644 --- a/src/fd_util.h +++ b/src/fd_util.h @@ -122,6 +122,8 @@ recvmsg_cloexec(int sockfd, struct msghdr *msg, int flags); #endif +#ifdef HAVE_INOTIFY_INIT + /** * Wrapper for inotify_init(), which sets the CLOEXEC flag (atomically * if supported by the OS). @@ -130,3 +132,5 @@ int inotify_init_cloexec(void); #endif + +#endif -- cgit v1.2.3 From c476819cb1186770b1b7395851e394caac39cbc8 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 19 Sep 2011 21:04:19 +0200 Subject: fd_util: add function close_socket() Wrap close(), use closesocket() on WIN32/WinSock. --- NEWS | 1 + src/client_new.c | 5 +++-- src/fd_util.c | 10 ++++++++++ src/fd_util.h | 6 ++++++ src/output/httpd_output_plugin.c | 4 ++-- src/server_socket.c | 2 +- src/socket_util.c | 6 +++--- 7 files changed, 26 insertions(+), 8 deletions(-) (limited to 'src/fd_util.h') diff --git a/NEWS b/NEWS index af731536..2f1907cd 100644 --- a/NEWS +++ b/NEWS @@ -9,6 +9,7 @@ ver 0.16.5 (2010/??/??) * decoder: - ffmpeg: higher precision timestamps - ffmpeg: don't require key frame for seeking +* WIN32: close sockets properly ver 0.16.4 (2011/09/01) diff --git a/src/client_new.c b/src/client_new.c index 0ee21916..e764a655 100644 --- a/src/client_new.c +++ b/src/client_new.c @@ -19,6 +19,7 @@ #include "config.h" #include "client_internal.h" +#include "fd_util.h" #include "fifo_buffer.h" #include "socket_util.h" #include "permission.h" @@ -67,7 +68,7 @@ void client_new(int fd, const struct sockaddr *sa, size_t sa_length, int uid) progname, hostaddr); g_free(hostaddr); - close(fd); + close_socket(fd); return; } @@ -77,7 +78,7 @@ void client_new(int fd, const struct sockaddr *sa, size_t sa_length, int uid) if (client_list_is_full()) { g_warning("Max Connections Reached!"); - close(fd); + close_socket(fd); return; } diff --git a/src/fd_util.c b/src/fd_util.c index 1f3004d0..4636c19e 100644 --- a/src/fd_util.c +++ b/src/fd_util.c @@ -304,3 +304,13 @@ inotify_init_cloexec(void) } #endif + +int +close_socket(int fd) +{ +#ifdef WIN32 + return closesocket(fd); +#else + return close(fd); +#endif +} diff --git a/src/fd_util.h b/src/fd_util.h index 3d465b20..d74bb30d 100644 --- a/src/fd_util.h +++ b/src/fd_util.h @@ -133,4 +133,10 @@ inotify_init_cloexec(void); #endif +/** + * Portable wrapper for close(); use closesocket() on WIN32/WinSock. + */ +int +close_socket(int fd); + #endif diff --git a/src/output/httpd_output_plugin.c b/src/output/httpd_output_plugin.c index 40ad05c3..2c140a30 100644 --- a/src/output/httpd_output_plugin.c +++ b/src/output/httpd_output_plugin.c @@ -201,7 +201,7 @@ httpd_listen_in_event(int fd, const struct sockaddr *address, g_warning("libwrap refused connection (libwrap=%s) from %s", progname, hostaddr); g_free(hostaddr); - close(fd); + close_socket(fd); g_mutex_unlock(httpd->mutex); return; } @@ -222,7 +222,7 @@ httpd_listen_in_event(int fd, const struct sockaddr *address, httpd->clients_cnt < httpd->clients_max)) httpd_client_add(httpd, fd); else - close(fd); + close_socket(fd); } else if (fd < 0 && errno != EINTR) { g_warning("accept() failed: %s", g_strerror(errno)); } diff --git a/src/server_socket.c b/src/server_socket.c index c1074067..b4114d2d 100644 --- a/src/server_socket.c +++ b/src/server_socket.c @@ -253,7 +253,7 @@ server_socket_close(struct server_socket *ss) continue; g_source_remove(s->source_id); - close(s->fd); + close_socket(s->fd); s->fd = -1; } } diff --git a/src/socket_util.c b/src/socket_util.c index 0909765b..3f7075ed 100644 --- a/src/socket_util.c +++ b/src/socket_util.c @@ -122,7 +122,7 @@ socket_bind_listen(int domain, int type, int protocol, if (ret < 0) { g_set_error(error, listen_quark(), errno, "setsockopt() failed: %s", g_strerror(errno)); - close(fd); + close_socket(fd); return -1; } @@ -130,7 +130,7 @@ socket_bind_listen(int domain, int type, int protocol, if (ret < 0) { g_set_error(error, listen_quark(), errno, "%s", g_strerror(errno)); - close(fd); + close_socket(fd); return -1; } @@ -138,7 +138,7 @@ socket_bind_listen(int domain, int type, int protocol, if (ret < 0) { g_set_error(error, listen_quark(), errno, "listen() failed: %s", g_strerror(errno)); - close(fd); + close_socket(fd); return -1; } -- cgit v1.2.3