gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] [libmicrohttpd] branch master updated (aac24654 -> 244ef608


From: gnunet
Subject: [GNUnet-SVN] [libmicrohttpd] branch master updated (aac24654 -> 244ef608)
Date: Tue, 14 Mar 2017 22:54:05 +0100

This is an automated email from the git hooks/post-receive script.

karlson2k pushed a change to branch master
in repository libmicrohttpd.

    from aac24654 Upgraded: fixed check for error state on socket
     new 4c219bf5 Prevent calling of MHD_get_fdset() and MHD_get_fdset2() for 
daemons with MHD_USE_INTERNAL_POLLING_THREAD, maintain backward compatibility
     new 244ef608 Prevent run of MHD_run_from_select() for daemon started with 
wrong flags. Maintain backward compatibility with except_fd_set set to NULL.

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/include/microhttpd.h |  14 ++-
 src/microhttpd/daemon.c  | 218 ++++++++++++++++++++++++++++++++++-------------
 2 files changed, 174 insertions(+), 58 deletions(-)

diff --git a/src/include/microhttpd.h b/src/include/microhttpd.h
index c887b714..c1461988 100644
--- a/src/include/microhttpd.h
+++ b/src/include/microhttpd.h
@@ -2153,6 +2153,9 @@ MHD_add_connection (struct MHD_Daemon *daemon,
  * before calling this function. FD_SETSIZE is assumed
  * to be platform's default.
  *
+ * This function could be called only for daemon started
+ * without MHD_USE_INTERNAL_POLLING_THREAD flag.
+ *
  * @param daemon daemon to get sets from
  * @param read_fd_set read set
  * @param write_fd_set write set
@@ -2181,6 +2184,9 @@ MHD_get_fdset (struct MHD_Daemon *daemon,
  * as @a fd_setsize allow usage of larger/smaller than
  * platform's default fd_sets.
  *
+ * This function could be called only for daemon started
+ * without MHD_USE_INTERNAL_POLLING_THREAD flag.
+ *
  * @param daemon daemon to get sets from
  * @param read_fd_set read set
  * @param write_fd_set write set
@@ -2210,6 +2216,9 @@ MHD_get_fdset2 (struct MHD_Daemon *daemon,
  * before calling this function. Size of fd_set is
  * determined by current value of FD_SETSIZE.
  *
+ * This function could be called only for daemon started
+ * without MHD_USE_INTERNAL_POLLING_THREAD flag.
+ *
  * @param daemon daemon to get sets from
  * @param read_fd_set read set
  * @param write_fd_set write set
@@ -2280,10 +2289,13 @@ MHD_run (struct MHD_Daemon *daemon);
  * not have to call `select()` again to determine which operations are
  * ready.
  *
+ * This function cannot be used with daemon started with
+ * MHD_USE_INTERNAL_POLLING_THREAD flag.
+ *
  * @param daemon daemon to run select loop for
  * @param read_fd_set read set
  * @param write_fd_set write set
- * @param except_fd_set except set (not used, can be NULL)
+ * @param except_fd_set except set
  * @return #MHD_NO on serious errors, #MHD_YES on success
  * @ingroup event
  */
diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c
index 6a112546..23310faf 100644
--- a/src/microhttpd/daemon.c
+++ b/src/microhttpd/daemon.c
@@ -889,13 +889,9 @@ urh_from_pollfd(struct MHD_UpgradeResponseHandle *urh,
 }
 #endif /* HTTPS_SUPPORT && UPGRADE_SUPPORT */
 
+
 /**
- * Obtain the `select()` sets for this daemon.
- * Daemon's FDs will be added to fd_sets. To get only
- * daemon FDs in fd_sets, call FD_ZERO for each fd_set
- * before calling this function. Passing custom FD_SETSIZE
- * as @a fd_setsize allow usage of larger/smaller than
- * platform's default fd_sets.
+ * Internal version of #MHD_get_fdset2().
  *
  * @param daemon daemon to get sets from
  * @param read_fd_set read set
@@ -904,44 +900,27 @@ urh_from_pollfd(struct MHD_UpgradeResponseHandle *urh,
  * @param max_fd increased to largest FD added (if larger
  *               than existing value); can be NULL
  * @param fd_setsize value of FD_SETSIZE
- * @return #MHD_YES on success, #MHD_NO if this
- *         daemon was not started with the right
- *         options for this call or any FD didn't
+ * @return #MHD_YES on success, #MHD_NO if any FD didn't
  *         fit fd_set.
  * @ingroup event
  */
 int
-MHD_get_fdset2 (struct MHD_Daemon *daemon,
-               fd_set *read_fd_set,
-               fd_set *write_fd_set,
-               fd_set *except_fd_set,
-               MHD_socket *max_fd,
-               unsigned int fd_setsize)
+internal_get_fdset2 (struct MHD_Daemon *daemon,
+                     fd_set *read_fd_set,
+                     fd_set *write_fd_set,
+                     fd_set *except_fd_set,
+                     MHD_socket *max_fd,
+                     unsigned int fd_setsize)
+
 {
   struct MHD_Connection *pos;
   struct MHD_Connection *posn;
   int result = MHD_YES;
   MHD_socket ls;
 
-  if ( (NULL == daemon) ||
-       (NULL == read_fd_set) ||
-       (NULL == write_fd_set) ||
-       (daemon->shutdown) ||
-       (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) ||
-       (0 != (daemon->options & MHD_USE_POLL)))
+  if (daemon->shutdown)
     return MHD_NO;
-#ifdef EPOLL_SUPPORT
-  if (0 != (daemon->options & MHD_USE_EPOLL))
-    {
-      /* we're in epoll mode, use the epoll FD as a stand-in for
-        the entire event set */
 
-      return MHD_add_to_fd_set_ (daemon->epoll_fd,
-                                 read_fd_set,
-                                 max_fd,
-                                 fd_setsize) ? MHD_YES : MHD_NO;
-    }
-#endif
   ls = daemon->listen_fd;
   if ( (MHD_INVALID_SOCKET != ls) &&
        (! daemon->was_quiesced) &&
@@ -1043,6 +1022,80 @@ MHD_get_fdset2 (struct MHD_Daemon *daemon,
 
 
 /**
+ * Obtain the `select()` sets for this daemon.
+ * Daemon's FDs will be added to fd_sets. To get only
+ * daemon FDs in fd_sets, call FD_ZERO for each fd_set
+ * before calling this function. Passing custom FD_SETSIZE
+ * as @a fd_setsize allow usage of larger/smaller than
+ * platform's default fd_sets.
+ *
+ * This function could be called only for daemon started
+ * without MHD_USE_INTERNAL_POLLING_THREAD flag.
+ *
+ * @param daemon daemon to get sets from
+ * @param read_fd_set read set
+ * @param write_fd_set write set
+ * @param except_fd_set except set
+ * @param max_fd increased to largest FD added (if larger
+ *               than existing value); can be NULL
+ * @param fd_setsize value of FD_SETSIZE
+ * @return #MHD_YES on success, #MHD_NO if this
+ *         daemon was not started with the right
+ *         options for this call or any FD didn't
+ *         fit fd_set.
+ * @ingroup event
+ */
+int
+MHD_get_fdset2 (struct MHD_Daemon *daemon,
+               fd_set *read_fd_set,
+               fd_set *write_fd_set,
+               fd_set *except_fd_set,
+               MHD_socket *max_fd,
+               unsigned int fd_setsize)
+{
+  fd_set es;
+
+  if ( (NULL == daemon) ||
+       (NULL == read_fd_set) ||
+       (NULL == write_fd_set) ||
+       (0 != (daemon->options & MHD_USE_INTERNAL_POLLING_THREAD)) ||
+       (0 != (daemon->options & MHD_USE_POLL)))
+    return MHD_NO;
+
+  if (NULL == except_fd_set)
+    { /* Workaround to maintain backward compatibility. */
+#ifdef HAVE_MESSAGES
+      MHD_DLOG (daemon,
+                _("MHD_get_fdset2() called with except_fd_set "
+                  "set to NULL. Such behavior is unsupported.\n"));
+#endif
+      except_fd_set = es;
+      FD_ZERO(except_fd_set);
+    }
+
+#ifdef EPOLL_SUPPORT
+  if (0 != (daemon->options & MHD_USE_EPOLL))
+    {
+      if (daemon->shutdown)
+        return MHD_NO;
+
+      /* we're in epoll mode, use the epoll FD as a stand-in for
+         the entire event set */
+
+      return MHD_add_to_fd_set_ (daemon->epoll_fd,
+                                 read_fd_set,
+                                 max_fd,
+                                 fd_setsize) ? MHD_YES : MHD_NO;
+    }
+#endif
+
+  return internal_get_fdset2 (daemon, read_fd_set,
+                              write_fd_set, except_fd_set,
+                              max_fd, fd_setsize);
+}
+
+
+/**
  * Call the handlers for a connection in the appropriate order based
  * on the readiness as detected by the event loop.
  *
@@ -3235,16 +3288,7 @@ MHD_get_timeout (struct MHD_Daemon *daemon,
 
 
 /**
- * Run webserver operations. This method should be called by clients
- * in combination with #MHD_get_fdset if the client-controlled select
- * method is used.
- *
- * You can use this function instead of #MHD_run if you called
- * `select()` on the result from #MHD_get_fdset.  File descriptors in
- * the sets that are not controlled by MHD will be ignored.  Calling
- * this function instead of #MHD_run is more efficient as MHD will
- * not have to call `select()` again to determine which operations are
- * ready.
+ * Internal version of #MHD_run_from_select().
  *
  * @param daemon daemon to run select loop for
  * @param read_fd_set read set
@@ -3254,10 +3298,10 @@ MHD_get_timeout (struct MHD_Daemon *daemon,
  * @ingroup event
  */
 int
-MHD_run_from_select (struct MHD_Daemon *daemon,
-                    const fd_set *read_fd_set,
-                    const fd_set *write_fd_set,
-                    const fd_set *except_fd_set)
+internal_run_from_select (struct MHD_Daemon *daemon,
+                          const fd_set *read_fd_set,
+                          const fd_set *write_fd_set,
+                          const fd_set *except_fd_set)
 {
   MHD_socket ds;
   struct MHD_Connection *pos;
@@ -3358,8 +3402,68 @@ MHD_run_from_select (struct MHD_Daemon *daemon,
 
 
 /**
+ * Run webserver operations. This method should be called by clients
+ * in combination with #MHD_get_fdset if the client-controlled select
+ * method is used.
+ *
+ * You can use this function instead of #MHD_run if you called
+ * `select()` on the result from #MHD_get_fdset.  File descriptors in
+ * the sets that are not controlled by MHD will be ignored.  Calling
+ * this function instead of #MHD_run is more efficient as MHD will
+ * not have to call `select()` again to determine which operations are
+ * ready.
+ *
+ * This function cannot be used with daemon started with
+ * MHD_USE_INTERNAL_POLLING_THREAD flag.
+ *
+ * @param daemon daemon to run select loop for
+ * @param read_fd_set read set
+ * @param write_fd_set write set
+ * @param except_fd_set except set
+ * @return #MHD_NO on serious errors, #MHD_YES on success
+ * @ingroup event
+ */
+int
+MHD_run_from_select (struct MHD_Daemon *daemon,
+                     const fd_set *read_fd_set,
+                     const fd_set *write_fd_set,
+                     const fd_set *except_fd_set)
+{
+  fd_set es;
+  if (0 != (daemon->options &
+        (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_POLL)) )
+    return MHD_NO;
+  if (NULL == read_fd_set || NULL == write_fd_set)
+    return MHD_NO;
+  if (NULL == except_fd_set)
+    { /* Workaround to maintain backward compatibility. */
+#ifdef HAVE_MESSAGES
+      MHD_DLOG (daemon,
+                _("MHD_run_from_select() called with except_fd_set "
+                  "set to NULL. Such behavior is deprecated.\n"));
+#endif
+      except_fd_set = es;
+      FD_ZERO(except_fd_set);
+    }
+  if (0 != (daemon->options & MHD_USE_EPOLL))
+    {
+#ifdef EPOLL_SUPPORT
+      int ret;
+      ret = MHD_epoll (daemon, MHD_NO);
+      MHD_cleanup_connections (daemon);
+      return ret;
+#else  /* ! EPOLL_SUPPORT */
+      return MHD_NO;
+#endif /* ! EPOLL_SUPPORT */
+    }
+  return internal_run_from_select (daemon, read_fd_set,
+                                   write_fd_set, except_fd_set);
+}
+
+
+/**
  * Main internal select() call.  Will compute select sets, call select()
- * and then #MHD_run_from_select with the result.
+ * and then #internal_run_from_select with the result.
  *
  * @param daemon daemon to run select() loop for
  * @param may_block #MHD_YES if blocking, #MHD_NO if non-blocking
@@ -3397,12 +3501,12 @@ MHD_select (struct MHD_Daemon *daemon,
 
       /* single-threaded, go over everything */
       if (MHD_NO ==
-          MHD_get_fdset2 (daemon,
-                          &rs,
-                          &ws,
-                          &es,
-                          &maxsock,
-                          FD_SETSIZE))
+          internal_get_fdset2 (daemon,
+                               &rs,
+                               &ws,
+                               &es,
+                               &maxsock,
+                               FD_SETSIZE))
         {
 #ifdef HAVE_MESSAGES
         MHD_DLOG (daemon,
@@ -3513,10 +3617,10 @@ MHD_select (struct MHD_Daemon *daemon,
 #endif
       return MHD_NO;
     }
-  if (MHD_YES == MHD_run_from_select (daemon,
-                                      &rs,
-                                      &ws,
-                                      &es))
+  if (MHD_YES == internal_run_from_select (daemon,
+                                           &rs,
+                                           &ws,
+                                           &es))
     return (MHD_NO == err_state) ? MHD_YES : MHD_NO;
   return MHD_NO;
 }

-- 
To stop receiving notification emails like this one, please contact
address@hidden



reply via email to

[Prev in Thread] Current Thread [Next in Thread]