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.c96
1 files changed, 73 insertions, 23 deletions
diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c
index d006f605..037d87d2 100644
--- a/src/microhttpd/daemon.c
+++ b/src/microhttpd/daemon.c
@@ -696,7 +696,14 @@ MHD_get_fdset (struct MHD_Daemon *daemon,
696 write_fd_set, 696 write_fd_set,
697 except_fd_set, 697 except_fd_set,
698 max_fd, 698 max_fd,
699 _MHD_SYS_DEFAULT_FD_SETSIZE); 699#ifdef HAS_FD_SETSIZE_OVERRIDABLE
700 daemon->fdset_size_set_by_app ?
701 ((unsigned int) daemon->fdset_size) :
702 ((unsigned int) _MHD_SYS_DEFAULT_FD_SETSIZE)
703#else /* ! HAS_FD_SETSIZE_OVERRIDABLE */
704 ((unsigned int) _MHD_SYS_DEFAULT_FD_SETSIZE)
705#endif /* ! HAS_FD_SETSIZE_OVERRIDABLE */
706 );
700} 707}
701 708
702 709
@@ -746,7 +753,8 @@ urh_to_fdset (struct MHD_UpgradeResponseHandle *urh,
746 if ((0 == (urh->app.celi & MHD_EPOLL_STATE_ERROR)) && 753 if ((0 == (urh->app.celi & MHD_EPOLL_STATE_ERROR)) &&
747 ((0 != urh->in_buffer_size) || 754 ((0 != urh->in_buffer_size) ||
748 (0 != urh->out_buffer_size) || 755 (0 != urh->out_buffer_size) ||
749 (0 != urh->out_buffer_used))) 756 (0 != urh->out_buffer_used))
757 && (NULL != es))
750 MHD_add_to_fd_set_ (conn_sckt, 758 MHD_add_to_fd_set_ (conn_sckt,
751 es, 759 es,
752 max_fd, 760 max_fd,
@@ -771,7 +779,8 @@ urh_to_fdset (struct MHD_UpgradeResponseHandle *urh,
771 if ((0 == (urh->mhd.celi & MHD_EPOLL_STATE_ERROR)) && 779 if ((0 == (urh->mhd.celi & MHD_EPOLL_STATE_ERROR)) &&
772 ((0 != urh->out_buffer_size) || 780 ((0 != urh->out_buffer_size) ||
773 (0 != urh->in_buffer_size) || 781 (0 != urh->in_buffer_size) ||
774 (0 != urh->in_buffer_used))) 782 (0 != urh->in_buffer_used))
783 && (NULL != es))
775 MHD_add_to_fd_set_ (mhd_sckt, 784 MHD_add_to_fd_set_ (mhd_sckt,
776 es, 785 es,
777 max_fd, 786 max_fd,
@@ -985,10 +994,11 @@ internal_get_fdset2 (struct MHD_Daemon *daemon,
985 fd_setsize)) 994 fd_setsize))
986 result = MHD_NO; 995 result = MHD_NO;
987#ifdef MHD_POSIX_SOCKETS 996#ifdef MHD_POSIX_SOCKETS
988 MHD_add_to_fd_set_ (pos->socket_fd, 997 if (NULL != except_fd_set)
989 except_fd_set, 998 MHD_add_to_fd_set_ (pos->socket_fd,
990 max_fd, 999 except_fd_set,
991 fd_setsize); 1000 max_fd,
1001 fd_setsize);
992#endif /* MHD_POSIX_SOCKETS */ 1002#endif /* MHD_POSIX_SOCKETS */
993 break; 1003 break;
994 case MHD_EVENT_LOOP_INFO_WRITE: 1004 case MHD_EVENT_LOOP_INFO_WRITE:
@@ -998,10 +1008,11 @@ internal_get_fdset2 (struct MHD_Daemon *daemon,
998 fd_setsize)) 1008 fd_setsize))
999 result = MHD_NO; 1009 result = MHD_NO;
1000#ifdef MHD_POSIX_SOCKETS 1010#ifdef MHD_POSIX_SOCKETS
1001 MHD_add_to_fd_set_ (pos->socket_fd, 1011 if (NULL != except_fd_set)
1002 except_fd_set, 1012 MHD_add_to_fd_set_ (pos->socket_fd,
1003 max_fd, 1013 except_fd_set,
1004 fd_setsize); 1014 max_fd,
1015 fd_setsize);
1005#endif /* MHD_POSIX_SOCKETS */ 1016#endif /* MHD_POSIX_SOCKETS */
1006 break; 1017 break;
1007 case MHD_EVENT_LOOP_INFO_PROCESS: 1018 case MHD_EVENT_LOOP_INFO_PROCESS:
@@ -1021,13 +1032,16 @@ internal_get_fdset2 (struct MHD_Daemon *daemon,
1021 /* W32 use limited array for fd_set so add INFO_READ/INFO_WRITE sockets 1032 /* W32 use limited array for fd_set so add INFO_READ/INFO_WRITE sockets
1022 * only after INFO_BLOCK sockets to ensure that INFO_BLOCK sockets will 1033 * only after INFO_BLOCK sockets to ensure that INFO_BLOCK sockets will
1023 * not be pushed out. */ 1034 * not be pushed out. */
1024 for (pos = daemon->connections_tail; NULL != pos; pos = posn) 1035 if (NULL != except_fd_set)
1025 { 1036 {
1026 posn = pos->prev; 1037 for (pos = daemon->connections_tail; NULL != pos; pos = posn)
1027 MHD_add_to_fd_set_ (pos->socket_fd, 1038 {
1028 except_fd_set, 1039 posn = pos->prev;
1029 max_fd, 1040 MHD_add_to_fd_set_ (pos->socket_fd,
1030 fd_setsize); 1041 except_fd_set,
1042 max_fd,
1043 fd_setsize);
1044 }
1031 } 1045 }
1032#endif /* MHD_WINSOCK_SOCKETS */ 1046#endif /* MHD_WINSOCK_SOCKETS */
1033#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT) 1047#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
@@ -1101,8 +1115,6 @@ MHD_get_fdset2 (struct MHD_Daemon *daemon,
1101 MHD_socket *max_fd, 1115 MHD_socket *max_fd,
1102 unsigned int fd_setsize) 1116 unsigned int fd_setsize)
1103{ 1117{
1104 fd_set es;
1105
1106 if ( (NULL == daemon) || 1118 if ( (NULL == daemon) ||
1107 (NULL == read_fd_set) || 1119 (NULL == read_fd_set) ||
1108 (NULL == write_fd_set) || 1120 (NULL == write_fd_set) ||
@@ -1110,16 +1122,54 @@ MHD_get_fdset2 (struct MHD_Daemon *daemon,
1110 MHD_D_IS_USING_POLL_ (daemon)) 1122 MHD_D_IS_USING_POLL_ (daemon))
1111 return MHD_NO; 1123 return MHD_NO;
1112 1124
1113 if (NULL == except_fd_set)
1114 { /* Workaround to maintain backward compatibility. */
1115#ifdef HAVE_MESSAGES 1125#ifdef HAVE_MESSAGES
1126 if (NULL == except_fd_set)
1127 {
1116 MHD_DLOG (daemon, 1128 MHD_DLOG (daemon,
1117 _ ("MHD_get_fdset2() called with except_fd_set " 1129 _ ("MHD_get_fdset2() called with except_fd_set "
1118 "set to NULL. Such behavior is unsupported.\n")); 1130 "set to NULL. Such behavior is unsupported.\n"));
1131 }
1119#endif 1132#endif
1120 FD_ZERO (&es); 1133
1121 except_fd_set = &es; 1134#ifdef HAS_FD_SETSIZE_OVERRIDABLE
1135 if (((unsigned int) INT_MAX) < fd_setsize)
1136 fd_setsize = (unsigned int) INT_MAX;
1137#ifdef HAVE_MESSAGES
1138 else if (daemon->fdset_size > ((int) fd_setsize))
1139 {
1140 if (daemon->fdset_size_set_by_app)
1141 {
1142 MHD_DLOG (daemon,
1143 _ ("MHD_get_fdset2() called with fd_setsize (%u) " \
1144 "less than value set by MHD_OPTION_APP_FD_SETSIZE (%d). " \
1145 "Some socket FDs may be not added. " \
1146 "Use MHD_OPTION_APP_FD_SETSIZE with the correct value.\n"),
1147 fd_setsize, daemon->fdset_size);
1148 }
1149 else
1150 {
1151 MHD_DLOG (daemon,
1152 _ ("MHD_get_fdset2() called with fd_setsize (%u) " \
1153 "less than FD_SETSIZE used by MHD (%d). " \
1154 "Some socket FDs may be not added. " \
1155 "Consider using MHD_OPTION_APP_FD_SETSIZE option.\n"),
1156 fd_setsize, daemon->fdset_size);
1157 }
1158 }
1159#endif /* HAVE_MESSAGES */
1160#else /* ! HAS_FD_SETSIZE_OVERRIDABLE */
1161 if (((unsigned int) FD_SETSIZE) > fd_setsize)
1162 {
1163#ifdef HAVE_MESSAGES
1164 MHD_DLOG (daemon,
1165 _ ("MHD_get_fdset2() called with fd_setsize (%u) " \
1166 "less than fixed FD_SETSIZE value (%d) used on the " \
1167 "platform.\n"),
1168 fd_setsize, (int) FD_SETSIZE);
1169#endif /* HAVE_MESSAGES */
1170 return MHD_NO;
1122 } 1171 }
1172#endif /* ! HAS_FD_SETSIZE_OVERRIDABLE */
1123 1173
1124#ifdef EPOLL_SUPPORT 1174#ifdef EPOLL_SUPPORT
1125 if (MHD_D_IS_USING_EPOLL_ (daemon)) 1175 if (MHD_D_IS_USING_EPOLL_ (daemon))