aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/examples/post_example.c2
-rw-r--r--src/include/microhttpd.h37
-rw-r--r--src/include/platform.h17
-rw-r--r--src/microhttpd/connection.c2
-rw-r--r--src/microhttpd/daemon.c151
-rw-r--r--src/microhttpd/internal.h6
-rw-r--r--src/microhttpd/response.c6
-rw-r--r--src/microhttpd/test_daemon.c2
-rw-r--r--src/testcurl/https/test_empty_response.c2
-rw-r--r--src/testcurl/https/test_https_get_select.c2
-rw-r--r--src/testcurl/https/test_https_time_out.c3
-rw-r--r--src/testcurl/https/test_tls_extensions.c3
-rw-r--r--src/testcurl/perf_get.c2
-rw-r--r--src/testcurl/perf_get_concurrent.c2
-rw-r--r--src/testcurl/test_callback.c4
-rw-r--r--src/testcurl/test_get.c4
-rw-r--r--src/testcurl/test_get_chunked.c2
-rw-r--r--src/testcurl/test_get_response_cleanup.c2
-rw-r--r--src/testcurl/test_get_sendfile.c2
-rw-r--r--src/testcurl/test_large_put.c2
-rw-r--r--src/testcurl/test_parse_cookies.c2
-rw-r--r--src/testcurl/test_post.c2
-rw-r--r--src/testcurl/test_post_loop.c2
-rw-r--r--src/testcurl/test_postform.c2
-rw-r--r--src/testcurl/test_process_arguments.c2
-rw-r--r--src/testcurl/test_process_headers.c2
-rw-r--r--src/testcurl/test_put_chunked.c2
-rw-r--r--src/testcurl/test_quiesce.c10
28 files changed, 161 insertions, 116 deletions
diff --git a/src/examples/post_example.c b/src/examples/post_example.c
index 9f104080..b0aecaac 100644
--- a/src/examples/post_example.c
+++ b/src/examples/post_example.c
@@ -705,7 +705,7 @@ main (int argc, char *const *argv)
705 fd_set rs; 705 fd_set rs;
706 fd_set ws; 706 fd_set ws;
707 fd_set es; 707 fd_set es;
708 int max; 708 MHD_socket max;
709 MHD_UNSIGNED_LONG_LONG mhd_timeout; 709 MHD_UNSIGNED_LONG_LONG mhd_timeout;
710 710
711 if (argc != 2) 711 if (argc != 2)
diff --git a/src/include/microhttpd.h b/src/include/microhttpd.h
index 1f8f6d9f..14fe3b31 100644
--- a/src/include/microhttpd.h
+++ b/src/include/microhttpd.h
@@ -105,12 +105,12 @@ extern "C"
105 "standard" includes won't be used (which might be a good 105 "standard" includes won't be used (which might be a good
106 idea, especially on platforms where they do not exist). */ 106 idea, especially on platforms where they do not exist). */
107#ifndef MHD_PLATFORM_H 107#ifndef MHD_PLATFORM_H
108#include <unistd.h>
109#include <stdarg.h> 108#include <stdarg.h>
110#include <stdint.h> 109#include <stdint.h>
111#ifdef __MINGW32__ 110#if defined(_WIN32) && !defined(__CYGWIN__)
112#include <ws2tcpip.h> 111#include <ws2tcpip.h>
113#else 112#else
113#include <unistd.h>
114#include <sys/time.h> 114#include <sys/time.h>
115#include <sys/types.h> 115#include <sys/types.h>
116#include <sys/socket.h> 116#include <sys/socket.h>
@@ -160,6 +160,23 @@ extern "C"
160#define _MHD_EXTERN extern 160#define _MHD_EXTERN extern
161#endif 161#endif
162 162
163#ifndef MHD_SOCKET_DEFINED
164/**
165 * MHD_socket is type for socket FDs
166 */
167#if !defined(_WIN32) || defined(_SYS_TYPES_FD_SET)
168#define MHD_POSIX_SOCKETS 1
169typedef int MHD_socket;
170#define MHD_INVALID_SOCKET (-1)
171#else /* !defined(_WIN32) || defined(_SYS_TYPES_FD_SET) */
172#define MHD_WINSOCK_SOCKETS 1
173#include <winsock2.h>
174typedef SOCKET MHD_socket;
175#define MHD_INVALID_SOCKET (INVALID_SOCKET)
176#endif /* !defined(_WIN32) || defined(_SYS_TYPES_FD_SET) */
177#define MHD_SOCKET_DEFINED 1
178#endif /* MHD_SOCKET_DEFINED */
179
163/** 180/**
164 * Not all architectures and `printf()`'s support the `long long` type. 181 * Not all architectures and `printf()`'s support the `long long` type.
165 * This gives the ability to replace `long long` with just a `long`, 182 * This gives the ability to replace `long long` with just a `long`,
@@ -948,7 +965,7 @@ union MHD_ConnectionInfo
948 /** 965 /**
949 * Connect socket 966 * Connect socket
950 */ 967 */
951 int connect_fd; 968 MHD_socket connect_fd;
952 969
953 /** 970 /**
954 * GNUtls session handle, of type "gnutls_session_t". 971 * GNUtls session handle, of type "gnutls_session_t".
@@ -1335,14 +1352,14 @@ MHD_start_daemon (unsigned int flags,
1335 * Note that some thread modes require the caller to have passed 1352 * Note that some thread modes require the caller to have passed
1336 * #MHD_USE_PIPE_FOR_SHUTDOWN when using this API. If this daemon is 1353 * #MHD_USE_PIPE_FOR_SHUTDOWN when using this API. If this daemon is
1337 * in one of those modes and this option was not given to 1354 * in one of those modes and this option was not given to
1338 * #MHD_start_daemon, this function will return -1. 1355 * #MHD_start_daemon, this function will return #MHD_INVALID_SOCKET.
1339 * 1356 *
1340 * @param daemon daemon to stop accepting new connections for 1357 * @param daemon daemon to stop accepting new connections for
1341 * @return old listen socket on success, -1 if the daemon was 1358 * @return old listen socket on success, #MHD_INVALID_SOCKET if
1342 * already not listening anymore 1359 * the daemon was already not listening anymore
1343 * @ingroup specialized 1360 * @ingroup specialized
1344 */ 1361 */
1345_MHD_EXTERN int 1362_MHD_EXTERN MHD_socket
1346MHD_quiesce_daemon (struct MHD_Daemon *daemon); 1363MHD_quiesce_daemon (struct MHD_Daemon *daemon);
1347 1364
1348 1365
@@ -1387,7 +1404,7 @@ MHD_stop_daemon (struct MHD_Daemon *daemon);
1387 */ 1404 */
1388_MHD_EXTERN int 1405_MHD_EXTERN int
1389MHD_add_connection (struct MHD_Daemon *daemon, 1406MHD_add_connection (struct MHD_Daemon *daemon,
1390 int client_socket, 1407 MHD_socket client_socket,
1391 const struct sockaddr *addr, 1408 const struct sockaddr *addr,
1392 socklen_t addrlen); 1409 socklen_t addrlen);
1393 1410
@@ -1414,7 +1431,7 @@ MHD_get_fdset (struct MHD_Daemon *daemon,
1414 fd_set *read_fd_set, 1431 fd_set *read_fd_set,
1415 fd_set *write_fd_set, 1432 fd_set *write_fd_set,
1416 fd_set *except_fd_set, 1433 fd_set *except_fd_set,
1417 int *max_fd); 1434 MHD_socket *max_fd);
1418 1435
1419 1436
1420/** 1437/**
@@ -2224,7 +2241,7 @@ union MHD_DaemonInfo
2224 /** 2241 /**
2225 * Listen socket file descriptor 2242 * Listen socket file descriptor
2226 */ 2243 */
2227 int listen_fd; 2244 MHD_socket listen_fd;
2228}; 2245};
2229 2246
2230 2247
diff --git a/src/include/platform.h b/src/include/platform.h
index 6433a2bf..01361f53 100644
--- a/src/include/platform.h
+++ b/src/include/platform.h
@@ -118,4 +118,21 @@
118 118
119#include <plibc.h> 119#include <plibc.h>
120 120
121#ifndef MHD_SOCKET_DEFINED
122/**
123 * MHD_socket is type for socket FDs
124 */
125#if !defined(_WIN32) || defined(_SYS_TYPES_FD_SET)
126#define MHD_POSIX_SOCKETS 1
127typedef int MHD_socket;
128#define MHD_INVALID_SOCKET (-1)
129#else /* !defined(_WIN32) || defined(_SYS_TYPES_FD_SET) */
130#define MHD_WINSOCK_SOCKETS 1
131#include <winsock2.h>
132typedef SOCKET MHD_socket;
133#define MHD_INVALID_SOCKET (INVALID_SOCKET)
134#endif /* !defined(_WIN32) || defined(_SYS_TYPES_FD_SET) */
135#define MHD_SOCKET_DEFINED 1
136#endif /* MHD_SOCKET_DEFINED */
137
121#endif 138#endif
diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c
index 65ea70fe..414c4b17 100644
--- a/src/microhttpd/connection.c
+++ b/src/microhttpd/connection.c
@@ -338,7 +338,7 @@ try_ready_normal_body (struct MHD_Connection *connection)
338 connection->response_write_position) ) 338 connection->response_write_position) )
339 return MHD_YES; /* response already ready */ 339 return MHD_YES; /* response already ready */
340#if LINUX 340#if LINUX
341 if ( (-1 != response->fd) && 341 if ( (MHD_INVALID_SOCKET != response->fd) &&
342 (0 == (connection->daemon->options & MHD_USE_SSL)) ) 342 (0 == (connection->daemon->options & MHD_USE_SSL)) )
343 { 343 {
344 /* will use sendfile, no need to bother response crc */ 344 /* will use sendfile, no need to bother response crc */
diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c
index 6da3fd88..c7ff9040 100644
--- a/src/microhttpd/daemon.c
+++ b/src/microhttpd/daemon.c
@@ -554,13 +554,13 @@ MHD_TLS_init (struct MHD_Daemon *daemon)
554 * @param max_fd maximum value to potentially update 554 * @param max_fd maximum value to potentially update
555 */ 555 */
556static void 556static void
557add_to_fd_set (int fd, 557add_to_fd_set (MHD_socket fd,
558 fd_set *set, 558 fd_set *set,
559 int *max_fd) 559 MHD_socket *max_fd)
560{ 560{
561 FD_SET (fd, set); 561 FD_SET (fd, set);
562 if ( (NULL != max_fd) && 562 if ( (NULL != max_fd) && (MHD_INVALID_SOCKET != fd) &&
563 (fd > *max_fd) ) 563 ((fd > *max_fd) || (MHD_INVALID_SOCKET == *max_fd)) )
564 *max_fd = fd; 564 *max_fd = fd;
565} 565}
566 566
@@ -587,10 +587,10 @@ MHD_get_fdset (struct MHD_Daemon *daemon,
587 fd_set *read_fd_set, 587 fd_set *read_fd_set,
588 fd_set *write_fd_set, 588 fd_set *write_fd_set,
589 fd_set *except_fd_set, 589 fd_set *except_fd_set,
590 int *max_fd) 590 MHD_socket *max_fd)
591{ 591{
592 struct MHD_Connection *pos; 592 struct MHD_Connection *pos;
593 int fd; 593 MHD_socket fd;
594 594
595 if ( (NULL == daemon) 595 if ( (NULL == daemon)
596 || (NULL == read_fd_set) 596 || (NULL == read_fd_set)
@@ -615,11 +615,12 @@ MHD_get_fdset (struct MHD_Daemon *daemon,
615 } 615 }
616#endif 616#endif
617 fd = daemon->socket_fd; 617 fd = daemon->socket_fd;
618 if (-1 != fd) 618 if (MHD_INVALID_SOCKET != fd)
619 { 619 {
620 FD_SET (fd, read_fd_set); 620 FD_SET (fd, read_fd_set);
621 /* update max file descriptor */ 621 /* update max file descriptor */
622 if ( (NULL != max_fd) && ((*max_fd) < fd)) 622 if ( (NULL != max_fd) &&
623 ((*max_fd) < fd || MHD_INVALID_SOCKET == (*max_fd)))
623 *max_fd = fd; 624 *max_fd = fd;
624 } 625 }
625 for (pos = daemon->connections_head; NULL != pos; pos = pos->next) 626 for (pos = daemon->connections_head; NULL != pos; pos = pos->next)
@@ -667,7 +668,7 @@ MHD_handle_connection (void *data)
667 int num_ready; 668 int num_ready;
668 fd_set rs; 669 fd_set rs;
669 fd_set ws; 670 fd_set ws;
670 int max; 671 MHD_socket max;
671 struct timeval tv; 672 struct timeval tv;
672 struct timeval *tvp; 673 struct timeval *tvp;
673 unsigned int timeout; 674 unsigned int timeout;
@@ -843,7 +844,7 @@ recv_param_adapter (struct MHD_Connection *connection,
843{ 844{
844 ssize_t ret; 845 ssize_t ret;
845 846
846 if ( (-1 == connection->socket_fd) || 847 if ( (MHD_INVALID_SOCKET == connection->socket_fd) ||
847 (MHD_CONNECTION_CLOSED == connection->state) ) 848 (MHD_CONNECTION_CLOSED == connection->state) )
848 { 849 {
849 errno = ENOTCONN; 850 errno = ENOTCONN;
@@ -876,12 +877,12 @@ send_param_adapter (struct MHD_Connection *connection,
876{ 877{
877 ssize_t ret; 878 ssize_t ret;
878#if LINUX 879#if LINUX
879 int fd; 880 MHD_socket fd;
880 off_t offset; 881 off_t offset;
881 off_t left; 882 off_t left;
882#endif 883#endif
883 884
884 if ( (-1 == connection->socket_fd) || 885 if ( (MHD_INVALID_SOCKET == connection->socket_fd) ||
885 (MHD_CONNECTION_CLOSED == connection->state) ) 886 (MHD_CONNECTION_CLOSED == connection->state) )
886 { 887 {
887 errno = ENOTCONN; 888 errno = ENOTCONN;
@@ -893,7 +894,7 @@ send_param_adapter (struct MHD_Connection *connection,
893 if ( (connection->write_buffer_append_offset == 894 if ( (connection->write_buffer_append_offset ==
894 connection->write_buffer_send_offset) && 895 connection->write_buffer_send_offset) &&
895 (NULL != connection->response) && 896 (NULL != connection->response) &&
896 (-1 != (fd = connection->response->fd)) ) 897 (MHD_INVALID_SOCKET != (fd = connection->response->fd)) )
897 { 898 {
898 /* can use sendfile */ 899 /* can use sendfile */
899 offset = (off_t) connection->response_write_position + connection->response->fd_off; 900 offset = (off_t) connection->response_write_position + connection->response->fd_off;
@@ -1027,7 +1028,7 @@ create_thread (pthread_t *thread,
1027 */ 1028 */
1028static int 1029static int
1029internal_add_connection (struct MHD_Daemon *daemon, 1030internal_add_connection (struct MHD_Daemon *daemon,
1030 int client_socket, 1031 MHD_socket client_socket,
1031 const struct sockaddr *addr, 1032 const struct sockaddr *addr,
1032 socklen_t addrlen, 1033 socklen_t addrlen,
1033 int external_add) 1034 int external_add)
@@ -1572,7 +1573,7 @@ resume_suspended_connections (struct MHD_Daemon *daemon)
1572 */ 1573 */
1573static void 1574static void
1574make_nonblocking_noninheritable (struct MHD_Daemon *daemon, 1575make_nonblocking_noninheritable (struct MHD_Daemon *daemon,
1575 int sock) 1576 MHD_socket sock)
1576{ 1577{
1577#ifdef WINDOWS 1578#ifdef WINDOWS
1578 DWORD dwFlags; 1579 DWORD dwFlags;
@@ -1652,7 +1653,7 @@ make_nonblocking_noninheritable (struct MHD_Daemon *daemon,
1652 */ 1653 */
1653int 1654int
1654MHD_add_connection (struct MHD_Daemon *daemon, 1655MHD_add_connection (struct MHD_Daemon *daemon,
1655 int client_socket, 1656 MHD_socket client_socket,
1656 const struct sockaddr *addr, 1657 const struct sockaddr *addr,
1657 socklen_t addrlen) 1658 socklen_t addrlen)
1658{ 1659{
@@ -1687,13 +1688,13 @@ MHD_accept_connection (struct MHD_Daemon *daemon)
1687#endif 1688#endif
1688 struct sockaddr *addr = (struct sockaddr *) &addrstorage; 1689 struct sockaddr *addr = (struct sockaddr *) &addrstorage;
1689 socklen_t addrlen; 1690 socklen_t addrlen;
1690 int s; 1691 MHD_socket s;
1691 int fd; 1692 MHD_socket fd;
1692 int nonblock; 1693 int nonblock;
1693 1694
1694 addrlen = sizeof (addrstorage); 1695 addrlen = sizeof (addrstorage);
1695 memset (addr, 0, sizeof (addrstorage)); 1696 memset (addr, 0, sizeof (addrstorage));
1696 if (-1 == (fd = daemon->socket_fd)) 1697 if (MHD_INVALID_SOCKET == (fd = daemon->socket_fd))
1697 return MHD_NO; 1698 return MHD_NO;
1698#ifdef HAVE_SOCK_NONBLOCK 1699#ifdef HAVE_SOCK_NONBLOCK
1699 nonblock = SOCK_NONBLOCK; 1700 nonblock = SOCK_NONBLOCK;
@@ -1709,7 +1710,7 @@ MHD_accept_connection (struct MHD_Daemon *daemon)
1709#else 1710#else
1710 s = ACCEPT (fd, addr, &addrlen); 1711 s = ACCEPT (fd, addr, &addrlen);
1711#endif 1712#endif
1712 if ((-1 == s) || (addrlen <= 0)) 1713 if ((MHD_INVALID_SOCKET == s) || (addrlen <= 0))
1713 { 1714 {
1714#if HAVE_MESSAGES 1715#if HAVE_MESSAGES
1715 /* This could be a common occurance with multiple worker threads */ 1716 /* This could be a common occurance with multiple worker threads */
@@ -1718,7 +1719,7 @@ MHD_accept_connection (struct MHD_Daemon *daemon)
1718 "Error accepting connection: %s\n", 1719 "Error accepting connection: %s\n",
1719 STRERROR (errno)); 1720 STRERROR (errno));
1720#endif 1721#endif
1721 if (-1 != s) 1722 if (MHD_INVALID_SOCKET != s)
1722 { 1723 {
1723 if (0 != CLOSE (s)) 1724 if (0 != CLOSE (s))
1724 MHD_PANIC ("close failed\n"); 1725 MHD_PANIC ("close failed\n");
@@ -1788,7 +1789,7 @@ MHD_cleanup_connections (struct MHD_Daemon *daemon)
1788 pos->epoll_state &= ~MHD_EPOLL_STATE_IN_EREADY_EDLL; 1789 pos->epoll_state &= ~MHD_EPOLL_STATE_IN_EREADY_EDLL;
1789 } 1790 }
1790 if ( (0 != (daemon->options & MHD_USE_EPOLL_LINUX_ONLY)) && 1791 if ( (0 != (daemon->options & MHD_USE_EPOLL_LINUX_ONLY)) &&
1791 (-1 != daemon->epoll_fd) && 1792 (MHD_INVALID_SOCKET != daemon->epoll_fd) &&
1792 (0 != (pos->epoll_state & MHD_EPOLL_STATE_IN_EPOLL_SET)) ) 1793 (0 != (pos->epoll_state & MHD_EPOLL_STATE_IN_EPOLL_SET)) )
1793 { 1794 {
1794 /* epoll documentation suggests that closing a FD 1795 /* epoll documentation suggests that closing a FD
@@ -1810,7 +1811,7 @@ MHD_cleanup_connections (struct MHD_Daemon *daemon)
1810 MHD_destroy_response (pos->response); 1811 MHD_destroy_response (pos->response);
1811 pos->response = NULL; 1812 pos->response = NULL;
1812 } 1813 }
1813 if (-1 != pos->socket_fd) 1814 if (MHD_INVALID_SOCKET != pos->socket_fd)
1814 { 1815 {
1815#ifdef WINDOWS 1816#ifdef WINDOWS
1816 SHUTDOWN (pos->socket_fd, SHUT_WR); 1817 SHUTDOWN (pos->socket_fd, SHUT_WR);
@@ -1939,7 +1940,7 @@ MHD_run_from_select (struct MHD_Daemon *daemon,
1939 const fd_set *write_fd_set, 1940 const fd_set *write_fd_set,
1940 const fd_set *except_fd_set) 1941 const fd_set *except_fd_set)
1941{ 1942{
1942 int ds; 1943 MHD_socket ds;
1943 char tmp; 1944 char tmp;
1944 struct MHD_Connection *pos; 1945 struct MHD_Connection *pos;
1945 struct MHD_Connection *next; 1946 struct MHD_Connection *next;
@@ -1958,7 +1959,7 @@ MHD_run_from_select (struct MHD_Daemon *daemon,
1958#endif 1959#endif
1959 1960
1960 /* select connection thread handling type */ 1961 /* select connection thread handling type */
1961 if ( (-1 != (ds = daemon->socket_fd)) && 1962 if ( (MHD_INVALID_SOCKET != (ds = daemon->socket_fd)) &&
1962 (FD_ISSET (ds, read_fd_set)) ) 1963 (FD_ISSET (ds, read_fd_set)) )
1963 (void) MHD_accept_connection (daemon); 1964 (void) MHD_accept_connection (daemon);
1964 /* drain signaling pipe to avoid spinning select */ 1965 /* drain signaling pipe to avoid spinning select */
@@ -1974,7 +1975,7 @@ MHD_run_from_select (struct MHD_Daemon *daemon,
1974 { 1975 {
1975 next = pos->next; 1976 next = pos->next;
1976 ds = pos->socket_fd; 1977 ds = pos->socket_fd;
1977 if (-1 == ds) 1978 if (MHD_INVALID_SOCKET == ds)
1978 continue; 1979 continue;
1979 switch (pos->event_loop_info) 1980 switch (pos->event_loop_info)
1980 { 1981 {
@@ -2026,7 +2027,7 @@ MHD_select (struct MHD_Daemon *daemon,
2026 fd_set rs; 2027 fd_set rs;
2027 fd_set ws; 2028 fd_set ws;
2028 fd_set es; 2029 fd_set es;
2029 int max; 2030 MHD_socket max;
2030 struct timeval timeout; 2031 struct timeval timeout;
2031 struct timeval *tv; 2032 struct timeval *tv;
2032 MHD_UNSIGNED_LONG_LONG ltimeout; 2033 MHD_UNSIGNED_LONG_LONG ltimeout;
@@ -2038,7 +2039,7 @@ MHD_select (struct MHD_Daemon *daemon,
2038 FD_ZERO (&rs); 2039 FD_ZERO (&rs);
2039 FD_ZERO (&ws); 2040 FD_ZERO (&ws);
2040 FD_ZERO (&es); 2041 FD_ZERO (&es);
2041 max = -1; 2042 max = MHD_INVALID_SOCKET;
2042 if (0 == (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) 2043 if (0 == (daemon->options & MHD_USE_THREAD_PER_CONNECTION))
2043 { 2044 {
2044 if (MHD_USE_SUSPEND_RESUME == (daemon->options & MHD_USE_SUSPEND_RESUME)) 2045 if (MHD_USE_SUSPEND_RESUME == (daemon->options & MHD_USE_SUSPEND_RESUME))
@@ -2051,13 +2052,13 @@ MHD_select (struct MHD_Daemon *daemon,
2051 /* If we're at the connection limit, no need to 2052 /* If we're at the connection limit, no need to
2052 accept new connections. */ 2053 accept new connections. */
2053 if ( (0 == daemon->max_connections) && 2054 if ( (0 == daemon->max_connections) &&
2054 (-1 != daemon->socket_fd) ) 2055 (MHD_INVALID_SOCKET != daemon->socket_fd) )
2055 FD_CLR (daemon->socket_fd, &rs); 2056 FD_CLR (daemon->socket_fd, &rs);
2056 } 2057 }
2057 else 2058 else
2058 { 2059 {
2059 /* accept only, have one thread per connection */ 2060 /* accept only, have one thread per connection */
2060 if (-1 != daemon->socket_fd) 2061 if (MHD_INVALID_SOCKET != daemon->socket_fd)
2061 { 2062 {
2062 max = daemon->socket_fd; 2063 max = daemon->socket_fd;
2063 FD_SET (daemon->socket_fd, &rs); 2064 FD_SET (daemon->socket_fd, &rs);
@@ -2067,7 +2068,7 @@ MHD_select (struct MHD_Daemon *daemon,
2067 { 2068 {
2068 FD_SET (daemon->wpipe[0], &rs); 2069 FD_SET (daemon->wpipe[0], &rs);
2069 /* update max file descriptor */ 2070 /* update max file descriptor */
2070 if (max < daemon->wpipe[0]) 2071 if (max < daemon->wpipe[0] || max == MHD_INVALID_SOCKET)
2071 max = daemon->wpipe[0]; 2072 max = daemon->wpipe[0];
2072 } 2073 }
2073 2074
@@ -2086,7 +2087,7 @@ MHD_select (struct MHD_Daemon *daemon,
2086 timeout.tv_sec = ltimeout / 1000; 2087 timeout.tv_sec = ltimeout / 1000;
2087 tv = &timeout; 2088 tv = &timeout;
2088 } 2089 }
2089 if (-1 == max) 2090 if (MHD_INVALID_SOCKET == max)
2090 return MHD_YES; 2091 return MHD_YES;
2091 num_ready = SELECT (max + 1, &rs, &ws, &es, tv); 2092 num_ready = SELECT (max + 1, &rs, &ws, &es, tv);
2092 if (MHD_YES == daemon->shutdown) 2093 if (MHD_YES == daemon->shutdown)
@@ -2139,7 +2140,7 @@ MHD_poll_all (struct MHD_Daemon *daemon,
2139 memset (p, 0, sizeof (p)); 2140 memset (p, 0, sizeof (p));
2140 poll_server = 0; 2141 poll_server = 0;
2141 poll_listen = -1; 2142 poll_listen = -1;
2142 if ( (-1 != daemon->socket_fd) && 2143 if ( (MHD_INVALID_SOCKET != daemon->socket_fd) &&
2143 (0 != daemon->max_connections) ) 2144 (0 != daemon->max_connections) )
2144 { 2145 {
2145 /* only listen if we are not at the connection limit */ 2146 /* only listen if we are not at the connection limit */
@@ -2275,7 +2276,7 @@ MHD_poll_listen_socket (struct MHD_Daemon *daemon,
2275 memset (&p, 0, sizeof (p)); 2276 memset (&p, 0, sizeof (p));
2276 poll_count = 0; 2277 poll_count = 0;
2277 poll_listen = -1; 2278 poll_listen = -1;
2278 if (-1 != daemon->socket_fd) 2279 if (MHD_INVALID_SOCKET != daemon->socket_fd)
2279 { 2280 {
2280 p[poll_count].fd = daemon->socket_fd; 2281 p[poll_count].fd = daemon->socket_fd;
2281 p[poll_count].events = POLLIN; 2282 p[poll_count].events = POLLIN;
@@ -2380,7 +2381,7 @@ MHD_epoll (struct MHD_Daemon *daemon,
2380 return MHD_NO; /* we're down! */ 2381 return MHD_NO; /* we're down! */
2381 if (MHD_YES == daemon->shutdown) 2382 if (MHD_YES == daemon->shutdown)
2382 return MHD_NO; 2383 return MHD_NO;
2383 if ( (-1 != daemon->socket_fd) && 2384 if ( (MHD_INVALID_SOCKET != daemon->socket_fd) &&
2384 (0 != daemon->max_connections) && 2385 (0 != daemon->max_connections) &&
2385 (MHD_NO == daemon->listen_socket_in_epoll) ) 2386 (MHD_NO == daemon->listen_socket_in_epoll) )
2386 { 2387 {
@@ -2675,22 +2676,22 @@ MHD_start_daemon (unsigned int flags,
2675 * Note that some thread modes require the caller to have passed 2676 * Note that some thread modes require the caller to have passed
2676 * #MHD_USE_PIPE_FOR_SHUTDOWN when using this API. If this daemon is 2677 * #MHD_USE_PIPE_FOR_SHUTDOWN when using this API. If this daemon is
2677 * in one of those modes and this option was not given to 2678 * in one of those modes and this option was not given to
2678 * #MHD_start_daemon, this function will return -1. 2679 * #MHD_start_daemon, this function will return #MHD_INVALID_SOCKET.
2679 * 2680 *
2680 * @param daemon daemon to stop accepting new connections for 2681 * @param daemon daemon to stop accepting new connections for
2681 * @return old listen socket on success, -1 if the daemon was 2682 * @return old listen socket on success, #MHD_INVALID_SOCKET if
2682 * already not listening anymore 2683 * the daemon was already not listening anymore
2683 * @ingroup specialized 2684 * @ingroup specialized
2684 */ 2685 */
2685int 2686MHD_socket
2686MHD_quiesce_daemon (struct MHD_Daemon *daemon) 2687MHD_quiesce_daemon (struct MHD_Daemon *daemon)
2687{ 2688{
2688 unsigned int i; 2689 unsigned int i;
2689 int ret; 2690 MHD_socket ret;
2690 2691
2691 ret = daemon->socket_fd; 2692 ret = daemon->socket_fd;
2692 if (-1 == ret) 2693 if (MHD_INVALID_SOCKET == ret)
2693 return -1; 2694 return MHD_INVALID_SOCKET;
2694 if ( (-1 == daemon->wpipe[1]) && 2695 if ( (-1 == daemon->wpipe[1]) &&
2695 (0 != (daemon->options & MHD_USE_SELECT_INTERNALLY)) ) 2696 (0 != (daemon->options & MHD_USE_SELECT_INTERNALLY)) )
2696 { 2697 {
@@ -2698,13 +2699,13 @@ MHD_quiesce_daemon (struct MHD_Daemon *daemon)
2698 MHD_DLOG (daemon, 2699 MHD_DLOG (daemon,
2699 "Using MHD_quiesce_daemon in this mode requires MHD_USE_PIPE_FOR_SHUTDOWN\n"); 2700 "Using MHD_quiesce_daemon in this mode requires MHD_USE_PIPE_FOR_SHUTDOWN\n");
2700#endif 2701#endif
2701 return -1; 2702 return MHD_INVALID_SOCKET;
2702 } 2703 }
2703 2704
2704 if (NULL != daemon->worker_pool) 2705 if (NULL != daemon->worker_pool)
2705 for (i = 0; i < daemon->worker_pool_size; i++) 2706 for (i = 0; i < daemon->worker_pool_size; i++)
2706 { 2707 {
2707 daemon->worker_pool[i].socket_fd = -1; 2708 daemon->worker_pool[i].socket_fd = MHD_INVALID_SOCKET;
2708#if EPOLL_SUPPORT 2709#if EPOLL_SUPPORT
2709 if ( (0 != (daemon->options & MHD_USE_EPOLL_LINUX_ONLY)) && 2710 if ( (0 != (daemon->options & MHD_USE_EPOLL_LINUX_ONLY)) &&
2710 (-1 != daemon->worker_pool[i].epoll_fd) && 2711 (-1 != daemon->worker_pool[i].epoll_fd) &&
@@ -2719,7 +2720,7 @@ MHD_quiesce_daemon (struct MHD_Daemon *daemon)
2719 } 2720 }
2720#endif 2721#endif
2721 } 2722 }
2722 daemon->socket_fd = -1; 2723 daemon->socket_fd = MHD_INVALID_SOCKET;
2723#if EPOLL_SUPPORT 2724#if EPOLL_SUPPORT
2724 if ( (0 != (daemon->options & MHD_USE_EPOLL_LINUX_ONLY)) && 2725 if ( (0 != (daemon->options & MHD_USE_EPOLL_LINUX_ONLY)) &&
2725 (-1 != daemon->epoll_fd) && 2726 (-1 != daemon->epoll_fd) &&
@@ -2928,7 +2929,7 @@ parse_options_va (struct MHD_Daemon *daemon,
2928 break; 2929 break;
2929#endif 2930#endif
2930 case MHD_OPTION_LISTEN_SOCKET: 2931 case MHD_OPTION_LISTEN_SOCKET:
2931 daemon->socket_fd = va_arg (ap, int); 2932 daemon->socket_fd = va_arg (ap, MHD_socket);
2932 break; 2933 break;
2933 case MHD_OPTION_EXTERNAL_LOGGER: 2934 case MHD_OPTION_EXTERNAL_LOGGER:
2934#if HAVE_MESSAGES 2935#if HAVE_MESSAGES
@@ -2974,9 +2975,8 @@ parse_options_va (struct MHD_Daemon *daemon,
2974 MHD_OPTION_END)) 2975 MHD_OPTION_END))
2975 return MHD_NO; 2976 return MHD_NO;
2976 break; 2977 break;
2977 /* all options taking 'int' or 'enum' */ 2978 /* all options taking 'enum' */
2978 case MHD_OPTION_HTTPS_CRED_TYPE: 2979 case MHD_OPTION_HTTPS_CRED_TYPE:
2979 case MHD_OPTION_LISTEN_SOCKET:
2980 if (MHD_YES != parse_options (daemon, 2980 if (MHD_YES != parse_options (daemon,
2981 servaddr, 2981 servaddr,
2982 opt, 2982 opt,
@@ -2984,6 +2984,15 @@ parse_options_va (struct MHD_Daemon *daemon,
2984 MHD_OPTION_END)) 2984 MHD_OPTION_END))
2985 return MHD_NO; 2985 return MHD_NO;
2986 break; 2986 break;
2987 /* all options taking 'MHD_socket' */
2988 case MHD_OPTION_LISTEN_SOCKET:
2989 if (MHD_YES != parse_options (daemon,
2990 servaddr,
2991 opt,
2992 (MHD_socket) oa[i].value,
2993 MHD_OPTION_END))
2994 return MHD_NO;
2995 break;
2987 /* all options taking one pointer */ 2996 /* all options taking one pointer */
2988 case MHD_OPTION_SOCK_ADDR: 2997 case MHD_OPTION_SOCK_ADDR:
2989 case MHD_OPTION_HTTPS_MEM_KEY: 2998 case MHD_OPTION_HTTPS_MEM_KEY:
@@ -3064,23 +3073,23 @@ parse_options_va (struct MHD_Daemon *daemon,
3064 * @param type socket type (usually SOCK_STREAM) 3073 * @param type socket type (usually SOCK_STREAM)
3065 * @param protocol desired protocol, 0 for default 3074 * @param protocol desired protocol, 0 for default
3066 */ 3075 */
3067static int 3076static MHD_socket
3068create_socket (struct MHD_Daemon *daemon, 3077create_socket (struct MHD_Daemon *daemon,
3069 int domain, int type, int protocol) 3078 int domain, int type, int protocol)
3070{ 3079{
3071 int ctype = type | SOCK_CLOEXEC; 3080 int ctype = type | SOCK_CLOEXEC;
3072 int fd; 3081 MHD_socket fd;
3073 3082
3074 /* use SOCK_STREAM rather than ai_socktype: some getaddrinfo 3083 /* use SOCK_STREAM rather than ai_socktype: some getaddrinfo
3075 * implementations do not set ai_socktype, e.g. RHL6.2. */ 3084 * implementations do not set ai_socktype, e.g. RHL6.2. */
3076 fd = SOCKET (domain, ctype, protocol); 3085 fd = SOCKET (domain, ctype, protocol);
3077 if ( (-1 == fd) && (EINVAL == errno) && (0 != SOCK_CLOEXEC) ) 3086 if ( (MHD_INVALID_SOCKET == fd) && (EINVAL == errno) && (0 != SOCK_CLOEXEC) )
3078 { 3087 {
3079 ctype = type; 3088 ctype = type;
3080 fd = SOCKET(domain, type, protocol); 3089 fd = SOCKET(domain, type, protocol);
3081 } 3090 }
3082 if (-1 == fd) 3091 if (MHD_INVALID_SOCKET == fd)
3083 return -1; 3092 return MHD_INVALID_SOCKET;
3084 if (type == ctype) 3093 if (type == ctype)
3085 make_nonblocking_noninheritable (daemon, fd); 3094 make_nonblocking_noninheritable (daemon, fd);
3086 return fd; 3095 return fd;
@@ -3114,7 +3123,7 @@ setup_epoll_to_listen (struct MHD_Daemon *daemon)
3114 if (0 == EPOLL_CLOEXEC) 3123 if (0 == EPOLL_CLOEXEC)
3115 make_nonblocking_noninheritable (daemon, 3124 make_nonblocking_noninheritable (daemon,
3116 daemon->epoll_fd); 3125 daemon->epoll_fd);
3117 if (-1 == daemon->socket_fd) 3126 if (MHD_INVALID_SOCKET == daemon->socket_fd)
3118 return MHD_YES; /* non-listening daemon */ 3127 return MHD_YES; /* non-listening daemon */
3119 event.events = EPOLLIN; 3128 event.events = EPOLLIN;
3120 event.data.ptr = daemon; 3129 event.data.ptr = daemon;
@@ -3184,7 +3193,7 @@ MHD_start_daemon_va (unsigned int flags,
3184{ 3193{
3185 const int on = 1; 3194 const int on = 1;
3186 struct MHD_Daemon *daemon; 3195 struct MHD_Daemon *daemon;
3187 int socket_fd; 3196 MHD_socket socket_fd;
3188 struct sockaddr_in servaddr4; 3197 struct sockaddr_in servaddr4;
3189#if HAVE_INET6 3198#if HAVE_INET6
3190 struct sockaddr_in6 servaddr6; 3199 struct sockaddr_in6 servaddr6;
@@ -3224,7 +3233,7 @@ MHD_start_daemon_va (unsigned int flags,
3224 NULL); 3233 NULL);
3225 } 3234 }
3226#endif 3235#endif
3227 daemon->socket_fd = -1; 3236 daemon->socket_fd = MHD_INVALID_SOCKET;
3228 daemon->options = (enum MHD_OPTION) flags; 3237 daemon->options = (enum MHD_OPTION) flags;
3229#if WINDOWS 3238#if WINDOWS
3230 /* Winsock is broken with respect to 'shutdown'; 3239 /* Winsock is broken with respect to 'shutdown';
@@ -3417,7 +3426,7 @@ MHD_start_daemon_va (unsigned int flags,
3417 goto free_and_fail; 3426 goto free_and_fail;
3418 } 3427 }
3419#endif 3428#endif
3420 if ( (-1 == daemon->socket_fd) && 3429 if ( (MHD_INVALID_SOCKET == daemon->socket_fd) &&
3421 (0 == (daemon->options & MHD_USE_NO_LISTEN_SOCKET)) ) 3430 (0 == (daemon->options & MHD_USE_NO_LISTEN_SOCKET)) )
3422 { 3431 {
3423 /* try to open listen socket */ 3432 /* try to open listen socket */
@@ -3427,7 +3436,7 @@ MHD_start_daemon_va (unsigned int flags,
3427 else 3436 else
3428 socket_fd = create_socket (daemon, 3437 socket_fd = create_socket (daemon,
3429 PF_INET, SOCK_STREAM, 0); 3438 PF_INET, SOCK_STREAM, 0);
3430 if (-1 == socket_fd) 3439 if (MHD_INVALID_SOCKET == socket_fd)
3431 { 3440 {
3432#if HAVE_MESSAGES 3441#if HAVE_MESSAGES
3433 if (0 != (flags & MHD_USE_DEBUG)) 3442 if (0 != (flags & MHD_USE_DEBUG))
@@ -3582,7 +3591,7 @@ MHD_start_daemon_va (unsigned int flags,
3582 MHD_DLOG (daemon, 3591 MHD_DLOG (daemon,
3583 "MHD failed to initialize IP connection limit mutex\n"); 3592 "MHD failed to initialize IP connection limit mutex\n");
3584#endif 3593#endif
3585 if ( (-1 != socket_fd) && 3594 if ( (MHD_INVALID_SOCKET != socket_fd) &&
3586 (0 != CLOSE (socket_fd)) ) 3595 (0 != CLOSE (socket_fd)) )
3587 MHD_PANIC ("close failed\n"); 3596 MHD_PANIC ("close failed\n");
3588 goto free_and_fail; 3597 goto free_and_fail;
@@ -3594,7 +3603,7 @@ MHD_start_daemon_va (unsigned int flags,
3594 "MHD failed to initialize IP connection limit mutex\n"); 3603 "MHD failed to initialize IP connection limit mutex\n");
3595#endif 3604#endif
3596 pthread_mutex_destroy (&daemon->cleanup_connection_mutex); 3605 pthread_mutex_destroy (&daemon->cleanup_connection_mutex);
3597 if ( (-1 != socket_fd) && 3606 if ( (MHD_INVALID_SOCKET != socket_fd) &&
3598 (0 != CLOSE (socket_fd)) ) 3607 (0 != CLOSE (socket_fd)) )
3599 MHD_PANIC ("close failed\n"); 3608 MHD_PANIC ("close failed\n");
3600 goto free_and_fail; 3609 goto free_and_fail;
@@ -3608,7 +3617,7 @@ MHD_start_daemon_va (unsigned int flags,
3608 MHD_DLOG (daemon, 3617 MHD_DLOG (daemon,
3609 "Failed to initialize TLS support\n"); 3618 "Failed to initialize TLS support\n");
3610#endif 3619#endif
3611 if ( (-1 != socket_fd) && 3620 if ( (MHD_INVALID_SOCKET != socket_fd) &&
3612 (0 != CLOSE (socket_fd)) ) 3621 (0 != CLOSE (socket_fd)) )
3613 MHD_PANIC ("close failed\n"); 3622 MHD_PANIC ("close failed\n");
3614 pthread_mutex_destroy (&daemon->cleanup_connection_mutex); 3623 pthread_mutex_destroy (&daemon->cleanup_connection_mutex);
@@ -3630,7 +3639,7 @@ MHD_start_daemon_va (unsigned int flags,
3630#endif 3639#endif
3631 pthread_mutex_destroy (&daemon->cleanup_connection_mutex); 3640 pthread_mutex_destroy (&daemon->cleanup_connection_mutex);
3632 pthread_mutex_destroy (&daemon->per_ip_connection_mutex); 3641 pthread_mutex_destroy (&daemon->per_ip_connection_mutex);
3633 if ( (-1 != socket_fd) && 3642 if ( (MHD_INVALID_SOCKET != socket_fd) &&
3634 (0 != CLOSE (socket_fd)) ) 3643 (0 != CLOSE (socket_fd)) )
3635 MHD_PANIC ("close failed\n"); 3644 MHD_PANIC ("close failed\n");
3636 goto free_and_fail; 3645 goto free_and_fail;
@@ -3773,7 +3782,7 @@ thread_failed:
3773 MHD_USE_SELECT_INTERNALLY mode. */ 3782 MHD_USE_SELECT_INTERNALLY mode. */
3774 if (0 == i) 3783 if (0 == i)
3775 { 3784 {
3776 if ( (-1 != socket_fd) && 3785 if ( (MHD_INVALID_SOCKET != socket_fd) &&
3777 (0 != CLOSE (socket_fd)) ) 3786 (0 != CLOSE (socket_fd)) )
3778 MHD_PANIC ("close failed\n"); 3787 MHD_PANIC ("close failed\n");
3779 pthread_mutex_destroy (&daemon->cleanup_connection_mutex); 3788 pthread_mutex_destroy (&daemon->cleanup_connection_mutex);
@@ -3923,7 +3932,7 @@ void
3923MHD_stop_daemon (struct MHD_Daemon *daemon) 3932MHD_stop_daemon (struct MHD_Daemon *daemon)
3924{ 3933{
3925 void *unused; 3934 void *unused;
3926 int fd; 3935 MHD_socket fd;
3927 unsigned int i; 3936 unsigned int i;
3928 int rc; 3937 int rc;
3929 3938
@@ -3931,7 +3940,7 @@ MHD_stop_daemon (struct MHD_Daemon *daemon)
3931 return; 3940 return;
3932 daemon->shutdown = MHD_YES; 3941 daemon->shutdown = MHD_YES;
3933 fd = daemon->socket_fd; 3942 fd = daemon->socket_fd;
3934 daemon->socket_fd = -1; 3943 daemon->socket_fd = MHD_INVALID_SOCKET;
3935 /* Prepare workers for shutdown */ 3944 /* Prepare workers for shutdown */
3936 if (NULL != daemon->worker_pool) 3945 if (NULL != daemon->worker_pool)
3937 { 3946 {
@@ -3939,11 +3948,11 @@ MHD_stop_daemon (struct MHD_Daemon *daemon)
3939 for (i = 0; i < daemon->worker_pool_size; ++i) 3948 for (i = 0; i < daemon->worker_pool_size; ++i)
3940 { 3949 {
3941 daemon->worker_pool[i].shutdown = MHD_YES; 3950 daemon->worker_pool[i].shutdown = MHD_YES;
3942 daemon->worker_pool[i].socket_fd = -1; 3951 daemon->worker_pool[i].socket_fd = MHD_INVALID_SOCKET;
3943#if EPOLL_SUPPORT 3952#if EPOLL_SUPPORT
3944 if ( (0 != (daemon->options & MHD_USE_EPOLL_LINUX_ONLY)) && 3953 if ( (0 != (daemon->options & MHD_USE_EPOLL_LINUX_ONLY)) &&
3945 (-1 != daemon->worker_pool[i].epoll_fd) && 3954 (-1 != daemon->worker_pool[i].epoll_fd) &&
3946 (-1 == fd) ) 3955 (MHD_INVALID_SOCKET == fd) )
3947 epoll_shutdown (&daemon->worker_pool[i]); 3956 epoll_shutdown (&daemon->worker_pool[i]);
3948#endif 3957#endif
3949 } 3958 }
@@ -3956,15 +3965,15 @@ MHD_stop_daemon (struct MHD_Daemon *daemon)
3956#ifdef HAVE_LISTEN_SHUTDOWN 3965#ifdef HAVE_LISTEN_SHUTDOWN
3957 else 3966 else
3958 { 3967 {
3959 /* fd might be -1 here due to 'MHD_quiesce_daemon' */ 3968 /* fd might be MHD_INVALID_SOCKET here due to 'MHD_quiesce_daemon' */
3960 if (-1 != fd) 3969 if (MHD_INVALID_SOCKET != fd)
3961 (void) SHUTDOWN (fd, SHUT_RDWR); 3970 (void) SHUTDOWN (fd, SHUT_RDWR);
3962 } 3971 }
3963#endif 3972#endif
3964#if EPOLL_SUPPORT 3973#if EPOLL_SUPPORT
3965 if ( (0 != (daemon->options & MHD_USE_EPOLL_LINUX_ONLY)) && 3974 if ( (0 != (daemon->options & MHD_USE_EPOLL_LINUX_ONLY)) &&
3966 (-1 != daemon->epoll_fd) && 3975 (-1 != daemon->epoll_fd) &&
3967 (-1 == fd) ) 3976 (MHD_INVALID_SOCKET == fd) )
3968 epoll_shutdown (daemon); 3977 epoll_shutdown (daemon);
3969#endif 3978#endif
3970 3979
@@ -4022,7 +4031,7 @@ MHD_stop_daemon (struct MHD_Daemon *daemon)
4022 } 4031 }
4023 } 4032 }
4024 close_all_connections (daemon); 4033 close_all_connections (daemon);
4025 if ( (-1 != fd) && 4034 if ( (MHD_INVALID_SOCKET != fd) &&
4026 (0 != CLOSE (fd)) ) 4035 (0 != CLOSE (fd)) )
4027 MHD_PANIC ("close failed\n"); 4036 MHD_PANIC ("close failed\n");
4028 4037
diff --git a/src/microhttpd/internal.h b/src/microhttpd/internal.h
index 95297087..0fa6682a 100644
--- a/src/microhttpd/internal.h
+++ b/src/microhttpd/internal.h
@@ -711,11 +711,11 @@ struct MHD_Connection
711 int client_aware; 711 int client_aware;
712 712
713 /** 713 /**
714 * Socket for this connection. Set to -1 if 714 * Socket for this connection. Set to MHD_INVALID_SOCKET if
715 * this connection has died (daemon should clean 715 * this connection has died (daemon should clean
716 * up in that case). 716 * up in that case).
717 */ 717 */
718 int socket_fd; 718 MHD_socket socket_fd;
719 719
720 /** 720 /**
721 * Has this socket been closed for reading (i.e. other side closed 721 * Has this socket been closed for reading (i.e. other side closed
@@ -1082,7 +1082,7 @@ struct MHD_Daemon
1082 /** 1082 /**
1083 * Listen socket. 1083 * Listen socket.
1084 */ 1084 */
1085 int socket_fd; 1085 MHD_socket socket_fd;
1086 1086
1087#if EPOLL_SUPPORT 1087#if EPOLL_SUPPORT
1088 /** 1088 /**
diff --git a/src/microhttpd/response.c b/src/microhttpd/response.c
index abaa64ca..180582f2 100644
--- a/src/microhttpd/response.c
+++ b/src/microhttpd/response.c
@@ -241,7 +241,7 @@ MHD_create_response_from_callback (uint64_t size,
241 if (NULL == (response = malloc (sizeof (struct MHD_Response) + block_size))) 241 if (NULL == (response = malloc (sizeof (struct MHD_Response) + block_size)))
242 return NULL; 242 return NULL;
243 memset (response, 0, sizeof (struct MHD_Response)); 243 memset (response, 0, sizeof (struct MHD_Response));
244 response->fd = -1; 244 response->fd = MHD_INVALID_SOCKET;
245 response->data = (void *) &response[1]; 245 response->data = (void *) &response[1];
246 response->data_buffer_size = block_size; 246 response->data_buffer_size = block_size;
247 if (0 != pthread_mutex_init (&response->mutex, NULL)) 247 if (0 != pthread_mutex_init (&response->mutex, NULL))
@@ -296,7 +296,7 @@ free_callback (void *cls)
296 struct MHD_Response *response = cls; 296 struct MHD_Response *response = cls;
297 297
298 (void) close (response->fd); 298 (void) close (response->fd);
299 response->fd = -1; 299 response->fd = MHD_INVALID_SOCKET;
300} 300}
301 301
302 302
@@ -380,7 +380,7 @@ MHD_create_response_from_data (size_t size,
380 if (NULL == (response = malloc (sizeof (struct MHD_Response)))) 380 if (NULL == (response = malloc (sizeof (struct MHD_Response))))
381 return NULL; 381 return NULL;
382 memset (response, 0, sizeof (struct MHD_Response)); 382 memset (response, 0, sizeof (struct MHD_Response));
383 response->fd = -1; 383 response->fd = MHD_INVALID_SOCKET;
384 if (0 != pthread_mutex_init (&response->mutex, NULL)) 384 if (0 != pthread_mutex_init (&response->mutex, NULL))
385 { 385 {
386 free (response); 386 free (response);
diff --git a/src/microhttpd/test_daemon.c b/src/microhttpd/test_daemon.c
index 4140fb4f..8608a112 100644
--- a/src/microhttpd/test_daemon.c
+++ b/src/microhttpd/test_daemon.c
@@ -91,7 +91,7 @@ testExternalRun ()
91{ 91{
92 struct MHD_Daemon *d; 92 struct MHD_Daemon *d;
93 fd_set rs; 93 fd_set rs;
94 int maxfd; 94 MHD_socket maxfd;
95 int i; 95 int i;
96 96
97 d = MHD_start_daemon (MHD_USE_DEBUG, 97 d = MHD_start_daemon (MHD_USE_DEBUG,
diff --git a/src/testcurl/https/test_empty_response.c b/src/testcurl/https/test_empty_response.c
index 570febdd..024a7dea 100644
--- a/src/testcurl/https/test_empty_response.c
+++ b/src/testcurl/https/test_empty_response.c
@@ -70,7 +70,7 @@ testInternalSelectGet ()
70 fd_set rs; 70 fd_set rs;
71 fd_set ws; 71 fd_set ws;
72 fd_set es; 72 fd_set es;
73 int max; 73 MHD_socket max;
74 int running; 74 int running;
75 struct CURLMsg *msg; 75 struct CURLMsg *msg;
76 time_t start; 76 time_t start;
diff --git a/src/testcurl/https/test_https_get_select.c b/src/testcurl/https/test_https_get_select.c
index ad3142d6..1631c2a7 100644
--- a/src/testcurl/https/test_https_get_select.c
+++ b/src/testcurl/https/test_https_get_select.c
@@ -84,7 +84,7 @@ testExternalGet (int flags)
84 fd_set rs; 84 fd_set rs;
85 fd_set ws; 85 fd_set ws;
86 fd_set es; 86 fd_set es;
87 int max; 87 MHD_socket max;
88 int running; 88 int running;
89 struct CURLMsg *msg; 89 struct CURLMsg *msg;
90 time_t start; 90 time_t start;
diff --git a/src/testcurl/https/test_https_time_out.c b/src/testcurl/https/test_https_time_out.c
index 369bb861..452035bb 100644
--- a/src/testcurl/https/test_https_time_out.c
+++ b/src/testcurl/https/test_https_time_out.c
@@ -41,7 +41,8 @@ static const char *http_get_req = "GET / HTTP/1.1\r\n\r\n";
41static int 41static int
42test_tls_session_time_out (gnutls_session_t session) 42test_tls_session_time_out (gnutls_session_t session)
43{ 43{
44 int sd, ret; 44 int ret;
45 MHD_socket sd;
45 struct sockaddr_in sa; 46 struct sockaddr_in sa;
46 47
47 sd = socket (AF_INET, SOCK_STREAM, 0); 48 sd = socket (AF_INET, SOCK_STREAM, 0);
diff --git a/src/testcurl/https/test_tls_extensions.c b/src/testcurl/https/test_tls_extensions.c
index 6ad3b97a..c1629d86 100644
--- a/src/testcurl/https/test_tls_extensions.c
+++ b/src/testcurl/https/test_tls_extensions.c
@@ -46,7 +46,8 @@ static int
46test_hello_extension (gnutls_session_t session, extensions_t exten_t, 46test_hello_extension (gnutls_session_t session, extensions_t exten_t,
47 int ext_count, int ext_length) 47 int ext_count, int ext_length)
48{ 48{
49 int i, sd, ret = 0, pos = 0; 49 int i, ret = 0, pos = 0;
50 MHD_socket sd;
50 int exten_data_len, ciphersuite_len, datalen; 51 int exten_data_len, ciphersuite_len, datalen;
51 struct sockaddr_in sa; 52 struct sockaddr_in sa;
52 char url[255]; 53 char url[255];
diff --git a/src/testcurl/perf_get.c b/src/testcurl/perf_get.c
index 54f383ca..d400a371 100644
--- a/src/testcurl/perf_get.c
+++ b/src/testcurl/perf_get.c
@@ -361,7 +361,7 @@ testExternalGet (int port)
361 fd_set rs; 361 fd_set rs;
362 fd_set ws; 362 fd_set ws;
363 fd_set es; 363 fd_set es;
364 int max; 364 MHD_socket max;
365 int running; 365 int running;
366 struct CURLMsg *msg; 366 struct CURLMsg *msg;
367 time_t start; 367 time_t start;
diff --git a/src/testcurl/perf_get_concurrent.c b/src/testcurl/perf_get_concurrent.c
index b6c9259b..333763b4 100644
--- a/src/testcurl/perf_get_concurrent.c
+++ b/src/testcurl/perf_get_concurrent.c
@@ -280,7 +280,7 @@ testExternalGet (int port)
280 fd_set rs; 280 fd_set rs;
281 fd_set ws; 281 fd_set ws;
282 fd_set es; 282 fd_set es;
283 int max; 283 MHD_socket max;
284 struct timeval tv; 284 struct timeval tv;
285 MHD_UNSIGNED_LONG_LONG tt; 285 MHD_UNSIGNED_LONG_LONG tt;
286 int tret; 286 int tret;
diff --git a/src/testcurl/test_callback.c b/src/testcurl/test_callback.c
index cc553324..86eb7dbc 100644
--- a/src/testcurl/test_callback.c
+++ b/src/testcurl/test_callback.c
@@ -88,7 +88,7 @@ int main(int argc, char **argv)
88 fd_set rs; 88 fd_set rs;
89 fd_set ws; 89 fd_set ws;
90 fd_set es; 90 fd_set es;
91 int max; 91 MHD_socket max;
92 CURL *c; 92 CURL *c;
93 CURLM *multi; 93 CURLM *multi;
94 CURLMcode mret; 94 CURLMcode mret;
@@ -130,7 +130,7 @@ int main(int argc, char **argv)
130 extra = 10; 130 extra = 10;
131 while ( (c != NULL) || (--extra > 0) ) 131 while ( (c != NULL) || (--extra > 0) )
132 { 132 {
133 max = -1; 133 max = MHD_INVALID_SOCKET;
134 FD_ZERO(&ws); 134 FD_ZERO(&ws);
135 FD_ZERO(&rs); 135 FD_ZERO(&rs);
136 FD_ZERO(&es); 136 FD_ZERO(&es);
diff --git a/src/testcurl/test_get.c b/src/testcurl/test_get.c
index cbe0e258..40920b36 100644
--- a/src/testcurl/test_get.c
+++ b/src/testcurl/test_get.c
@@ -259,7 +259,7 @@ testExternalGet ()
259 fd_set rs; 259 fd_set rs;
260 fd_set ws; 260 fd_set ws;
261 fd_set es; 261 fd_set es;
262 int max; 262 MHD_socket max;
263 int running; 263 int running;
264 struct CURLMsg *msg; 264 struct CURLMsg *msg;
265 time_t start; 265 time_t start;
@@ -448,7 +448,7 @@ static int
448testStopRace (int poll_flag) 448testStopRace (int poll_flag)
449{ 449{
450 struct sockaddr_in sin; 450 struct sockaddr_in sin;
451 int fd; 451 MHD_socket fd;
452 struct MHD_Daemon *d; 452 struct MHD_Daemon *d;
453 453
454 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_DEBUG | poll_flag, 454 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_DEBUG | poll_flag,
diff --git a/src/testcurl/test_get_chunked.c b/src/testcurl/test_get_chunked.c
index d80de8de..c9528d37 100644
--- a/src/testcurl/test_get_chunked.c
+++ b/src/testcurl/test_get_chunked.c
@@ -284,7 +284,7 @@ testExternalGet ()
284 fd_set rs; 284 fd_set rs;
285 fd_set ws; 285 fd_set ws;
286 fd_set es; 286 fd_set es;
287 int max; 287 MHD_socket max;
288 int running; 288 int running;
289 struct CURLMsg *msg; 289 struct CURLMsg *msg;
290 time_t start; 290 time_t start;
diff --git a/src/testcurl/test_get_response_cleanup.c b/src/testcurl/test_get_response_cleanup.c
index e0d1a0dc..81615766 100644
--- a/src/testcurl/test_get_response_cleanup.c
+++ b/src/testcurl/test_get_response_cleanup.c
@@ -217,7 +217,7 @@ testExternalGet ()
217 fd_set rs; 217 fd_set rs;
218 fd_set ws; 218 fd_set ws;
219 fd_set es; 219 fd_set es;
220 int max; 220 MHD_socket max;
221 time_t start; 221 time_t start;
222 struct timeval tv; 222 struct timeval tv;
223 pid_t curl; 223 pid_t curl;
diff --git a/src/testcurl/test_get_sendfile.c b/src/testcurl/test_get_sendfile.c
index 5443801a..7f85458c 100644
--- a/src/testcurl/test_get_sendfile.c
+++ b/src/testcurl/test_get_sendfile.c
@@ -265,7 +265,7 @@ testExternalGet ()
265 fd_set rs; 265 fd_set rs;
266 fd_set ws; 266 fd_set ws;
267 fd_set es; 267 fd_set es;
268 int max; 268 MHD_socket max;
269 int running; 269 int running;
270 struct CURLMsg *msg; 270 struct CURLMsg *msg;
271 time_t start; 271 time_t start;
diff --git a/src/testcurl/test_large_put.c b/src/testcurl/test_large_put.c
index 4b9ae5fc..8b37fc30 100644
--- a/src/testcurl/test_large_put.c
+++ b/src/testcurl/test_large_put.c
@@ -323,7 +323,7 @@ testExternalPut ()
323 fd_set rs; 323 fd_set rs;
324 fd_set ws; 324 fd_set ws;
325 fd_set es; 325 fd_set es;
326 int max; 326 MHD_socket max;
327 int running; 327 int running;
328 struct CURLMsg *msg; 328 struct CURLMsg *msg;
329 time_t start; 329 time_t start;
diff --git a/src/testcurl/test_parse_cookies.c b/src/testcurl/test_parse_cookies.c
index 2eb178c5..6a14dce9 100644
--- a/src/testcurl/test_parse_cookies.c
+++ b/src/testcurl/test_parse_cookies.c
@@ -117,7 +117,7 @@ testExternalGet ()
117 fd_set rs; 117 fd_set rs;
118 fd_set ws; 118 fd_set ws;
119 fd_set es; 119 fd_set es;
120 int max; 120 MHD_socket max;
121 int running; 121 int running;
122 struct CURLMsg *msg; 122 struct CURLMsg *msg;
123 time_t start; 123 time_t start;
diff --git a/src/testcurl/test_post.c b/src/testcurl/test_post.c
index 2501a3d9..f735c630 100644
--- a/src/testcurl/test_post.c
+++ b/src/testcurl/test_post.c
@@ -319,7 +319,7 @@ testExternalPost ()
319 fd_set rs; 319 fd_set rs;
320 fd_set ws; 320 fd_set ws;
321 fd_set es; 321 fd_set es;
322 int max; 322 MHD_socket max;
323 int running; 323 int running;
324 struct CURLMsg *msg; 324 struct CURLMsg *msg;
325 time_t start; 325 time_t start;
diff --git a/src/testcurl/test_post_loop.c b/src/testcurl/test_post_loop.c
index 1d4657c6..4fce55be 100644
--- a/src/testcurl/test_post_loop.c
+++ b/src/testcurl/test_post_loop.c
@@ -304,7 +304,7 @@ testExternalPost ()
304 fd_set rs; 304 fd_set rs;
305 fd_set ws; 305 fd_set ws;
306 fd_set es; 306 fd_set es;
307 int max; 307 MHD_socket max;
308 int running; 308 int running;
309 struct CURLMsg *msg; 309 struct CURLMsg *msg;
310 time_t start; 310 time_t start;
diff --git a/src/testcurl/test_postform.c b/src/testcurl/test_postform.c
index 69c9f27e..1af7af50 100644
--- a/src/testcurl/test_postform.c
+++ b/src/testcurl/test_postform.c
@@ -344,7 +344,7 @@ testExternalPost ()
344 fd_set rs; 344 fd_set rs;
345 fd_set ws; 345 fd_set ws;
346 fd_set es; 346 fd_set es;
347 int max; 347 MHD_socket max;
348 int running; 348 int running;
349 struct CURLMsg *msg; 349 struct CURLMsg *msg;
350 time_t start; 350 time_t start;
diff --git a/src/testcurl/test_process_arguments.c b/src/testcurl/test_process_arguments.c
index d41ddb44..add14b45 100644
--- a/src/testcurl/test_process_arguments.c
+++ b/src/testcurl/test_process_arguments.c
@@ -120,7 +120,7 @@ testExternalGet ()
120 fd_set rs; 120 fd_set rs;
121 fd_set ws; 121 fd_set ws;
122 fd_set es; 122 fd_set es;
123 int max; 123 MHD_socket max;
124 int running; 124 int running;
125 struct CURLMsg *msg; 125 struct CURLMsg *msg;
126 time_t start; 126 time_t start;
diff --git a/src/testcurl/test_process_headers.c b/src/testcurl/test_process_headers.c
index fbe28849..1962d7db 100644
--- a/src/testcurl/test_process_headers.c
+++ b/src/testcurl/test_process_headers.c
@@ -298,7 +298,7 @@ testExternalGet ()
298 fd_set rs; 298 fd_set rs;
299 fd_set ws; 299 fd_set ws;
300 fd_set es; 300 fd_set es;
301 int max; 301 MHD_socket max;
302 int running; 302 int running;
303 struct CURLMsg *msg; 303 struct CURLMsg *msg;
304 time_t start; 304 time_t start;
diff --git a/src/testcurl/test_put_chunked.c b/src/testcurl/test_put_chunked.c
index ced7b29d..decde05b 100644
--- a/src/testcurl/test_put_chunked.c
+++ b/src/testcurl/test_put_chunked.c
@@ -304,7 +304,7 @@ testExternalPut ()
304 fd_set rs; 304 fd_set rs;
305 fd_set ws; 305 fd_set ws;
306 fd_set es; 306 fd_set es;
307 int max; 307 MHD_socket max;
308 int running; 308 int running;
309 struct CURLMsg *msg; 309 struct CURLMsg *msg;
310 time_t start; 310 time_t start;
diff --git a/src/testcurl/test_quiesce.c b/src/testcurl/test_quiesce.c
index ddf794dc..068c2364 100644
--- a/src/testcurl/test_quiesce.c
+++ b/src/testcurl/test_quiesce.c
@@ -112,7 +112,7 @@ ServeOneRequest(int fd)
112 fd_set rs; 112 fd_set rs;
113 fd_set ws; 113 fd_set ws;
114 fd_set es; 114 fd_set es;
115 int max; 115 MHD_socket max;
116 time_t start; 116 time_t start;
117 struct timeval tv; 117 struct timeval tv;
118 int done = 0; 118 int done = 0;
@@ -182,7 +182,7 @@ testGet (int type, int pool_count, int poll_flag)
182 char buf[2048]; 182 char buf[2048];
183 struct CBC cbc; 183 struct CBC cbc;
184 CURLcode errornum; 184 CURLcode errornum;
185 int fd; 185 MHD_socket fd;
186 186
187 cbc.buf = buf; 187 cbc.buf = buf;
188 cbc.size = 2048; 188 cbc.size = 2048;
@@ -290,13 +290,13 @@ testExternalGet ()
290 fd_set rs; 290 fd_set rs;
291 fd_set ws; 291 fd_set ws;
292 fd_set es; 292 fd_set es;
293 int max; 293 MHD_socket max;
294 int running; 294 int running;
295 struct CURLMsg *msg; 295 struct CURLMsg *msg;
296 time_t start; 296 time_t start;
297 struct timeval tv; 297 struct timeval tv;
298 int i; 298 int i;
299 int fd; 299 MHD_socket fd;
300 300
301 multi = NULL; 301 multi = NULL;
302 cbc.buf = buf; 302 cbc.buf = buf;
@@ -384,7 +384,7 @@ testExternalGet ()
384 if (i == 0) { 384 if (i == 0) {
385 /* quiesce the daemon on the 1st iteration, so the 2nd should fail */ 385 /* quiesce the daemon on the 1st iteration, so the 2nd should fail */
386 fd = MHD_quiesce_daemon(d); 386 fd = MHD_quiesce_daemon(d);
387 if (-1 == fd) 387 if (MHD_INVALID_SOCKET == fd)
388 abort (); 388 abort ();
389 close (fd); 389 close (fd);
390 c = setupCURL (&cbc); 390 c = setupCURL (&cbc);