diff options
author | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2016-08-23 20:13:23 +0000 |
---|---|---|
committer | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2016-08-23 20:13:23 +0000 |
commit | b6d29e0cb35aeb2df21f2e959a93ca0552951009 (patch) | |
tree | 02db574a6e238a042c1a935f8be4b355c4853c4b | |
parent | 16a4b0b527e56e9b7268bfd921646bfd722e56bb (diff) |
Moved add_to_fd_set() to mhd_sockets.c, simplified return value
-rw-r--r-- | src/microhttpd/daemon.c | 79 | ||||
-rw-r--r-- | src/microhttpd/mhd_sockets.c | 29 | ||||
-rw-r--r-- | src/microhttpd/mhd_sockets.h | 17 |
3 files changed, 69 insertions, 56 deletions
diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c index eef9eca8..105f3083 100644 --- a/src/microhttpd/daemon.c +++ b/src/microhttpd/daemon.c @@ -634,34 +634,6 @@ MHD_TLS_init (struct MHD_Daemon *daemon) #endif -/** - * Add @a fd to the @a set. If @a fd is - * greater than @a max_fd, set @a max_fd to @a fd. - * - * @param fd file descriptor to add to the @a set - * @param set set to modify - * @param max_fd maximum value to potentially update - * @param fd_setsize value of FD_SETSIZE - * @return #MHD_YES on success, #MHD_NO otherwise - */ -static int -add_to_fd_set (MHD_socket fd, - fd_set *set, - MHD_socket *max_fd, - unsigned int fd_setsize) -{ - if (NULL == set || MHD_INVALID_SOCKET == fd) - return MHD_NO; - if (!MHD_SCKT_FD_FITS_FDSET_SETSIZE_(fd, set, fd_setsize)) - return MHD_NO; - MHD_SCKT_ADD_FD_TO_FDSET_SETSIZE_(fd, set, fd_setsize); - if ( (NULL != max_fd) && - ((fd > *max_fd) || (MHD_INVALID_SOCKET == *max_fd)) ) - *max_fd = fd; - - return MHD_YES; -} - #undef MHD_get_fdset /** @@ -740,11 +712,11 @@ MHD_get_fdset2 (struct MHD_Daemon *daemon, /* we're in epoll mode, use the epoll FD as a stand-in for the entire event set */ - return add_to_fd_set (daemon->epoll_fd, read_fd_set, max_fd, fd_setsize); + return MHD_add_to_fd_set_ (daemon->epoll_fd, read_fd_set, max_fd, fd_setsize) ? MHD_YES : MHD_NO; } #endif if (MHD_INVALID_SOCKET != daemon->socket_fd && - MHD_YES != add_to_fd_set (daemon->socket_fd, read_fd_set, max_fd, fd_setsize)) + !MHD_add_to_fd_set_ (daemon->socket_fd, read_fd_set, max_fd, fd_setsize)) result = MHD_NO; for (pos = daemon->connections_head; NULL != pos; pos = pos->next) @@ -752,19 +724,19 @@ MHD_get_fdset2 (struct MHD_Daemon *daemon, switch (pos->event_loop_info) { case MHD_EVENT_LOOP_INFO_READ: - if (MHD_YES != add_to_fd_set (pos->socket_fd, read_fd_set, max_fd, fd_setsize)) + if (!MHD_add_to_fd_set_ (pos->socket_fd, read_fd_set, max_fd, fd_setsize)) result = MHD_NO; break; case MHD_EVENT_LOOP_INFO_WRITE: - if (MHD_YES != add_to_fd_set (pos->socket_fd, write_fd_set, max_fd, fd_setsize)) + if (!MHD_add_to_fd_set_ (pos->socket_fd, write_fd_set, max_fd, fd_setsize)) result = MHD_NO; if (pos->read_buffer_size > pos->read_buffer_offset && - MHD_YES != add_to_fd_set (pos->socket_fd, read_fd_set, max_fd, fd_setsize)) + !MHD_add_to_fd_set_ (pos->socket_fd, read_fd_set, max_fd, fd_setsize)) result = MHD_NO; break; case MHD_EVENT_LOOP_INFO_BLOCK: if (pos->read_buffer_size > pos->read_buffer_offset && - MHD_YES != add_to_fd_set (pos->socket_fd, read_fd_set, max_fd, fd_setsize)) + !MHD_add_to_fd_set_ (pos->socket_fd, read_fd_set, max_fd, fd_setsize)) result = MHD_NO; break; case MHD_EVENT_LOOP_INFO_CLEANUP: @@ -915,23 +887,19 @@ MHD_handle_connection (void *data) switch (con->event_loop_info) { case MHD_EVENT_LOOP_INFO_READ: - if (MHD_YES != - add_to_fd_set (con->socket_fd, &rs, &maxsock, FD_SETSIZE)) + if (!MHD_add_to_fd_set_ (con->socket_fd, &rs, &maxsock, FD_SETSIZE)) err_state = 1; break; case MHD_EVENT_LOOP_INFO_WRITE: - if (MHD_YES != - add_to_fd_set (con->socket_fd, &ws, &maxsock, FD_SETSIZE)) + if (!MHD_add_to_fd_set_ (con->socket_fd, &ws, &maxsock, FD_SETSIZE)) err_state = 1; if ( (con->read_buffer_size > con->read_buffer_offset) && - (MHD_YES != - add_to_fd_set (con->socket_fd, &rs, &maxsock, FD_SETSIZE)) ) + (!MHD_add_to_fd_set_ (con->socket_fd, &rs, &maxsock, FD_SETSIZE)) ) err_state = 1; break; case MHD_EVENT_LOOP_INFO_BLOCK: if ( (con->read_buffer_size > con->read_buffer_offset) && - (MHD_YES != - add_to_fd_set (con->socket_fd, &rs, &maxsock, FD_SETSIZE)) ) + (!MHD_add_to_fd_set_ (con->socket_fd, &rs, &maxsock, FD_SETSIZE)) ) err_state = 1; tv.tv_sec = 0; tv.tv_usec = 0; @@ -944,8 +912,7 @@ MHD_handle_connection (void *data) #if WINDOWS if (MHD_INVALID_PIPE_ != spipe) { - if (MHD_YES != - add_to_fd_set (spipe, &rs, &maxsock, FD_SETSIZE)) + if (!MHD_add_to_fd_set_ (spipe, &rs, &maxsock, FD_SETSIZE)) err_state = 1; } #endif @@ -2339,10 +2306,10 @@ MHD_select (struct MHD_Daemon *daemon, { /* accept only, have one thread per connection */ if ( (MHD_INVALID_SOCKET != daemon->socket_fd) && - (MHD_YES != add_to_fd_set (daemon->socket_fd, - &rs, - &maxsock, - FD_SETSIZE)) ) + (!MHD_add_to_fd_set_ (daemon->socket_fd, + &rs, + &maxsock, + FD_SETSIZE)) ) { #ifdef HAVE_MESSAGES MHD_DLOG (daemon, "Could not add listen socket to fdset"); @@ -2351,10 +2318,10 @@ MHD_select (struct MHD_Daemon *daemon, } } if ( (MHD_INVALID_PIPE_ != daemon->wpipe[0]) && - (MHD_YES != add_to_fd_set (daemon->wpipe[0], - &rs, - &maxsock, - FD_SETSIZE)) ) + (!MHD_add_to_fd_set_ (daemon->wpipe[0], + &rs, + &maxsock, + FD_SETSIZE)) ) { #if defined(MHD_WINSOCK_SOCKETS) /* fdset limit reached, new connections @@ -2363,10 +2330,10 @@ MHD_select (struct MHD_Daemon *daemon, if (MHD_INVALID_SOCKET != daemon->socket_fd) { FD_CLR (daemon->socket_fd, &rs); - if (MHD_YES != add_to_fd_set (daemon->wpipe[0], - &rs, - &maxsock, - FD_SETSIZE)) + if (!MHD_add_to_fd_set_ (daemon->wpipe[0], + &rs, + &maxsock, + FD_SETSIZE)) { #endif /* MHD_WINSOCK_SOCKETS */ #ifdef HAVE_MESSAGES diff --git a/src/microhttpd/mhd_sockets.c b/src/microhttpd/mhd_sockets.c index 643ed849..640c59e3 100644 --- a/src/microhttpd/mhd_sockets.c +++ b/src/microhttpd/mhd_sockets.c @@ -235,3 +235,32 @@ const char* MHD_W32_strerror_winsock_(int err) #endif /* MHD_WINSOCK_SOCKETS */ + + +/** + * Add @a fd to the @a set. If @a fd is + * greater than @a max_fd, set @a max_fd to @a fd. + * + * @param fd file descriptor to add to the @a set + * @param set set to modify + * @param max_fd maximum value to potentially update + * @param fd_setsize value of FD_SETSIZE + * @return non-zero if succeeded, zero otherwise + */ +int +MHD_add_to_fd_set_ (MHD_socket fd, + fd_set *set, + MHD_socket *max_fd, + unsigned int fd_setsize) +{ + if (NULL == set || MHD_INVALID_SOCKET == fd) + return 0; + if (!MHD_SCKT_FD_FITS_FDSET_SETSIZE_(fd, set, fd_setsize)) + return 0; + MHD_SCKT_ADD_FD_TO_FDSET_SETSIZE_(fd, set, fd_setsize); + if ( (NULL != max_fd) && + ((fd > *max_fd) || (MHD_INVALID_SOCKET == *max_fd)) ) + *max_fd = fd; + + return !0; +} diff --git a/src/microhttpd/mhd_sockets.h b/src/microhttpd/mhd_sockets.h index 13b90d2e..4d8444ca 100644 --- a/src/microhttpd/mhd_sockets.h +++ b/src/microhttpd/mhd_sockets.h @@ -569,4 +569,21 @@ # define MHD_socket_set_error_to_ENOMEM() MHD_socket_set_error_(MHD_SCKT_ENOMEM_) #endif +/* Socket functions */ + +/** + * Add @a fd to the @a set. If @a fd is + * greater than @a max_fd, set @a max_fd to @a fd. + * + * @param fd file descriptor to add to the @a set + * @param set set to modify + * @param max_fd maximum value to potentially update + * @param fd_setsize value of FD_SETSIZE + * @return non-zero if succeeded, zero otherwise + */ +int +MHD_add_to_fd_set_ (MHD_socket fd, + fd_set *set, + MHD_socket *max_fd, + unsigned int fd_setsize); #endif /* ! MHD_SOCKETS_H */ |