aboutsummaryrefslogtreecommitdiff
path: root/src/microhttpd/daemon.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/microhttpd/daemon.c')
-rw-r--r--src/microhttpd/daemon.c310
1 files changed, 189 insertions, 121 deletions
diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c
index a6a93e77..e639c229 100644
--- a/src/microhttpd/daemon.c
+++ b/src/microhttpd/daemon.c
@@ -294,14 +294,14 @@ MHD_ip_limit_add (struct MHD_Daemon *daemon,
294 MHD_ip_count_lock (daemon); 294 MHD_ip_count_lock (daemon);
295 295
296 /* Search for the IP address */ 296 /* Search for the IP address */
297 if (NULL == (nodep = TSEARCH (key, 297 if (NULL == (nodep = tsearch (key,
298 &daemon->per_ip_connection_count, 298 &daemon->per_ip_connection_count,
299 &MHD_ip_addr_compare))) 299 &MHD_ip_addr_compare)))
300 { 300 {
301#if HAVE_MESSAGES 301#if HAVE_MESSAGES
302 MHD_DLOG (daemon, 302 MHD_DLOG (daemon,
303 "Failed to add IP connection count node\n"); 303 "Failed to add IP connection count node\n");
304#endif 304#endif
305 MHD_ip_count_unlock (daemon); 305 MHD_ip_count_unlock (daemon);
306 free (key); 306 free (key);
307 return MHD_NO; 307 return MHD_NO;
@@ -350,10 +350,10 @@ MHD_ip_limit_del (struct MHD_Daemon *daemon,
350 MHD_ip_count_lock (daemon); 350 MHD_ip_count_lock (daemon);
351 351
352 /* Search for the IP address */ 352 /* Search for the IP address */
353 if (NULL == (nodep = TFIND (&search_key, 353 if (NULL == (nodep = tfind (&search_key,
354 &daemon->per_ip_connection_count, 354 &daemon->per_ip_connection_count,
355 &MHD_ip_addr_compare))) 355 &MHD_ip_addr_compare)))
356 { 356 {
357 /* Something's wrong if we couldn't find an IP address 357 /* Something's wrong if we couldn't find an IP address
358 * that was previously added */ 358 * that was previously added */
359 MHD_PANIC ("Failed to find previously-added IP address\n"); 359 MHD_PANIC ("Failed to find previously-added IP address\n");
@@ -367,8 +367,8 @@ MHD_ip_limit_del (struct MHD_Daemon *daemon,
367 /* Remove the node entirely if count reduces to 0 */ 367 /* Remove the node entirely if count reduces to 0 */
368 if (0 == --found_key->count) 368 if (0 == --found_key->count)
369 { 369 {
370 TDELETE (found_key, 370 tdelete (found_key,
371 &daemon->per_ip_connection_count, 371 &daemon->per_ip_connection_count,
372 &MHD_ip_addr_compare); 372 &MHD_ip_addr_compare);
373 free (found_key); 373 free (found_key);
374 } 374 }
@@ -696,7 +696,7 @@ MHD_handle_connection (void *data)
696 /* how did we get here!? */ 696 /* how did we get here!? */
697 goto exit; 697 goto exit;
698 } 698 }
699 num_ready = SELECT (max + 1, &rs, &ws, NULL, tvp); 699 num_ready = select (max + 1, &rs, &ws, NULL, tvp);
700 if (num_ready < 0) 700 if (num_ready < 0)
701 { 701 {
702 if (EINTR == errno) 702 if (EINTR == errno)
@@ -705,7 +705,7 @@ MHD_handle_connection (void *data)
705 MHD_DLOG (con->daemon, 705 MHD_DLOG (con->daemon,
706 "Error during select (%d): `%s'\n", 706 "Error during select (%d): `%s'\n",
707 max, 707 max,
708 STRERROR (errno)); 708 strerror (errno));
709#endif 709#endif
710 break; 710 break;
711 } 711 }
@@ -751,7 +751,7 @@ MHD_handle_connection (void *data)
751 continue; 751 continue;
752#if HAVE_MESSAGES 752#if HAVE_MESSAGES
753 MHD_DLOG (con->daemon, "Error during poll: `%s'\n", 753 MHD_DLOG (con->daemon, "Error during poll: `%s'\n",
754 STRERROR (errno)); 754 strerror (errno));
755#endif 755#endif
756 break; 756 break;
757 } 757 }
@@ -814,7 +814,7 @@ recv_param_adapter (struct MHD_Connection *connection,
814 errno = ENOTCONN; 814 errno = ENOTCONN;
815 return -1; 815 return -1;
816 } 816 }
817 ret = RECV (connection->socket_fd, other, i, MSG_NOSIGNAL); 817 ret = recv (connection->socket_fd, other, i, MSG_NOSIGNAL);
818#if EPOLL_SUPPORT 818#if EPOLL_SUPPORT
819 if (ret < (ssize_t) i) 819 if (ret < (ssize_t) i)
820 { 820 {
@@ -853,7 +853,7 @@ send_param_adapter (struct MHD_Connection *connection,
853 return -1; 853 return -1;
854 } 854 }
855 if (0 != (connection->daemon->options & MHD_USE_SSL)) 855 if (0 != (connection->daemon->options & MHD_USE_SSL))
856 return SEND (connection->socket_fd, other, i, MSG_NOSIGNAL); 856 return send (connection->socket_fd, other, i, MSG_NOSIGNAL);
857#if LINUX 857#if LINUX
858 if ( (connection->write_buffer_append_offset == 858 if ( (connection->write_buffer_append_offset ==
859 connection->write_buffer_send_offset) && 859 connection->write_buffer_send_offset) &&
@@ -889,7 +889,7 @@ send_param_adapter (struct MHD_Connection *connection,
889 http://lists.gnu.org/archive/html/libmicrohttpd/2011-02/msg00015.html */ 889 http://lists.gnu.org/archive/html/libmicrohttpd/2011-02/msg00015.html */
890 } 890 }
891#endif 891#endif
892 ret = SEND (connection->socket_fd, other, i, MSG_NOSIGNAL); 892 ret = send (connection->socket_fd, other, i, MSG_NOSIGNAL);
893#if EPOLL_SUPPORT 893#if EPOLL_SUPPORT
894 if (ret < (ssize_t) i) 894 if (ret < (ssize_t) i)
895 { 895 {
@@ -1009,7 +1009,7 @@ MHD_add_connection (struct MHD_Daemon *daemon,
1009 client_socket, 1009 client_socket,
1010 addr, addrlen); 1010 addr, addrlen);
1011 /* all pools are at their connection limit, must refuse */ 1011 /* all pools are at their connection limit, must refuse */
1012 if (0 != CLOSE (client_socket)) 1012 if (0 != close (client_socket))
1013 MHD_PANIC ("close failed\n"); 1013 MHD_PANIC ("close failed\n");
1014 return MHD_NO; 1014 return MHD_NO;
1015 } 1015 }
@@ -1024,7 +1024,7 @@ MHD_add_connection (struct MHD_Daemon *daemon,
1024 client_socket, 1024 client_socket,
1025 FD_SETSIZE); 1025 FD_SETSIZE);
1026#endif 1026#endif
1027 if (0 != CLOSE (client_socket)) 1027 if (0 != close (client_socket))
1028 MHD_PANIC ("close failed\n"); 1028 MHD_PANIC ("close failed\n");
1029 return MHD_NO; 1029 return MHD_NO;
1030 } 1030 }
@@ -1044,7 +1044,7 @@ MHD_add_connection (struct MHD_Daemon *daemon,
1044 MHD_DLOG (daemon, 1044 MHD_DLOG (daemon,
1045 "Server reached connection limit (closing inbound connection)\n"); 1045 "Server reached connection limit (closing inbound connection)\n");
1046#endif 1046#endif
1047 if (0 != CLOSE (client_socket)) 1047 if (0 != close (client_socket))
1048 MHD_PANIC ("close failed\n"); 1048 MHD_PANIC ("close failed\n");
1049 return MHD_NO; 1049 return MHD_NO;
1050 } 1050 }
@@ -1059,7 +1059,7 @@ MHD_add_connection (struct MHD_Daemon *daemon,
1059 MHD_DLOG (daemon, "Connection rejected, closing connection\n"); 1059 MHD_DLOG (daemon, "Connection rejected, closing connection\n");
1060#endif 1060#endif
1061#endif 1061#endif
1062 if (0 != CLOSE (client_socket)) 1062 if (0 != close (client_socket))
1063 MHD_PANIC ("close failed\n"); 1063 MHD_PANIC ("close failed\n");
1064 MHD_ip_limit_del (daemon, addr, addrlen); 1064 MHD_ip_limit_del (daemon, addr, addrlen);
1065 return MHD_NO; 1065 return MHD_NO;
@@ -1080,9 +1080,9 @@ MHD_add_connection (struct MHD_Daemon *daemon,
1080#if HAVE_MESSAGES 1080#if HAVE_MESSAGES
1081 MHD_DLOG (daemon, 1081 MHD_DLOG (daemon,
1082 "Error allocating memory: %s\n", 1082 "Error allocating memory: %s\n",
1083 STRERROR (errno)); 1083 strerror (errno));
1084#endif 1084#endif
1085 if (0 != CLOSE (client_socket)) 1085 if (0 != close (client_socket))
1086 MHD_PANIC ("close failed\n"); 1086 MHD_PANIC ("close failed\n");
1087 MHD_ip_limit_del (daemon, addr, addrlen); 1087 MHD_ip_limit_del (daemon, addr, addrlen);
1088 return MHD_NO; 1088 return MHD_NO;
@@ -1094,9 +1094,9 @@ MHD_add_connection (struct MHD_Daemon *daemon,
1094#if HAVE_MESSAGES 1094#if HAVE_MESSAGES
1095 MHD_DLOG (daemon, 1095 MHD_DLOG (daemon,
1096 "Error allocating memory: %s\n", 1096 "Error allocating memory: %s\n",
1097 STRERROR (errno)); 1097 strerror (errno));
1098#endif 1098#endif
1099 if (0 != CLOSE (client_socket)) 1099 if (0 != close (client_socket))
1100 MHD_PANIC ("close failed\n"); 1100 MHD_PANIC ("close failed\n");
1101 MHD_ip_limit_del (daemon, addr, addrlen); 1101 MHD_ip_limit_del (daemon, addr, addrlen);
1102 free (connection); 1102 free (connection);
@@ -1109,9 +1109,9 @@ MHD_add_connection (struct MHD_Daemon *daemon,
1109#if HAVE_MESSAGES 1109#if HAVE_MESSAGES
1110 MHD_DLOG (daemon, 1110 MHD_DLOG (daemon,
1111 "Error allocating memory: %s\n", 1111 "Error allocating memory: %s\n",
1112 STRERROR (errno)); 1112 strerror (errno));
1113#endif 1113#endif
1114 if (0 != CLOSE (client_socket)) 1114 if (0 != close (client_socket))
1115 MHD_PANIC ("close failed\n"); 1115 MHD_PANIC ("close failed\n");
1116 MHD_ip_limit_del (daemon, addr, addrlen); 1116 MHD_ip_limit_del (daemon, addr, addrlen);
1117 MHD_pool_destroy (connection->pool); 1117 MHD_pool_destroy (connection->pool);
@@ -1149,7 +1149,7 @@ MHD_add_connection (struct MHD_Daemon *daemon,
1149 MHD_DLOG (daemon, 1149 MHD_DLOG (daemon,
1150 "Failed to make socket %d non-blocking: %s\n", 1150 "Failed to make socket %d non-blocking: %s\n",
1151 connection->socket_fd, 1151 connection->socket_fd,
1152 STRERROR (errno)); 1152 strerror (errno));
1153#endif 1153#endif
1154 } 1154 }
1155#else 1155#else
@@ -1159,7 +1159,7 @@ MHD_add_connection (struct MHD_Daemon *daemon,
1159#if HAVE_MESSAGES 1159#if HAVE_MESSAGES
1160 MHD_DLOG (daemon, 1160 MHD_DLOG (daemon,
1161 "Failed to make socket non-blocking: %s\n", 1161 "Failed to make socket non-blocking: %s\n",
1162 STRERROR (errno)); 1162 strerror (errno));
1163#endif 1163#endif
1164 } 1164 }
1165#endif 1165#endif
@@ -1190,7 +1190,7 @@ MHD_add_connection (struct MHD_Daemon *daemon,
1190 "Failed to setup TLS credentials: unknown credential type %d\n", 1190 "Failed to setup TLS credentials: unknown credential type %d\n",
1191 daemon->cred_type); 1191 daemon->cred_type);
1192#endif 1192#endif
1193 if (0 != CLOSE (client_socket)) 1193 if (0 != close (client_socket))
1194 MHD_PANIC ("close failed\n"); 1194 MHD_PANIC ("close failed\n");
1195 MHD_ip_limit_del (daemon, addr, addrlen); 1195 MHD_ip_limit_del (daemon, addr, addrlen);
1196 free (connection->addr); 1196 free (connection->addr);
@@ -1233,7 +1233,7 @@ MHD_add_connection (struct MHD_Daemon *daemon,
1233 { 1233 {
1234#if HAVE_MESSAGES 1234#if HAVE_MESSAGES
1235 MHD_DLOG (daemon, "Failed to create a thread: %s\n", 1235 MHD_DLOG (daemon, "Failed to create a thread: %s\n",
1236 STRERROR (res_thread_create)); 1236 strerror (res_thread_create));
1237#endif 1237#endif
1238 goto cleanup; 1238 goto cleanup;
1239 } 1239 }
@@ -1256,7 +1256,7 @@ MHD_add_connection (struct MHD_Daemon *daemon,
1256 if (0 != (daemon->options & MHD_USE_DEBUG)) 1256 if (0 != (daemon->options & MHD_USE_DEBUG))
1257 MHD_DLOG (daemon, 1257 MHD_DLOG (daemon,
1258 "Call to epoll_ctl failed: %s\n", 1258 "Call to epoll_ctl failed: %s\n",
1259 STRERROR (errno)); 1259 strerror (errno));
1260#endif 1260#endif
1261 goto cleanup; 1261 goto cleanup;
1262 } 1262 }
@@ -1276,7 +1276,7 @@ MHD_add_connection (struct MHD_Daemon *daemon,
1276 return MHD_YES; 1276 return MHD_YES;
1277#if HTTPS_SUPPORT || EPOLL_SUPPORT 1277#if HTTPS_SUPPORT || EPOLL_SUPPORT
1278 cleanup: 1278 cleanup:
1279 if (0 != CLOSE (client_socket)) 1279 if (0 != close (client_socket))
1280 MHD_PANIC ("close failed\n"); 1280 MHD_PANIC ("close failed\n");
1281 MHD_ip_limit_del (daemon, addr, addrlen); 1281 MHD_ip_limit_del (daemon, addr, addrlen);
1282 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && 1282 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
@@ -1321,6 +1321,9 @@ MHD_accept_connection (struct MHD_Daemon *daemon)
1321#endif 1321#endif
1322 struct sockaddr *addr = (struct sockaddr *) &addrstorage; 1322 struct sockaddr *addr = (struct sockaddr *) &addrstorage;
1323 socklen_t addrlen; 1323 socklen_t addrlen;
1324#ifdef WINDOWS
1325 LPVOID msgBuffer;
1326#endif
1324 int s; 1327 int s;
1325 int fd; 1328 int fd;
1326 int nonblock; 1329 int nonblock;
@@ -1341,20 +1344,37 @@ MHD_accept_connection (struct MHD_Daemon *daemon)
1341#if HAVE_ACCEPT4 1344#if HAVE_ACCEPT4
1342 s = accept4 (fd, addr, &addrlen, SOCK_CLOEXEC | nonblock); 1345 s = accept4 (fd, addr, &addrlen, SOCK_CLOEXEC | nonblock);
1343#else 1346#else
1344 s = ACCEPT (fd, addr, &addrlen); 1347 s = accept (fd, addr, &addrlen);
1345#endif 1348#endif
1346 if ((-1 == s) || (addrlen <= 0)) 1349 if ((-1 == s) || (addrlen <= 0))
1347 { 1350 {
1348#if HAVE_MESSAGES 1351#if HAVE_MESSAGES
1349 /* This could be a common occurance with multiple worker threads */ 1352 /* This could be a common occurance with multiple worker threads */
1350 if ((EAGAIN != errno) && (EWOULDBLOCK != errno)) 1353 if ((EAGAIN != errno) && (EWOULDBLOCK != errno))
1354 {
1355#ifndef WINDOWS
1351 MHD_DLOG (daemon, 1356 MHD_DLOG (daemon,
1352 "Error accepting connection: %s\n", 1357 "Error accepting connection: %s\n",
1353 STRERROR (errno)); 1358 strerror (errno));
1359#else
1360 FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER |
1361 FORMAT_MESSAGE_FROM_SYSTEM |
1362 FORMAT_MESSAGE_IGNORE_INSERTS,
1363 NULL,
1364 (DWORD) GetLastError (),
1365 MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT),
1366 (LPTSTR) &msgBuffer,
1367 0, NULL);
1368 MHD_DLOG (daemon,
1369 "Error accepting connection: %s\n",
1370 msgBuffer);
1371 LocalFree (msgBuffer);
1354#endif 1372#endif
1373#endif
1374 }
1355 if (-1 != s) 1375 if (-1 != s)
1356 { 1376 {
1357 if (0 != CLOSE (s)) 1377 if (0 != close (s))
1358 MHD_PANIC ("close failed\n"); 1378 MHD_PANIC ("close failed\n");
1359 /* just in case */ 1379 /* just in case */
1360 } 1380 }
@@ -1370,9 +1390,9 @@ MHD_accept_connection (struct MHD_Daemon *daemon)
1370 if (0 != ioctlsocket (s, FIONBIO, &flags)) 1390 if (0 != ioctlsocket (s, FIONBIO, &flags))
1371 { 1391 {
1372#if HAVE_MESSAGES 1392#if HAVE_MESSAGES
1373 MHD_DLOG (daemon, 1393 MHD_DLOG (daemon,
1374 "Failed to make socket non-blocking: %s\n", 1394 "Failed to make socket non-blocking: %s\n",
1375 STRERROR (errno)); 1395 strerror (errno));
1376#endif 1396#endif
1377 } 1397 }
1378 if (!GetHandleInformation ((HANDLE) s, &dwFlags) || 1398 if (!GetHandleInformation ((HANDLE) s, &dwFlags) ||
@@ -1380,10 +1400,18 @@ MHD_accept_connection (struct MHD_Daemon *daemon)
1380 !SetHandleInformation ((HANDLE) s, HANDLE_FLAG_INHERIT, 0))) 1400 !SetHandleInformation ((HANDLE) s, HANDLE_FLAG_INHERIT, 0)))
1381 { 1401 {
1382#if HAVE_MESSAGES 1402#if HAVE_MESSAGES
1383 SetErrnoFromWinError (GetLastError ()); 1403 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
1384 MHD_DLOG (daemon, 1404 FORMAT_MESSAGE_FROM_SYSTEM |
1385 "Failed to make socket non-inheritable: %s\n", 1405 FORMAT_MESSAGE_IGNORE_INSERTS,
1386 STRERROR (errno)); 1406 NULL,
1407 (DWORD) GetLastError(),
1408 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
1409 (LPTSTR) &msgBuffer,
1410 0, NULL );
1411 MHD_DLOG (daemon,
1412 "Error accepting connection: %s\n",
1413 msgBuffer);
1414 LocalFree(msgBuffer);
1387#endif 1415#endif
1388 } 1416 }
1389#else 1417#else
@@ -1401,8 +1429,8 @@ MHD_accept_connection (struct MHD_Daemon *daemon)
1401 { 1429 {
1402#if HAVE_MESSAGES 1430#if HAVE_MESSAGES
1403 MHD_DLOG (daemon, 1431 MHD_DLOG (daemon,
1404 "Failed to make socket non-inheritable: %s\n", 1432 "Failed to make socket non-inheritable: %s\n",
1405 STRERROR (errno)); 1433 strerror (errno));
1406#endif 1434#endif
1407 } 1435 }
1408#endif 1436#endif
@@ -1485,7 +1513,7 @@ MHD_cleanup_connections (struct MHD_Daemon *daemon)
1485 pos->response = NULL; 1513 pos->response = NULL;
1486 } 1514 }
1487 if ( (-1 != pos->socket_fd) && 1515 if ( (-1 != pos->socket_fd) &&
1488 (0 != CLOSE (pos->socket_fd)) ) 1516 (0 != close (pos->socket_fd)) )
1489 MHD_PANIC ("close failed\n"); 1517 MHD_PANIC ("close failed\n");
1490 if (NULL != pos->addr) 1518 if (NULL != pos->addr)
1491 free (pos->addr); 1519 free (pos->addr);
@@ -1690,7 +1718,14 @@ MHD_select (struct MHD_Daemon *daemon,
1690 struct timeval timeout; 1718 struct timeval timeout;
1691 struct timeval *tv; 1719 struct timeval *tv;
1692 MHD_UNSIGNED_LONG_LONG ltimeout; 1720 MHD_UNSIGNED_LONG_LONG ltimeout;
1721#ifdef WINDOWS
1722 LPVOID msgBuffer;
1723 DWORD dwBytes;
1724#endif
1693 1725
1726#ifdef WINDOWS
1727loop_select:
1728#endif
1694 timeout.tv_sec = 0; 1729 timeout.tv_sec = 0;
1695 timeout.tv_usec = 0; 1730 timeout.tv_usec = 0;
1696 if (MHD_YES == daemon->shutdown) 1731 if (MHD_YES == daemon->shutdown)
@@ -1707,19 +1742,20 @@ MHD_select (struct MHD_Daemon *daemon,
1707 1742
1708 /* If we're at the connection limit, no need to 1743 /* If we're at the connection limit, no need to
1709 accept new connections. */ 1744 accept new connections. */
1710 if ( (0 == daemon->max_connections) && 1745 if ( (0 == daemon->max_connections) &&
1711 (-1 != daemon->socket_fd) ) 1746 (-1 != daemon->socket_fd) )
1712 FD_CLR (daemon->socket_fd, &rs); 1747 FD_CLR (daemon->socket_fd, &rs);
1713 } 1748 }
1714 else 1749 else
1715 { 1750 {
1716 /* accept only, have one thread per connection */ 1751 /* accept only, have one thread per connection */
1717 if (-1 != daemon->socket_fd) 1752 if (-1 != daemon->socket_fd)
1718 { 1753 {
1719 max = daemon->socket_fd; 1754 max = daemon->socket_fd;
1720 FD_SET (daemon->socket_fd, &rs); 1755 FD_SET (daemon->socket_fd, &rs);
1721 } 1756 }
1722 } 1757 }
1758#ifndef WINDOWS
1723 if (-1 != daemon->wpipe[0]) 1759 if (-1 != daemon->wpipe[0])
1724 { 1760 {
1725 FD_SET (daemon->wpipe[0], &rs); 1761 FD_SET (daemon->wpipe[0], &rs);
@@ -1727,12 +1763,18 @@ MHD_select (struct MHD_Daemon *daemon,
1727 if (max < daemon->wpipe[0]) 1763 if (max < daemon->wpipe[0])
1728 max = daemon->wpipe[0]; 1764 max = daemon->wpipe[0];
1729 } 1765 }
1766#endif
1730 1767
1731 tv = NULL; 1768 tv = NULL;
1732 if (MHD_NO == may_block) 1769 if (MHD_NO == may_block)
1733 { 1770 {
1771#ifndef WINDOWS
1734 timeout.tv_usec = 0; 1772 timeout.tv_usec = 0;
1773#else
1774 timeout.tv_usec = 100000;
1775#endif
1735 timeout.tv_sec = 0; 1776 timeout.tv_sec = 0;
1777
1736 tv = &timeout; 1778 tv = &timeout;
1737 } 1779 }
1738 else if ( (0 == (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && 1780 else if ( (0 == (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
@@ -1745,7 +1787,15 @@ MHD_select (struct MHD_Daemon *daemon,
1745 } 1787 }
1746 if (-1 == max) 1788 if (-1 == max)
1747 return MHD_YES; 1789 return MHD_YES;
1748 num_ready = SELECT (max + 1, &rs, &ws, &es, tv); 1790#ifdef WINDOWS
1791 if (tv == NULL)
1792 {
1793 timeout.tv_usec = 100000;
1794 timeout.tv_sec = 0;
1795 tv = &timeout;
1796 }
1797#endif
1798 num_ready = select (max + 1, &rs, &ws, &es, tv);
1749 if (MHD_YES == daemon->shutdown) 1799 if (MHD_YES == daemon->shutdown)
1750 return MHD_NO; 1800 return MHD_NO;
1751 if (num_ready < 0) 1801 if (num_ready < 0)
@@ -1753,10 +1803,41 @@ MHD_select (struct MHD_Daemon *daemon,
1753 if (EINTR == errno) 1803 if (EINTR == errno)
1754 return MHD_YES; 1804 return MHD_YES;
1755#if HAVE_MESSAGES 1805#if HAVE_MESSAGES
1756 MHD_DLOG (daemon, "select failed: %s\n", STRERROR (errno)); 1806#ifndef WINDOWS
1807 MHD_DLOG (daemon, "select failed: %s\n", strerror (errno));
1808#else
1809 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
1810 FORMAT_MESSAGE_FROM_SYSTEM |
1811 FORMAT_MESSAGE_IGNORE_INSERTS,
1812 NULL,
1813 (DWORD) GetLastError(),
1814 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
1815 (LPTSTR) &msgBuffer,
1816 0, NULL);
1817 MHD_DLOG (daemon, "select failed: %s\n", msgBuffer);
1818 LocalFree(msgBuffer);
1819#endif
1757#endif 1820#endif
1758 return MHD_NO; 1821 return MHD_NO;
1759 } 1822 }
1823#ifdef WINDOWS
1824 if (num_ready == 0) {
1825 if (-1 != daemon->wpipe[0])
1826 {
1827 if (! PeekNamedPipe((HANDLE) daemon->wpipe[0], NULL, 0, NULL, &dwBytes, NULL))
1828 {
1829 goto loop_select;
1830 }
1831 else if (dwBytes)
1832 FD_SET (daemon->wpipe[0], &rs);
1833 else
1834 goto loop_select;
1835 }
1836 else
1837 goto loop_select;
1838 }
1839#endif
1840
1760 return MHD_run_from_select (daemon, &rs, &ws, &es); 1841 return MHD_run_from_select (daemon, &rs, &ws, &es);
1761} 1842}
1762 1843
@@ -1850,7 +1931,7 @@ MHD_poll_all (struct MHD_Daemon *daemon,
1850#if HAVE_MESSAGES 1931#if HAVE_MESSAGES
1851 MHD_DLOG (daemon, 1932 MHD_DLOG (daemon,
1852 "poll failed: %s\n", 1933 "poll failed: %s\n",
1853 STRERROR (errno)); 1934 strerror (errno));
1854#endif 1935#endif
1855 return MHD_NO; 1936 return MHD_NO;
1856 } 1937 }
@@ -1950,7 +2031,7 @@ MHD_poll_listen_socket (struct MHD_Daemon *daemon,
1950 if (EINTR == errno) 2031 if (EINTR == errno)
1951 return MHD_YES; 2032 return MHD_YES;
1952#if HAVE_MESSAGES 2033#if HAVE_MESSAGES
1953 MHD_DLOG (daemon, "poll failed: %s\n", STRERROR (errno)); 2034 MHD_DLOG (daemon, "poll failed: %s\n", strerror (errno));
1954#endif 2035#endif
1955 return MHD_NO; 2036 return MHD_NO;
1956 } 2037 }
@@ -2043,7 +2124,7 @@ MHD_epoll (struct MHD_Daemon *daemon,
2043 if (0 != (daemon->options & MHD_USE_DEBUG)) 2124 if (0 != (daemon->options & MHD_USE_DEBUG))
2044 MHD_DLOG (daemon, 2125 MHD_DLOG (daemon,
2045 "Call to epoll_ctl failed: %s\n", 2126 "Call to epoll_ctl failed: %s\n",
2046 STRERROR (errno)); 2127 strerror (errno));
2047#endif 2128#endif
2048 return MHD_NO; 2129 return MHD_NO;
2049 } 2130 }
@@ -2095,7 +2176,7 @@ MHD_epoll (struct MHD_Daemon *daemon,
2095 if (0 != (daemon->options & MHD_USE_DEBUG)) 2176 if (0 != (daemon->options & MHD_USE_DEBUG))
2096 MHD_DLOG (daemon, 2177 MHD_DLOG (daemon,
2097 "Call to epoll_wait failed: %s\n", 2178 "Call to epoll_wait failed: %s\n",
2098 STRERROR (errno)); 2179 strerror (errno));
2099#endif 2180#endif
2100 return MHD_NO; 2181 return MHD_NO;
2101 } 2182 }
@@ -2681,19 +2762,19 @@ create_socket (int domain, int type, int protocol)
2681#ifdef WINDOWS 2762#ifdef WINDOWS
2682 DWORD dwFlags; 2763 DWORD dwFlags;
2683#endif 2764#endif
2684 2765
2685 /* use SOCK_STREAM rather than ai_socktype: some getaddrinfo 2766 /* use SOCK_STREAM rather than ai_socktype: some getaddrinfo
2686 * implementations do not set ai_socktype, e.g. RHL6.2. */ 2767 * implementations do not set ai_socktype, e.g. RHL6.2. */
2687 fd = SOCKET (domain, ctype, protocol); 2768 fd = socket (domain, ctype, protocol);
2688 if ( (-1 == fd) && (EINVAL == errno) && (0 != sock_cloexec) ) 2769 if ( (-1 == fd) && (EINVAL == errno) && (0 != sock_cloexec) )
2689 { 2770 {
2690 sock_cloexec = 0; 2771 sock_cloexec = 0;
2691 fd = SOCKET(domain, type, protocol); 2772 fd = socket(domain, type, protocol);
2692 } 2773 }
2693 if (-1 == fd) 2774 if (-1 == fd)
2694 return -1; 2775 return -1;
2695 if (0 != sock_cloexec) 2776 if (0 != sock_cloexec)
2696 return fd; /* this is it */ 2777 return fd; /* this is it */
2697 /* flag was not set during 'socket' call, let's try setting it manually */ 2778 /* flag was not set during 'socket' call, let's try setting it manually */
2698#ifndef WINDOWS 2779#ifndef WINDOWS
2699 flags = fcntl (fd, F_GETFD); 2780 flags = fcntl (fd, F_GETFD);
@@ -2702,9 +2783,6 @@ create_socket (int domain, int type, int protocol)
2702 if (!GetHandleInformation ((HANDLE) fd, &dwFlags)) 2783 if (!GetHandleInformation ((HANDLE) fd, &dwFlags))
2703#endif 2784#endif
2704 { 2785 {
2705#ifdef WINDOWS
2706 SetErrnoFromWinError (GetLastError ());
2707#endif
2708 return fd; /* good luck */ 2786 return fd; /* good luck */
2709 } 2787 }
2710#ifndef WINDOWS 2788#ifndef WINDOWS
@@ -2718,9 +2796,6 @@ create_socket (int domain, int type, int protocol)
2718 if (!SetHandleInformation ((HANDLE) fd, HANDLE_FLAG_INHERIT, 0)) 2796 if (!SetHandleInformation ((HANDLE) fd, HANDLE_FLAG_INHERIT, 0))
2719#endif 2797#endif
2720 { 2798 {
2721#ifdef WINDOWS
2722 SetErrnoFromWinError (GetLastError ());
2723#endif
2724 return fd; /* good luck */ 2799 return fd; /* good luck */
2725 } 2800 }
2726 return fd; 2801 return fd;
@@ -2747,7 +2822,7 @@ setup_epoll_to_listen (struct MHD_Daemon *daemon)
2747 if (0 != (daemon->options & MHD_USE_DEBUG)) 2822 if (0 != (daemon->options & MHD_USE_DEBUG))
2748 MHD_DLOG (daemon, 2823 MHD_DLOG (daemon,
2749 "Call to epoll_create1 failed: %s\n", 2824 "Call to epoll_create1 failed: %s\n",
2750 STRERROR (errno)); 2825 strerror (errno));
2751#endif 2826#endif
2752 return MHD_NO; 2827 return MHD_NO;
2753 } 2828 }
@@ -2764,7 +2839,7 @@ setup_epoll_to_listen (struct MHD_Daemon *daemon)
2764 if (0 != (daemon->options & MHD_USE_DEBUG)) 2839 if (0 != (daemon->options & MHD_USE_DEBUG))
2765 MHD_DLOG (daemon, 2840 MHD_DLOG (daemon,
2766 "Call to epoll_ctl failed: %s\n", 2841 "Call to epoll_ctl failed: %s\n",
2767 STRERROR (errno)); 2842 strerror (errno));
2768#endif 2843#endif
2769 return MHD_NO; 2844 return MHD_NO;
2770 } 2845 }
@@ -2812,15 +2887,15 @@ MHD_start_daemon_va (unsigned int flags,
2812 2887
2813#ifndef HAVE_INET6 2888#ifndef HAVE_INET6
2814 if (0 != (flags & MHD_USE_IPv6)) 2889 if (0 != (flags & MHD_USE_IPv6))
2815 return NULL; 2890 return NULL;
2816#endif 2891#endif
2817#ifndef HAVE_POLL_H 2892#ifndef HAVE_POLL_H
2818 if (0 != (flags & MHD_USE_POLL)) 2893 if (0 != (flags & MHD_USE_POLL))
2819 return NULL; 2894 return NULL;
2820#endif 2895#endif
2821#if ! HTTPS_SUPPORT 2896#if ! HTTPS_SUPPORT
2822 if (0 != (flags & MHD_USE_SSL)) 2897 if (0 != (flags & MHD_USE_SSL))
2823 return NULL; 2898 return NULL;
2824#endif 2899#endif
2825 if (NULL == dh) 2900 if (NULL == dh)
2826 return NULL; 2901 return NULL;
@@ -2865,12 +2940,17 @@ MHD_start_daemon_va (unsigned int flags,
2865 if (0 == (flags & (MHD_USE_SELECT_INTERNALLY | MHD_USE_THREAD_PER_CONNECTION))) 2940 if (0 == (flags & (MHD_USE_SELECT_INTERNALLY | MHD_USE_THREAD_PER_CONNECTION)))
2866 use_pipe = 0; /* useless if we are using 'external' select */ 2941 use_pipe = 0; /* useless if we are using 'external' select */
2867 if ( (use_pipe) && 2942 if ( (use_pipe) &&
2868 (0 != PIPE (daemon->wpipe)) ) 2943#ifndef WINDOWS
2944 (0 != pipe (daemon->wpipe)) )
2945#else
2946 (0 == CreatePipe ((HANDLE *) &daemon->wpipe[0],
2947 (HANDLE *) &daemon->wpipe[1], NULL, 0)) )
2948#endif
2869 { 2949 {
2870#if HAVE_MESSAGES 2950#if HAVE_MESSAGES
2871 MHD_DLOG (daemon, 2951 MHD_DLOG (daemon,
2872 "Failed to create control pipe: %s\n", 2952 "Failed to create control pipe: %s\n",
2873 STRERROR (errno)); 2953 strerror (errno));
2874#endif 2954#endif
2875 free (daemon); 2955 free (daemon);
2876 return NULL; 2956 return NULL;
@@ -2883,9 +2963,9 @@ MHD_start_daemon_va (unsigned int flags,
2883 MHD_DLOG (daemon, 2963 MHD_DLOG (daemon,
2884 "file descriptor for control pipe exceeds maximum value\n"); 2964 "file descriptor for control pipe exceeds maximum value\n");
2885#endif 2965#endif
2886 if (0 != CLOSE (daemon->wpipe[0])) 2966 if (0 != close (daemon->wpipe[0]))
2887 MHD_PANIC ("close failed\n"); 2967 MHD_PANIC ("close failed\n");
2888 if (0 != CLOSE (daemon->wpipe[1])) 2968 if (0 != close (daemon->wpipe[1]))
2889 MHD_PANIC ("close failed\n"); 2969 MHD_PANIC ("close failed\n");
2890 free (daemon); 2970 free (daemon);
2891 return NULL; 2971 return NULL;
@@ -2937,7 +3017,7 @@ MHD_start_daemon_va (unsigned int flags,
2937#if HAVE_MESSAGES 3017#if HAVE_MESSAGES
2938 MHD_DLOG (daemon, 3018 MHD_DLOG (daemon,
2939 "Failed to allocate memory for nonce-nc map: %s\n", 3019 "Failed to allocate memory for nonce-nc map: %s\n",
2940 STRERROR (errno)); 3020 strerror (errno));
2941#endif 3021#endif
2942#if HTTPS_SUPPORT 3022#if HTTPS_SUPPORT
2943 if (0 != (flags & MHD_USE_SSL)) 3023 if (0 != (flags & MHD_USE_SSL))
@@ -3025,20 +3105,20 @@ MHD_start_daemon_va (unsigned int flags,
3025 if (0 != (flags & MHD_USE_DEBUG)) 3105 if (0 != (flags & MHD_USE_DEBUG))
3026 MHD_DLOG (daemon, 3106 MHD_DLOG (daemon,
3027 "Call to socket failed: %s\n", 3107 "Call to socket failed: %s\n",
3028 STRERROR (errno)); 3108 strerror (errno));
3029#endif 3109#endif
3030 goto free_and_fail; 3110 goto free_and_fail;
3031 } 3111 }
3032 if ( (0 > SETSOCKOPT (socket_fd, 3112 if ( (setsockopt (socket_fd,
3033 SOL_SOCKET, 3113 SOL_SOCKET,
3034 SO_REUSEADDR, 3114 SO_REUSEADDR,
3035 &on, sizeof (on))) && 3115 &on, sizeof (on))) &&
3036 (0 != (flags & MHD_USE_DEBUG)) ) 3116 (0 != (flags & MHD_USE_DEBUG)) )
3037 { 3117 {
3038#if HAVE_MESSAGES 3118#if HAVE_MESSAGES
3039 MHD_DLOG (daemon, 3119 MHD_DLOG (daemon,
3040 "setsockopt failed: %s\n", 3120 "setsockopt failed: %s\n",
3041 STRERROR (errno)); 3121 strerror (errno));
3042#endif 3122#endif
3043 } 3123 }
3044 3124
@@ -3090,30 +3170,30 @@ MHD_start_daemon_va (unsigned int flags,
3090#else 3170#else
3091 const char on = 1; 3171 const char on = 1;
3092#endif 3172#endif
3093 if ( (0 > SETSOCKOPT (socket_fd, 3173 if ( (setsockopt (socket_fd,
3094 IPPROTO_IPV6, IPV6_V6ONLY, 3174 IPPROTO_IPV6, IPV6_V6ONLY,
3095 &on, sizeof (on))) && 3175 &on, sizeof (on))) &&
3096 (0 != (flags & MHD_USE_DEBUG)) ) 3176 (0 != (flags & MHD_USE_DEBUG)) )
3097 { 3177 {
3098#if HAVE_MESSAGES 3178#if HAVE_MESSAGES
3099 MHD_DLOG (daemon, 3179 MHD_DLOG (daemon,
3100 "setsockopt failed: %s\n", 3180 "setsockopt failed: %s\n",
3101 STRERROR (errno)); 3181 strerror (errno));
3102#endif 3182#endif
3103 } 3183 }
3104#endif 3184#endif
3105#endif 3185#endif
3106 } 3186 }
3107 if (-1 == BIND (socket_fd, servaddr, addrlen)) 3187 if (-1 == bind (socket_fd, servaddr, addrlen))
3108 { 3188 {
3109#if HAVE_MESSAGES 3189#if HAVE_MESSAGES
3110 if (0 != (flags & MHD_USE_DEBUG)) 3190 if (0 != (flags & MHD_USE_DEBUG))
3111 MHD_DLOG (daemon, 3191 MHD_DLOG (daemon,
3112 "Failed to bind to port %u: %s\n", 3192 "Failed to bind to port %u: %s\n",
3113 (unsigned int) port, 3193 (unsigned int) port,
3114 STRERROR (errno)); 3194 strerror (errno));
3115#endif 3195#endif
3116 if (0 != CLOSE (socket_fd)) 3196 if (0 != close (socket_fd))
3117 MHD_PANIC ("close failed\n"); 3197 MHD_PANIC ("close failed\n");
3118 goto free_and_fail; 3198 goto free_and_fail;
3119 } 3199 }
@@ -3126,23 +3206,23 @@ MHD_start_daemon_va (unsigned int flags,
3126#if HAVE_MESSAGES 3206#if HAVE_MESSAGES
3127 MHD_DLOG (daemon, 3207 MHD_DLOG (daemon,
3128 "Failed to make listen socket non-blocking: %s\n", 3208 "Failed to make listen socket non-blocking: %s\n",
3129 STRERROR (errno)); 3209 strerror (errno));
3130#endif 3210#endif
3131 if (0 != CLOSE (socket_fd)) 3211 if (0 != close (socket_fd))
3132 MHD_PANIC ("close failed\n"); 3212 MHD_PANIC ("close failed\n");
3133 goto free_and_fail; 3213 goto free_and_fail;
3134 } 3214 }
3135 } 3215 }
3136#endif 3216#endif
3137 if (LISTEN (socket_fd, 32) < 0) 3217 if (listen (socket_fd, 32) < 0)
3138 { 3218 {
3139#if HAVE_MESSAGES 3219#if HAVE_MESSAGES
3140 if (0 != (flags & MHD_USE_DEBUG)) 3220 if (0 != (flags & MHD_USE_DEBUG))
3141 MHD_DLOG (daemon, 3221 MHD_DLOG (daemon,
3142 "Failed to listen for connections: %s\n", 3222 "Failed to listen for connections: %s\n",
3143 STRERROR (errno)); 3223 strerror (errno));
3144#endif 3224#endif
3145 if (0 != CLOSE (socket_fd)) 3225 if (0 != close (socket_fd))
3146 MHD_PANIC ("close failed\n"); 3226 MHD_PANIC ("close failed\n");
3147 goto free_and_fail; 3227 goto free_and_fail;
3148 } 3228 }
@@ -3162,7 +3242,7 @@ MHD_start_daemon_va (unsigned int flags,
3162 socket_fd, 3242 socket_fd,
3163 FD_SETSIZE); 3243 FD_SETSIZE);
3164#endif 3244#endif
3165 if (0 != CLOSE (socket_fd)) 3245 if (0 != close (socket_fd))
3166 MHD_PANIC ("close failed\n"); 3246 MHD_PANIC ("close failed\n");
3167 goto free_and_fail; 3247 goto free_and_fail;
3168 } 3248 }
@@ -3175,7 +3255,7 @@ MHD_start_daemon_va (unsigned int flags,
3175 "MHD failed to initialize IP connection limit mutex\n"); 3255 "MHD failed to initialize IP connection limit mutex\n");
3176#endif 3256#endif
3177 if ( (-1 != socket_fd) && 3257 if ( (-1 != socket_fd) &&
3178 (0 != CLOSE (socket_fd)) ) 3258 (0 != close (socket_fd)) )
3179 MHD_PANIC ("close failed\n"); 3259 MHD_PANIC ("close failed\n");
3180 goto free_and_fail; 3260 goto free_and_fail;
3181 } 3261 }
@@ -3187,7 +3267,7 @@ MHD_start_daemon_va (unsigned int flags,
3187#endif 3267#endif
3188 pthread_mutex_destroy (&daemon->cleanup_connection_mutex); 3268 pthread_mutex_destroy (&daemon->cleanup_connection_mutex);
3189 if ( (-1 != socket_fd) && 3269 if ( (-1 != socket_fd) &&
3190 (0 != CLOSE (socket_fd)) ) 3270 (0 != close (socket_fd)) )
3191 MHD_PANIC ("close failed\n"); 3271 MHD_PANIC ("close failed\n");
3192 goto free_and_fail; 3272 goto free_and_fail;
3193 } 3273 }
@@ -3201,7 +3281,7 @@ MHD_start_daemon_va (unsigned int flags,
3201 "Failed to initialize TLS support\n"); 3281 "Failed to initialize TLS support\n");
3202#endif 3282#endif
3203 if ( (-1 != socket_fd) && 3283 if ( (-1 != socket_fd) &&
3204 (0 != CLOSE (socket_fd)) ) 3284 (0 != close (socket_fd)) )
3205 MHD_PANIC ("close failed\n"); 3285 MHD_PANIC ("close failed\n");
3206 pthread_mutex_destroy (&daemon->cleanup_connection_mutex); 3286 pthread_mutex_destroy (&daemon->cleanup_connection_mutex);
3207 pthread_mutex_destroy (&daemon->per_ip_connection_mutex); 3287 pthread_mutex_destroy (&daemon->per_ip_connection_mutex);
@@ -3218,12 +3298,12 @@ MHD_start_daemon_va (unsigned int flags,
3218#if HAVE_MESSAGES 3298#if HAVE_MESSAGES
3219 MHD_DLOG (daemon, 3299 MHD_DLOG (daemon,
3220 "Failed to create listen thread: %s\n", 3300 "Failed to create listen thread: %s\n",
3221 STRERROR (res_thread_create)); 3301 strerror (res_thread_create));
3222#endif 3302#endif
3223 pthread_mutex_destroy (&daemon->cleanup_connection_mutex); 3303 pthread_mutex_destroy (&daemon->cleanup_connection_mutex);
3224 pthread_mutex_destroy (&daemon->per_ip_connection_mutex); 3304 pthread_mutex_destroy (&daemon->per_ip_connection_mutex);
3225 if ( (-1 != socket_fd) && 3305 if ( (-1 != socket_fd) &&
3226 (0 != CLOSE (socket_fd)) ) 3306 (0 != close (socket_fd)) )
3227 MHD_PANIC ("close failed\n"); 3307 MHD_PANIC ("close failed\n");
3228 goto free_and_fail; 3308 goto free_and_fail;
3229 } 3309 }
@@ -3257,14 +3337,8 @@ MHD_start_daemon_va (unsigned int flags,
3257 goto thread_failed; 3337 goto thread_failed;
3258#else 3338#else
3259 sk_flags = 1; 3339 sk_flags = 1;
3260#if HAVE_PLIBC_FD
3261 if (SOCKET_ERROR ==
3262 ioctlsocket (plibc_fd_get_handle (socket_fd), FIONBIO, &sk_flags))
3263 goto thread_failed;
3264#else
3265 if (ioctlsocket (socket_fd, FIONBIO, &sk_flags) == SOCKET_ERROR) 3340 if (ioctlsocket (socket_fd, FIONBIO, &sk_flags) == SOCKET_ERROR)
3266 goto thread_failed; 3341 goto thread_failed;
3267#endif // PLIBC_FD
3268#endif // MINGW 3342#endif // MINGW
3269 3343
3270 /* Allocate memory for pooled objects */ 3344 /* Allocate memory for pooled objects */
@@ -3314,8 +3388,8 @@ MHD_start_daemon_va (unsigned int flags,
3314 { 3388 {
3315#if HAVE_MESSAGES 3389#if HAVE_MESSAGES
3316 MHD_DLOG (daemon, 3390 MHD_DLOG (daemon,
3317 "Failed to create pool thread: %s\n", 3391 "Failed to create pool thread: %s\n",
3318 STRERROR (res_thread_create)); 3392 strerror (res_thread_create));
3319#endif 3393#endif
3320 /* Free memory for this worker; cleanup below handles 3394 /* Free memory for this worker; cleanup below handles
3321 * all previously-created workers. */ 3395 * all previously-created workers. */
@@ -3334,7 +3408,7 @@ thread_failed:
3334 if (0 == i) 3408 if (0 == i)
3335 { 3409 {
3336 if ( (-1 != socket_fd) && 3410 if ( (-1 != socket_fd) &&
3337 (0 != CLOSE (socket_fd)) ) 3411 (0 != close (socket_fd)) )
3338 MHD_PANIC ("close failed\n"); 3412 MHD_PANIC ("close failed\n");
3339 pthread_mutex_destroy (&daemon->cleanup_connection_mutex); 3413 pthread_mutex_destroy (&daemon->cleanup_connection_mutex);
3340 pthread_mutex_destroy (&daemon->per_ip_connection_mutex); 3414 pthread_mutex_destroy (&daemon->per_ip_connection_mutex);
@@ -3422,7 +3496,7 @@ close_all_connections (struct MHD_Daemon *daemon)
3422 (0 != pthread_mutex_lock (&daemon->cleanup_connection_mutex)) ) 3496 (0 != pthread_mutex_lock (&daemon->cleanup_connection_mutex)) )
3423 MHD_PANIC ("Failed to acquire cleanup mutex\n"); 3497 MHD_PANIC ("Failed to acquire cleanup mutex\n");
3424 for (pos = daemon->connections_head; NULL != pos; pos = pos->nextX) 3498 for (pos = daemon->connections_head; NULL != pos; pos = pos->nextX)
3425 SHUTDOWN (pos->socket_fd, 3499 shutdown (pos->socket_fd,
3426 (pos->read_closed == MHD_YES) ? SHUT_WR : SHUT_RDWR); 3500 (pos->read_closed == MHD_YES) ? SHUT_WR : SHUT_RDWR);
3427 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && 3501 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
3428 (0 != pthread_mutex_unlock (&daemon->cleanup_connection_mutex)) ) 3502 (0 != pthread_mutex_unlock (&daemon->cleanup_connection_mutex)) )
@@ -3509,7 +3583,7 @@ MHD_stop_daemon (struct MHD_Daemon *daemon)
3509 } 3583 }
3510 if (-1 != daemon->wpipe[1]) 3584 if (-1 != daemon->wpipe[1])
3511 { 3585 {
3512 if (1 != WRITE (daemon->wpipe[1], "e", 1)) 3586 if (1 != write (daemon->wpipe[1], "e", 1))
3513 MHD_PANIC ("failed to signal shutdownn via pipe"); 3587 MHD_PANIC ("failed to signal shutdownn via pipe");
3514 } 3588 }
3515#ifdef HAVE_LISTEN_SHUTDOWN 3589#ifdef HAVE_LISTEN_SHUTDOWN
@@ -3517,7 +3591,7 @@ MHD_stop_daemon (struct MHD_Daemon *daemon)
3517 { 3591 {
3518 /* fd might be -1 here due to 'MHD_quiesce_daemon' */ 3592 /* fd might be -1 here due to 'MHD_quiesce_daemon' */
3519 if (-1 != fd) 3593 if (-1 != fd)
3520 (void) SHUTDOWN (fd, SHUT_RDWR); 3594 (void) shutdown (fd, SHUT_RDWR);
3521 } 3595 }
3522#endif 3596#endif
3523#if EPOLL_SUPPORT 3597#if EPOLL_SUPPORT
@@ -3546,7 +3620,7 @@ MHD_stop_daemon (struct MHD_Daemon *daemon)
3546 pthread_mutex_destroy (&daemon->worker_pool[i].cleanup_connection_mutex); 3620 pthread_mutex_destroy (&daemon->worker_pool[i].cleanup_connection_mutex);
3547#if EPOLL_SUPPORT 3621#if EPOLL_SUPPORT
3548 if ( (-1 != daemon->worker_pool[i].epoll_fd) && 3622 if ( (-1 != daemon->worker_pool[i].epoll_fd) &&
3549 (0 != CLOSE (daemon->worker_pool[i].epoll_fd)) ) 3623 (0 != close (daemon->worker_pool[i].epoll_fd)) )
3550 MHD_PANIC ("close failed\n"); 3624 MHD_PANIC ("close failed\n");
3551#endif 3625#endif
3552 } 3626 }
@@ -3567,7 +3641,7 @@ MHD_stop_daemon (struct MHD_Daemon *daemon)
3567 } 3641 }
3568 close_all_connections (daemon); 3642 close_all_connections (daemon);
3569 if ( (-1 != fd) && 3643 if ( (-1 != fd) &&
3570 (0 != CLOSE (fd)) ) 3644 (0 != close (fd)) )
3571 MHD_PANIC ("close failed\n"); 3645 MHD_PANIC ("close failed\n");
3572 3646
3573 /* TLS clean up */ 3647 /* TLS clean up */
@@ -3582,7 +3656,7 @@ MHD_stop_daemon (struct MHD_Daemon *daemon)
3582#if EPOLL_SUPPORT 3656#if EPOLL_SUPPORT
3583 if ( (0 != (daemon->options & MHD_USE_EPOLL_LINUX_ONLY)) && 3657 if ( (0 != (daemon->options & MHD_USE_EPOLL_LINUX_ONLY)) &&
3584 (-1 != daemon->epoll_fd) && 3658 (-1 != daemon->epoll_fd) &&
3585 (0 != CLOSE (daemon->epoll_fd)) ) 3659 (0 != close (daemon->epoll_fd)) )
3586 MHD_PANIC ("close failed\n"); 3660 MHD_PANIC ("close failed\n");
3587#endif 3661#endif
3588 3662
@@ -3595,9 +3669,9 @@ MHD_stop_daemon (struct MHD_Daemon *daemon)
3595 3669
3596 if (-1 != daemon->wpipe[1]) 3670 if (-1 != daemon->wpipe[1])
3597 { 3671 {
3598 if (0 != CLOSE (daemon->wpipe[0])) 3672 if (0 != close (daemon->wpipe[0]))
3599 MHD_PANIC ("close failed\n"); 3673 MHD_PANIC ("close failed\n");
3600 if (0 != CLOSE (daemon->wpipe[1])) 3674 if (0 != close (daemon->wpipe[1]))
3601 MHD_PANIC ("close failed\n"); 3675 MHD_PANIC ("close failed\n");
3602 } 3676 }
3603 free (daemon); 3677 free (daemon);
@@ -3687,15 +3761,12 @@ GCRY_THREAD_OPTION_PTHREAD_IMPL;
3687/** 3761/**
3688 * Initialize do setup work. 3762 * Initialize do setup work.
3689 */ 3763 */
3690void ATTRIBUTE_CONSTRUCTOR 3764void ATTRIBUTE_CONSTRUCTOR
3691MHD_init () 3765MHD_init ()
3692{ 3766{
3693 mhd_panic = &mhd_panic_std; 3767 mhd_panic = &mhd_panic_std;
3694 mhd_panic_cls = NULL; 3768 mhd_panic_cls = NULL;
3695 3769
3696#ifdef WINDOWS
3697 plibc_init ("GNU", "libmicrohttpd");
3698#endif
3699#if HTTPS_SUPPORT 3770#if HTTPS_SUPPORT
3700 gcry_control (GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread); 3771 gcry_control (GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread);
3701 gnutls_global_init (); 3772 gnutls_global_init ();
@@ -3703,15 +3774,12 @@ MHD_init ()
3703} 3774}
3704 3775
3705 3776
3706void ATTRIBUTE_DESTRUCTOR 3777void ATTRIBUTE_DESTRUCTOR
3707MHD_fini () 3778MHD_fini ()
3708{ 3779{
3709#if HTTPS_SUPPORT 3780#if HTTPS_SUPPORT
3710 gnutls_global_deinit (); 3781 gnutls_global_deinit ();
3711#endif 3782#endif
3712#ifdef WINDOWS
3713 plibc_shutdown ();
3714#endif
3715} 3783}
3716 3784
3717/* end of daemon.c */ 3785/* end of daemon.c */