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.c129
1 files changed, 91 insertions, 38 deletions
diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c
index 6a112546..e5384c59 100644
--- a/src/microhttpd/daemon.c
+++ b/src/microhttpd/daemon.c
@@ -889,13 +889,9 @@ urh_from_pollfd(struct MHD_UpgradeResponseHandle *urh,
889} 889}
890#endif /* HTTPS_SUPPORT && UPGRADE_SUPPORT */ 890#endif /* HTTPS_SUPPORT && UPGRADE_SUPPORT */
891 891
892
892/** 893/**
893 * Obtain the `select()` sets for this daemon. 894 * Internal version of #MHD_get_fdset2().
894 * Daemon's FDs will be added to fd_sets. To get only
895 * daemon FDs in fd_sets, call FD_ZERO for each fd_set
896 * before calling this function. Passing custom FD_SETSIZE
897 * as @a fd_setsize allow usage of larger/smaller than
898 * platform's default fd_sets.
899 * 895 *
900 * @param daemon daemon to get sets from 896 * @param daemon daemon to get sets from
901 * @param read_fd_set read set 897 * @param read_fd_set read set
@@ -904,44 +900,27 @@ urh_from_pollfd(struct MHD_UpgradeResponseHandle *urh,
904 * @param max_fd increased to largest FD added (if larger 900 * @param max_fd increased to largest FD added (if larger
905 * than existing value); can be NULL 901 * than existing value); can be NULL
906 * @param fd_setsize value of FD_SETSIZE 902 * @param fd_setsize value of FD_SETSIZE
907 * @return #MHD_YES on success, #MHD_NO if this 903 * @return #MHD_YES on success, #MHD_NO if any FD didn't
908 * daemon was not started with the right
909 * options for this call or any FD didn't
910 * fit fd_set. 904 * fit fd_set.
911 * @ingroup event 905 * @ingroup event
912 */ 906 */
913int 907int
914MHD_get_fdset2 (struct MHD_Daemon *daemon, 908internal_get_fdset2 (struct MHD_Daemon *daemon,
915 fd_set *read_fd_set, 909 fd_set *read_fd_set,
916 fd_set *write_fd_set, 910 fd_set *write_fd_set,
917 fd_set *except_fd_set, 911 fd_set *except_fd_set,
918 MHD_socket *max_fd, 912 MHD_socket *max_fd,
919 unsigned int fd_setsize) 913 unsigned int fd_setsize)
914
920{ 915{
921 struct MHD_Connection *pos; 916 struct MHD_Connection *pos;
922 struct MHD_Connection *posn; 917 struct MHD_Connection *posn;
923 int result = MHD_YES; 918 int result = MHD_YES;
924 MHD_socket ls; 919 MHD_socket ls;
925 920
926 if ( (NULL == daemon) || 921 if (daemon->shutdown)
927 (NULL == read_fd_set) ||
928 (NULL == write_fd_set) ||
929 (daemon->shutdown) ||
930 (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) ||
931 (0 != (daemon->options & MHD_USE_POLL)))
932 return MHD_NO; 922 return MHD_NO;
933#ifdef EPOLL_SUPPORT
934 if (0 != (daemon->options & MHD_USE_EPOLL))
935 {
936 /* we're in epoll mode, use the epoll FD as a stand-in for
937 the entire event set */
938 923
939 return MHD_add_to_fd_set_ (daemon->epoll_fd,
940 read_fd_set,
941 max_fd,
942 fd_setsize) ? MHD_YES : MHD_NO;
943 }
944#endif
945 ls = daemon->listen_fd; 924 ls = daemon->listen_fd;
946 if ( (MHD_INVALID_SOCKET != ls) && 925 if ( (MHD_INVALID_SOCKET != ls) &&
947 (! daemon->was_quiesced) && 926 (! daemon->was_quiesced) &&
@@ -1043,6 +1022,80 @@ MHD_get_fdset2 (struct MHD_Daemon *daemon,
1043 1022
1044 1023
1045/** 1024/**
1025 * Obtain the `select()` sets for this daemon.
1026 * Daemon's FDs will be added to fd_sets. To get only
1027 * daemon FDs in fd_sets, call FD_ZERO for each fd_set
1028 * before calling this function. Passing custom FD_SETSIZE
1029 * as @a fd_setsize allow usage of larger/smaller than
1030 * platform's default fd_sets.
1031 *
1032 * This function could be called only for daemon started
1033 * without MHD_USE_INTERNAL_POLLING_THREAD flag.
1034 *
1035 * @param daemon daemon to get sets from
1036 * @param read_fd_set read set
1037 * @param write_fd_set write set
1038 * @param except_fd_set except set
1039 * @param max_fd increased to largest FD added (if larger
1040 * than existing value); can be NULL
1041 * @param fd_setsize value of FD_SETSIZE
1042 * @return #MHD_YES on success, #MHD_NO if this
1043 * daemon was not started with the right
1044 * options for this call or any FD didn't
1045 * fit fd_set.
1046 * @ingroup event
1047 */
1048int
1049MHD_get_fdset2 (struct MHD_Daemon *daemon,
1050 fd_set *read_fd_set,
1051 fd_set *write_fd_set,
1052 fd_set *except_fd_set,
1053 MHD_socket *max_fd,
1054 unsigned int fd_setsize)
1055{
1056 fd_set es;
1057
1058 if ( (NULL == daemon) ||
1059 (NULL == read_fd_set) ||
1060 (NULL == write_fd_set) ||
1061 (0 != (daemon->options & MHD_USE_INTERNAL_POLLING_THREAD)) ||
1062 (0 != (daemon->options & MHD_USE_POLL)))
1063 return MHD_NO;
1064
1065 if (NULL == except_fd_set)
1066 { /* Workaround to maintain backward compatibility. */
1067#ifdef HAVE_MESSAGES
1068 MHD_DLOG (daemon,
1069 _("MHD_get_fdset2() called with except_fd_set "
1070 "set to NULL. Such behavior is unsupported.\n"));
1071#endif
1072 except_fd_set = es;
1073 FD_ZERO(except_fd_set);
1074 }
1075
1076#ifdef EPOLL_SUPPORT
1077 if (0 != (daemon->options & MHD_USE_EPOLL))
1078 {
1079 if (daemon->shutdown)
1080 return MHD_NO;
1081
1082 /* we're in epoll mode, use the epoll FD as a stand-in for
1083 the entire event set */
1084
1085 return MHD_add_to_fd_set_ (daemon->epoll_fd,
1086 read_fd_set,
1087 max_fd,
1088 fd_setsize) ? MHD_YES : MHD_NO;
1089 }
1090#endif
1091
1092 return internal_get_fdset2 (daemon, read_fd_set,
1093 write_fd_set, except_fd_set,
1094 max_fd, fd_setsize);
1095}
1096
1097
1098/**
1046 * Call the handlers for a connection in the appropriate order based 1099 * Call the handlers for a connection in the appropriate order based
1047 * on the readiness as detected by the event loop. 1100 * on the readiness as detected by the event loop.
1048 * 1101 *
@@ -3397,12 +3450,12 @@ MHD_select (struct MHD_Daemon *daemon,
3397 3450
3398 /* single-threaded, go over everything */ 3451 /* single-threaded, go over everything */
3399 if (MHD_NO == 3452 if (MHD_NO ==
3400 MHD_get_fdset2 (daemon, 3453 internal_get_fdset2 (daemon,
3401 &rs, 3454 &rs,
3402 &ws, 3455 &ws,
3403 &es, 3456 &es,
3404 &maxsock, 3457 &maxsock,
3405 FD_SETSIZE)) 3458 FD_SETSIZE))
3406 { 3459 {
3407#ifdef HAVE_MESSAGES 3460#ifdef HAVE_MESSAGES
3408 MHD_DLOG (daemon, 3461 MHD_DLOG (daemon,