From 61fa3896442b5629e28d36d4e9e924440e03d873 Mon Sep 17 00:00:00 2001 From: "Evgeny Grin (Karlson2k)" Date: Fri, 16 Apr 2021 17:11:21 +0300 Subject: Fixes and improvements for 6c751386a2e06d35b6d072c064bd581ddd561c52 Fixed build on platforms without epoll, saved one sys-call for externally added connections. --- src/microhttpd/daemon.c | 57 ++++++++++++++++++++++--------------------------- 1 file changed, 25 insertions(+), 32 deletions(-) (limited to 'src/microhttpd/daemon.c') diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c index fde1703d..294ed722 100644 --- a/src/microhttpd/daemon.c +++ b/src/microhttpd/daemon.c @@ -2376,7 +2376,7 @@ psk_gnutls_adapter (gnutls_session_t session, * @param non_blck indicate that socket in non-blocking mode * @param sk_spipe_supprs indicate that the @a client_socket has * set SIGPIPE suppression - * @param sk_is_unix true if this is a UNIX domain socket (AF_UNIX) + * @param sk_is_nonip _MHD_YES if this is not a TCP/IP socket * @return pointer to the connection on success, NULL if this daemon could * not handle the connection (i.e. malloc failed, etc). * The socket will be closed in case of error; 'errno' is @@ -2390,7 +2390,7 @@ new_connection_prepare_ (struct MHD_Daemon *daemon, bool external_add, bool non_blck, bool sk_spipe_supprs, - bool sk_is_unix) + enum MHD_tristate sk_is_nonip) { struct MHD_Connection *connection; int eno = 0; @@ -2492,7 +2492,7 @@ new_connection_prepare_ (struct MHD_Daemon *daemon, connection->addr_len = addrlen; connection->socket_fd = client_socket; connection->sk_nonblck = non_blck; - connection->is_unix = sk_is_unix; + connection->is_nonip = sk_is_nonip; connection->sk_spipe_suppress = sk_spipe_supprs; connection->daemon = daemon; connection->last_activity = MHD_monotonic_sec_counter (); @@ -2863,7 +2863,7 @@ cleanup: * @param non_blck indicate that socket in non-blocking mode * @param sk_spipe_supprs indicate that the @a client_socket has * set SIGPIPE suppression - * @param sk_is_unix true if this is a UNIX domain socket (AF_UNIX) + * @param sk_is_nonip _MHD_YES if this is not a TCP/IP socket * @return #MHD_YES on success, #MHD_NO if this daemon could * not handle the connection (i.e. malloc failed, etc). * The socket will be closed in any case; 'errno' is @@ -2877,7 +2877,7 @@ internal_add_connection (struct MHD_Daemon *daemon, bool external_add, bool non_blck, bool sk_spipe_supprs, - bool sk_is_unix) + enum MHD_tristate sk_is_nonip) { struct MHD_Connection *connection; @@ -2923,7 +2923,7 @@ internal_add_connection (struct MHD_Daemon *daemon, external_add, non_blck, sk_spipe_supprs, - sk_is_unix); + sk_is_nonip); if (NULL == connection) return MHD_NO; @@ -3348,7 +3348,6 @@ MHD_add_connection (struct MHD_Daemon *daemon, { bool sk_nonbl; bool sk_spipe_supprs; - bool sk_is_unix = false; /* NOT thread safe with internal thread. TODO: fix thread safety. */ if ((0 == (daemon->options & MHD_USE_INTERNAL_POLLING_THREAD)) && @@ -3419,20 +3418,6 @@ MHD_add_connection (struct MHD_Daemon *daemon, _ ("Failed to set noninheritable mode on new client socket.\n")); #endif } -#ifdef SO_DOMAIN - { - int af; - socklen_t len = sizeof (af); - - if ( (0 == getsockopt (daemon->listen_fd, - SOL_SOCKET, - SO_DOMAIN, - &af, - &len)) && - (AF_UNIX == af) ) - sk_is_unix = true; - } -#endif #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) if (NULL != daemon->worker_pool) @@ -3453,7 +3438,7 @@ MHD_add_connection (struct MHD_Daemon *daemon, true, sk_nonbl, sk_spipe_supprs, - sk_is_unix); + _MHD_UNKNOWN); } /* all pools are at their connection limit, must refuse */ MHD_socket_close_chk_ (client_socket); @@ -3471,7 +3456,7 @@ MHD_add_connection (struct MHD_Daemon *daemon, true, sk_nonbl, sk_spipe_supprs, - sk_is_unix); + _MHD_UNKNOWN); } @@ -5840,20 +5825,25 @@ parse_options_va (struct MHD_Daemon *daemon, { daemon->listen_fd = va_arg (ap, MHD_socket); -#ifdef SO_DOMAIN +#if defined(SO_DOMAIN) && defined(AF_UNIX) { int af; socklen_t len = sizeof (af); - if ( (0 == getsockopt (daemon->listen_fd, - SOL_SOCKET, - SO_DOMAIN, - &af, - &len)) && - (AF_UNIX == af) ) - daemon->listen_is_unix = true; + if (0 == getsockopt (daemon->listen_fd, + SOL_SOCKET, + SO_DOMAIN, + &af, + &len)) + { + daemon->listen_is_unix = (AF_UNIX == af) ? _MHD_YES : MHD_NO; + } + else + daemon->listen_is_unix = _MHD_UNKNOWN; } -#endif +#else /* ! SO_DOMAIN || ! AF_UNIX */ + daemon->listen_is_unix = _MHD_UNKNOWN; +#endif /* ! SO_DOMAIN || ! AF_UNIX */ } break; case MHD_OPTION_EXTERNAL_LOGGER: @@ -6342,6 +6332,7 @@ MHD_start_daemon_va (unsigned int flags, } #endif /* HTTPS_SUPPORT */ daemon->listen_fd = MHD_INVALID_SOCKET; + daemon->listen_is_unix = _MHD_NO; daemon->listening_address_reuse = 0; daemon->options = *pflags; pflags = &daemon->options; @@ -6722,6 +6713,8 @@ MHD_start_daemon_va (unsigned int flags, servaddr = (struct sockaddr *) &servaddr4; } } + else + daemon->listen_is_unix = _MHD_UNKNOWN; daemon->listen_fd = listen_fd; if (0 != (*pflags & MHD_USE_IPv6)) { -- cgit v1.2.3