diff options
-rw-r--r-- | src/microhttpd/daemon.c | 48 | ||||
-rw-r--r-- | src/microhttpd/internal.h | 5 |
2 files changed, 35 insertions, 18 deletions
diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c index 206b1a69..ae6aaeed 100644 --- a/src/microhttpd/daemon.c +++ b/src/microhttpd/daemon.c | |||
@@ -1940,6 +1940,7 @@ MHD_cleanup_connections (struct MHD_Daemon *daemon); | |||
1940 | * @param addrlen number of bytes in @a addr | 1940 | * @param addrlen number of bytes in @a addr |
1941 | * @param external_add perform additional operations needed due | 1941 | * @param external_add perform additional operations needed due |
1942 | * to the application calling us directly | 1942 | * to the application calling us directly |
1943 | * @param non_blck indicate that socket in non-blocking mode | ||
1943 | * @return #MHD_YES on success, #MHD_NO if this daemon could | 1944 | * @return #MHD_YES on success, #MHD_NO if this daemon could |
1944 | * not handle the connection (i.e. malloc failed, etc). | 1945 | * not handle the connection (i.e. malloc failed, etc). |
1945 | * The socket will be closed in any case; 'errno' is | 1946 | * The socket will be closed in any case; 'errno' is |
@@ -1950,7 +1951,8 @@ internal_add_connection (struct MHD_Daemon *daemon, | |||
1950 | MHD_socket client_socket, | 1951 | MHD_socket client_socket, |
1951 | const struct sockaddr *addr, | 1952 | const struct sockaddr *addr, |
1952 | socklen_t addrlen, | 1953 | socklen_t addrlen, |
1953 | int external_add) | 1954 | int external_add, |
1955 | bool non_blck) | ||
1954 | { | 1956 | { |
1955 | struct MHD_Connection *connection; | 1957 | struct MHD_Connection *connection; |
1956 | unsigned int i; | 1958 | unsigned int i; |
@@ -1970,7 +1972,8 @@ internal_add_connection (struct MHD_Daemon *daemon, | |||
1970 | client_socket, | 1972 | client_socket, |
1971 | addr, | 1973 | addr, |
1972 | addrlen, | 1974 | addrlen, |
1973 | external_add); | 1975 | external_add, |
1976 | non_blck); | ||
1974 | } | 1977 | } |
1975 | /* all pools are at their connection limit, must refuse */ | 1978 | /* all pools are at their connection limit, must refuse */ |
1976 | MHD_socket_close_chk_ (client_socket); | 1979 | MHD_socket_close_chk_ (client_socket); |
@@ -2119,6 +2122,7 @@ internal_add_connection (struct MHD_Daemon *daemon, | |||
2119 | addrlen); | 2122 | addrlen); |
2120 | connection->addr_len = addrlen; | 2123 | connection->addr_len = addrlen; |
2121 | connection->socket_fd = client_socket; | 2124 | connection->socket_fd = client_socket; |
2125 | connection->sk_nonblck = non_blck; | ||
2122 | connection->daemon = daemon; | 2126 | connection->daemon = daemon; |
2123 | connection->last_activity = MHD_monotonic_sec_counter(); | 2127 | connection->last_activity = MHD_monotonic_sec_counter(); |
2124 | 2128 | ||
@@ -2581,31 +2585,33 @@ MHD_add_connection (struct MHD_Daemon *daemon, | |||
2581 | const struct sockaddr *addr, | 2585 | const struct sockaddr *addr, |
2582 | socklen_t addrlen) | 2586 | socklen_t addrlen) |
2583 | { | 2587 | { |
2584 | /* internal_add_connection() assume that non-blocking is | 2588 | bool sk_nonbl; |
2585 | already set in MHD_USE_EPOLL_TURBO mode */ | 2589 | if (! MHD_socket_nonblocking_ (client_socket)) |
2586 | if (0 != (daemon->options & MHD_USE_EPOLL_TURBO)) | ||
2587 | { | 2590 | { |
2588 | if (! MHD_socket_nonblocking_ (client_socket)) | ||
2589 | { | ||
2590 | #ifdef HAVE_MESSAGES | 2591 | #ifdef HAVE_MESSAGES |
2591 | MHD_DLOG (daemon, | 2592 | MHD_DLOG (daemon, |
2592 | _("Failed to set nonblocking mode on new client socket: %s\n"), | 2593 | _("Failed to set nonblocking mode on new client socket: %s\n"), |
2593 | MHD_socket_last_strerr_()); | 2594 | MHD_socket_last_strerr_()); |
2594 | #endif | 2595 | #endif |
2595 | } | 2596 | sk_nonbl = 0; |
2596 | if (! MHD_socket_noninheritable_ (client_socket)) | 2597 | } |
2597 | { | 2598 | else |
2599 | sk_nonbl = !0; | ||
2600 | |||
2601 | if ( (0 != (daemon->options & MHD_USE_EPOLL_TURBO)) && | ||
2602 | (! MHD_socket_noninheritable_ (client_socket)) ) | ||
2603 | { | ||
2598 | #ifdef HAVE_MESSAGES | 2604 | #ifdef HAVE_MESSAGES |
2599 | MHD_DLOG (daemon, | 2605 | MHD_DLOG (daemon, |
2600 | _("Failed to set noninheritable mode on new client socket.\n")); | 2606 | _("Failed to set noninheritable mode on new client socket.\n")); |
2601 | #endif | 2607 | #endif |
2602 | } | ||
2603 | } | 2608 | } |
2604 | return internal_add_connection (daemon, | 2609 | return internal_add_connection (daemon, |
2605 | client_socket, | 2610 | client_socket, |
2606 | addr, | 2611 | addr, |
2607 | addrlen, | 2612 | addrlen, |
2608 | MHD_YES); | 2613 | MHD_YES, |
2614 | sk_nonbl); | ||
2609 | } | 2615 | } |
2610 | 2616 | ||
2611 | 2617 | ||
@@ -2635,6 +2641,7 @@ MHD_accept_connection (struct MHD_Daemon *daemon) | |||
2635 | socklen_t addrlen; | 2641 | socklen_t addrlen; |
2636 | MHD_socket s; | 2642 | MHD_socket s; |
2637 | MHD_socket fd; | 2643 | MHD_socket fd; |
2644 | bool sk_nonbl; | ||
2638 | 2645 | ||
2639 | addrlen = sizeof (addrstorage); | 2646 | addrlen = sizeof (addrstorage); |
2640 | memset (addr, | 2647 | memset (addr, |
@@ -2647,10 +2654,12 @@ MHD_accept_connection (struct MHD_Daemon *daemon) | |||
2647 | addr, | 2654 | addr, |
2648 | &addrlen, | 2655 | &addrlen, |
2649 | MAYBE_SOCK_CLOEXEC | MAYBE_SOCK_NONBLOCK); | 2656 | MAYBE_SOCK_CLOEXEC | MAYBE_SOCK_NONBLOCK); |
2657 | sk_nonbl = (MAYBE_SOCK_NONBLOCK != 0); | ||
2650 | #else /* ! USE_ACCEPT4 */ | 2658 | #else /* ! USE_ACCEPT4 */ |
2651 | s = accept (fd, | 2659 | s = accept (fd, |
2652 | addr, | 2660 | addr, |
2653 | &addrlen); | 2661 | &addrlen); |
2662 | sk_nonbl = 0; | ||
2654 | #endif /* ! USE_ACCEPT4 */ | 2663 | #endif /* ! USE_ACCEPT4 */ |
2655 | if ( (MHD_INVALID_SOCKET == s) || | 2664 | if ( (MHD_INVALID_SOCKET == s) || |
2656 | (addrlen <= 0) ) | 2665 | (addrlen <= 0) ) |
@@ -2708,6 +2717,8 @@ MHD_accept_connection (struct MHD_Daemon *daemon) | |||
2708 | MHD_socket_last_strerr_()); | 2717 | MHD_socket_last_strerr_()); |
2709 | #endif | 2718 | #endif |
2710 | } | 2719 | } |
2720 | else | ||
2721 | sk_nonbl = !0; | ||
2711 | #endif /* !USE_ACCEPT4 || !HAVE_SOCK_NONBLOCK */ | 2722 | #endif /* !USE_ACCEPT4 || !HAVE_SOCK_NONBLOCK */ |
2712 | #if !defined(USE_ACCEPT4) || !defined(SOCK_CLOEXEC) | 2723 | #if !defined(USE_ACCEPT4) || !defined(SOCK_CLOEXEC) |
2713 | if (! MHD_socket_noninheritable_ (s)) | 2724 | if (! MHD_socket_noninheritable_ (s)) |
@@ -2729,7 +2740,8 @@ MHD_accept_connection (struct MHD_Daemon *daemon) | |||
2729 | s, | 2740 | s, |
2730 | addr, | 2741 | addr, |
2731 | addrlen, | 2742 | addrlen, |
2732 | MHD_NO); | 2743 | MHD_NO, |
2744 | sk_nonbl); | ||
2733 | return MHD_YES; | 2745 | return MHD_YES; |
2734 | } | 2746 | } |
2735 | 2747 | ||
diff --git a/src/microhttpd/internal.h b/src/microhttpd/internal.h index 2858a347..b6426df0 100644 --- a/src/microhttpd/internal.h +++ b/src/microhttpd/internal.h | |||
@@ -790,6 +790,11 @@ struct MHD_Connection | |||
790 | MHD_socket socket_fd; | 790 | MHD_socket socket_fd; |
791 | 791 | ||
792 | /** | 792 | /** |
793 | * Non-zero if #socket_fd is non-blocking, zero otherwise. | ||
794 | */ | ||
795 | bool sk_nonblck; | ||
796 | |||
797 | /** | ||
793 | * Has this socket been closed for reading (i.e. other side closed | 798 | * Has this socket been closed for reading (i.e. other side closed |
794 | * the connection)? If so, we must completely close the connection | 799 | * the connection)? If so, we must completely close the connection |
795 | * once we are done sending our response (and stop trying to read | 800 | * once we are done sending our response (and stop trying to read |