commit 56cccc6da257000049292016e1bda822c3934967
parent 947ab9361f6ed36141ff4adfc8265b728d0f2cf9
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
Date: Fri, 14 Oct 2016 16:50:18 +0300
epoll FD is not MHD_socket type, adjust and unify usage
Diffstat:
3 files changed, 15 insertions(+), 6 deletions(-)
diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c
@@ -2540,7 +2540,7 @@ MHD_cleanup_connections (struct MHD_Daemon *daemon)
pos);
pos->epoll_state &= ~MHD_EPOLL_STATE_IN_EREADY_EDLL;
}
- if ( (MHD_INVALID_SOCKET != daemon->epoll_fd) &&
+ if ( (-1 != daemon->epoll_fd) &&
(0 != (pos->epoll_state & MHD_EPOLL_STATE_IN_EPOLL_SET)) )
{
/* epoll documentation suggests that closing a FD
@@ -3402,7 +3402,7 @@ MHD_epoll (struct MHD_Daemon *daemon,
}
#if HTTPS_SUPPORT
if ( (MHD_NO == daemon->upgrade_fd_in_epoll) &&
- (MHD_INVALID_SOCKET != daemon->epoll_upgrade_fd) )
+ (-1 != daemon->epoll_upgrade_fd) )
{
event.events = EPOLLIN | EPOLLOUT;
event.data.ptr = (void *) upgrade_marker;
@@ -4298,7 +4298,7 @@ setup_epoll_to_listen (struct MHD_Daemon *daemon)
struct epoll_event event;
daemon->epoll_fd = setup_epoll_fd (daemon);
- if (MHD_INVALID_SOCKET == daemon->epoll_fd)
+ if (-1 == daemon->epoll_fd)
return MHD_NO;
#if HTTPS_SUPPORT
if (MHD_USE_TLS_EPOLL_UPGRADE == (MHD_USE_TLS_EPOLL_UPGRADE & daemon->options))
@@ -5310,10 +5310,10 @@ MHD_stop_daemon (struct MHD_Daemon *daemon)
MHD_mutex_destroy_chk_ (&daemon->worker_pool[i].cleanup_connection_mutex);
#ifdef EPOLL_SUPPORT
if (-1 != daemon->worker_pool[i].epoll_fd)
- MHD_socket_close_chk_ (daemon->worker_pool[i].epoll_fd);
+ MHD_fd_close_chk_ (daemon->worker_pool[i].epoll_fd);
#if HTTPS_SUPPORT
if (-1 != daemon->worker_pool[i].epoll_upgrade_fd)
- MHD_socket_close_chk_ (daemon->worker_pool[i].epoll_upgrade_fd);
+ MHD_fd_close_chk_ (daemon->worker_pool[i].epoll_upgrade_fd);
#endif
#endif
/* Individual ITCs are always used */
diff --git a/src/microhttpd/internal.h b/src/microhttpd/internal.h
@@ -66,6 +66,15 @@
/**
+ * Close FD and abort execution if error is detected.
+ * @param fd the FD to close
+ */
+#define MHD_fd_close_chk_(fd) do { \
+ if (0 == close ((fd)) && (EBADF == errno)) \
+ MHD_PANIC(_("Failed to close FD.\n")); \
+ } while(0)
+
+/**
* Should we perform additional sanity checks at runtime (on our internal
* invariants)? This may lead to aborts, but can be useful for debugging.
*/
diff --git a/src/microhttpd/response.c b/src/microhttpd/response.c
@@ -808,7 +808,7 @@ MHD_response_execute_upgrade_ (struct MHD_Response *response,
to the event set of the daemon's `epoll_upgrade_fd` */
struct epoll_event event;
- EXTRA_CHECK (MHD_SOCKET_INVALID != daemon->epoll_upgrade_fd);
+ EXTRA_CHECK (-1 != daemon->epoll_upgrade_fd);
/* First, add network socket */
event.events = EPOLLIN | EPOLLOUT;
event.data.ptr = &urh->app;