gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] [libmicrohttpd] branch master updated (0c8a6adb -> 0e0822dd


From: gnunet
Subject: [GNUnet-SVN] [libmicrohttpd] branch master updated (0c8a6adb -> 0e0822dd)
Date: Sun, 19 Feb 2017 21:11:29 +0100

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

karlson2k pushed a change to branch master
in repository libmicrohttpd.

    from 0c8a6adb Simplified checks for internal polling thread.
     new f05715b7 call_handlers(): no need to call read or write handler in 
case of hard error
     new b473e121 call_handlers(): use 'bool' type for parameters
     new d9b6e400 Changed poll()/select()/epoll monitoring logic: connections 
monitored for incoming data only when expecting any incoming data; connections 
always monitored for disconnection and out-of-band data; connections are closed 
faster in case of any error conditions; fixed non-zero timeout in poll() mode 
with MHD_EVENT_LOOP_INFO_BLOCK connections.
     new 58cb9681 MHD_epoll(): call handler depending on read/write ready state 
instead of loop state.
     new 0e0822dd call_handlers(): call read/write handlers only if connections 
is in read/write mode

The 5 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/microhttpd/daemon.c      | 138 ++++++++++++++++++++++---------------------
 src/microhttpd/internal.h    |   7 ++-
 src/microhttpd/mhd_sockets.h |  30 ++++++++++
 3 files changed, 106 insertions(+), 69 deletions(-)

diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c
index c83a51d5..fcd70ce1 100644
--- a/src/microhttpd/daemon.c
+++ b/src/microhttpd/daemon.c
@@ -824,17 +824,11 @@ MHD_get_fdset2 (struct MHD_Daemon *daemon,
                                     max_fd,
                                     fd_setsize))
            result = MHD_NO;
-         if ( (pos->read_buffer_size > pos->read_buffer_offset) &&
-             ! MHD_add_to_fd_set_ (pos->socket_fd,
-                                    read_fd_set,
-                                    max_fd,
-                                    fd_setsize))
-            result = MHD_NO;
          break;
        case MHD_EVENT_LOOP_INFO_BLOCK:
-         if ( (pos->read_buffer_size > pos->read_buffer_offset) &&
+         if ( (NULL == except_fd_set) ||
              ! MHD_add_to_fd_set_ (pos->socket_fd,
-                                    read_fd_set,
+                                   except_fd_set,
                                     max_fd,
                                     fd_setsize))
             result = MHD_NO;
@@ -887,9 +881,9 @@ MHD_get_fdset2 (struct MHD_Daemon *daemon,
  */
 static int
 call_handlers (struct MHD_Connection *con,
-               int read_ready,
-               int write_ready,
-               int force_close)
+               bool read_ready,
+               bool write_ready,
+               bool force_close)
 {
   int ret;
   /* Initial state of connection. */
@@ -897,15 +891,19 @@ call_handlers (struct MHD_Connection *con,
 
 #ifdef HTTPS_SUPPORT
   if (con->tls_read_ready)
-    read_ready = MHD_YES;
+    read_ready = true;
 #endif /* HTTPS_SUPPORT */
-  if (read_ready)
-    con->read_handler (con);
-  if (write_ready)
-    con->write_handler (con);
-  if (force_close)
+  if (!force_close)
+    {
+      if (MHD_EVENT_LOOP_INFO_READ == con->event_loop_info && read_ready)
+        con->read_handler (con);
+      if (MHD_EVENT_LOOP_INFO_WRITE == con->event_loop_info && write_ready)
+        con->write_handler (con);
+    }
+  else
     MHD_connection_close_ (con,
                            MHD_REQUEST_TERMINATED_WITH_ERROR);
+
   ret = con->idle_handler (con);
 
   /* Fast track for fast connections. */
@@ -1427,6 +1425,7 @@ thread_main_handle_connection (void *data)
   int num_ready;
   fd_set rs;
   fd_set ws;
+  fd_set es;
   MHD_socket maxsock;
   struct timeval tv;
   struct timeval *tvp;
@@ -1564,10 +1563,11 @@ thread_main_handle_connection (void *data)
       if (0 == (daemon->options & MHD_USE_POLL))
        {
          /* use select */
-         int err_state = 0;
+         bool err_state = false;
 
          FD_ZERO (&rs);
          FD_ZERO (&ws);
+          FD_ZERO (&es);
          maxsock = MHD_INVALID_SOCKET;
          switch (con->event_loop_info)
            {
@@ -1576,28 +1576,21 @@ thread_main_handle_connection (void *data)
                                         &rs,
                                         &maxsock,
                                         FD_SETSIZE))
-               err_state = 1;
+               err_state = true;
              break;
            case MHD_EVENT_LOOP_INFO_WRITE:
              if (! MHD_add_to_fd_set_ (con->socket_fd,
                                         &ws,
                                         &maxsock,
                                         FD_SETSIZE))
-                err_state = 1;
-             if ( (con->read_buffer_size > con->read_buffer_offset) &&
-                   (! MHD_add_to_fd_set_ (con->socket_fd,
-                                          &rs,
-                                          &maxsock,
-                                          FD_SETSIZE)) )
-               err_state = 1;
+                err_state = true;
              break;
            case MHD_EVENT_LOOP_INFO_BLOCK:
-             if ( (con->read_buffer_size > con->read_buffer_offset) &&
-                   (! MHD_add_to_fd_set_ (con->socket_fd,
-                                          &rs,
-                                          &maxsock,
-                                          FD_SETSIZE)) )
-               err_state = 1;
+             if (! MHD_add_to_fd_set_ (con->socket_fd,
+                                        &es,
+                                        &maxsock,
+                                        FD_SETSIZE))
+               err_state = true;
              tv.tv_sec = 0;
              tv.tv_usec = 0;
              tvp = &tv;
@@ -1616,7 +1609,7 @@ thread_main_handle_connection (void *data)
                 err_state = 1;
             }
 #endif
-            if (0 != err_state)
+            if (err_state)
               {
 #ifdef HAVE_MESSAGES
                 MHD_DLOG (con->daemon,
@@ -1658,7 +1651,8 @@ thread_main_handle_connection (void *data)
                                        &rs),
                              FD_ISSET (con->socket_fd,
                                        &ws),
-                             MHD_NO))
+                             FD_ISSET (con->socket_fd,
+                                       &es)) )
             goto exit;
        }
 #ifdef HAVE_POLL
@@ -1672,16 +1666,13 @@ thread_main_handle_connection (void *data)
          switch (con->event_loop_info)
            {
            case MHD_EVENT_LOOP_INFO_READ:
-             p[0].events |= POLLIN;
+             p[0].events |= POLLIN | MHD_POLL_EVENTS_ERR_DISC;
              break;
            case MHD_EVENT_LOOP_INFO_WRITE:
-             p[0].events |= POLLOUT;
-             if (con->read_buffer_size > con->read_buffer_offset)
-               p[0].events |= POLLIN;
+             p[0].events |= POLLOUT | MHD_POLL_EVENTS_ERR_DISC;
              break;
            case MHD_EVENT_LOOP_INFO_BLOCK:
-             if (con->read_buffer_size > con->read_buffer_offset)
-               p[0].events |= POLLIN;
+             p[0].events |= MHD_POLL_EVENTS_ERR_DISC;
              tv.tv_sec = 0;
              tv.tv_usec = 0;
              tvp = &tv;
@@ -1728,7 +1719,7 @@ thread_main_handle_connection (void *data)
               call_handlers (con,
                              0 != (p[0].revents & POLLIN),
                              0 != (p[0].revents & POLLOUT),
-                             0 != (p[0].revents & (POLLERR | POLLHUP))))
+                             0 != (p[0].revents & (POLLERR | 
MHD_POLL_REVENTS_ERR_DISC))))
             goto exit;
        }
 #endif
@@ -2284,7 +2275,7 @@ internal_add_connection (struct MHD_Daemon *daemon,
        {
          struct epoll_event event;
 
-         event.events = EPOLLIN | EPOLLOUT | EPOLLET;
+         event.events = EPOLLIN | EPOLLOUT | EPOLLPRI | EPOLLET;
          event.data.ptr = connection;
          if (0 != epoll_ctl (daemon->epoll_fd,
                              EPOLL_CTL_ADD,
@@ -3057,7 +3048,8 @@ MHD_run_from_select (struct MHD_Daemon *daemon,
                                    read_fd_set),
                          FD_ISSET (ds,
                                    write_fd_set),
-                         MHD_NO);
+                         FD_ISSET (ds,
+                                   except_fd_set));
         }
     }
 
@@ -3347,16 +3339,14 @@ MHD_poll_all (struct MHD_Daemon *daemon,
        switch (pos->event_loop_info)
          {
          case MHD_EVENT_LOOP_INFO_READ:
-           p[poll_server+i].events |= POLLIN;
+           p[poll_server+i].events |= POLLIN | MHD_POLL_EVENTS_ERR_DISC;
            break;
          case MHD_EVENT_LOOP_INFO_WRITE:
-           p[poll_server+i].events |= POLLOUT;
-           if (pos->read_buffer_size > pos->read_buffer_offset)
-             p[poll_server+i].events |= POLLIN;
+           p[poll_server+i].events |= POLLOUT | MHD_POLL_EVENTS_ERR_DISC;
            break;
          case MHD_EVENT_LOOP_INFO_BLOCK:
-           if (pos->read_buffer_size > pos->read_buffer_offset)
-             p[poll_server+i].events |= POLLIN;
+           p[poll_server+i].events |=  MHD_POLL_EVENTS_ERR_DISC;
+           timeout = 0;
            break;
          case MHD_EVENT_LOOP_INFO_CLEANUP:
            timeout = 0; /* clean up "pos" immediately */
@@ -3438,7 +3428,7 @@ MHD_poll_all (struct MHD_Daemon *daemon,
         call_handlers (pos,
                        0 != (p[poll_server+i].revents & POLLIN),
                        0 != (p[poll_server+i].revents & POLLOUT),
-                       MHD_NO);
+                       0 != (p[poll_server+i].revents & 
MHD_POLL_REVENTS_ERR_DISC));
         i++;
       }
 #if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
@@ -3886,12 +3876,10 @@ MHD_epoll (struct MHD_Daemon *daemon,
              connection as 'eready'. */
           pos = events[i].data.ptr;
           /* normal processing: update read/write data */
-          if (0 != (events[i].events & EPOLLIN))
+          if (0 != (events[i].events & (EPOLLPRI | EPOLLERR | EPOLLHUP)))
             {
-              pos->epoll_state |= MHD_EPOLL_STATE_READ_READY;
-              if ( ( (MHD_EVENT_LOOP_INFO_READ == pos->event_loop_info) ||
-                     (pos->read_buffer_size > pos->read_buffer_offset) ) &&
-                   (0 == (pos->epoll_state & MHD_EPOLL_STATE_IN_EREADY_EDLL) ) 
)
+              pos->epoll_state |= MHD_EPOLL_STATE_ERROR;
+              if (0 == (pos->epoll_state & MHD_EPOLL_STATE_IN_EREADY_EDLL))
                 {
                   EDLL_insert (daemon->eready_head,
                                daemon->eready_tail,
@@ -3899,16 +3887,32 @@ MHD_epoll (struct MHD_Daemon *daemon,
                   pos->epoll_state |= MHD_EPOLL_STATE_IN_EREADY_EDLL;
                 }
             }
-          if (0 != (events[i].events & EPOLLOUT))
+          else
             {
-              pos->epoll_state |= MHD_EPOLL_STATE_WRITE_READY;
-              if ( (MHD_EVENT_LOOP_INFO_WRITE == pos->event_loop_info) &&
-                   (0 == (pos->epoll_state & MHD_EPOLL_STATE_IN_EREADY_EDLL) ) 
)
+              if (0 != (events[i].events & EPOLLIN))
                 {
-                  EDLL_insert (daemon->eready_head,
-                               daemon->eready_tail,
-                               pos);
-                  pos->epoll_state |= MHD_EPOLL_STATE_IN_EREADY_EDLL;
+                  pos->epoll_state |= MHD_EPOLL_STATE_READ_READY;
+                  if ( ( (MHD_EVENT_LOOP_INFO_READ == pos->event_loop_info) ||
+                         (pos->read_buffer_size > pos->read_buffer_offset) ) &&
+                       (0 == (pos->epoll_state & 
MHD_EPOLL_STATE_IN_EREADY_EDLL) ) )
+                    {
+                      EDLL_insert (daemon->eready_head,
+                                   daemon->eready_tail,
+                                   pos);
+                      pos->epoll_state |= MHD_EPOLL_STATE_IN_EREADY_EDLL;
+                    }
+                }
+              if (0 != (events[i].events & EPOLLOUT))
+                {
+                  pos->epoll_state |= MHD_EPOLL_STATE_WRITE_READY;
+                  if ( (MHD_EVENT_LOOP_INFO_WRITE == pos->event_loop_info) &&
+                       (0 == (pos->epoll_state & 
MHD_EPOLL_STATE_IN_EREADY_EDLL) ) )
+                    {
+                      EDLL_insert (daemon->eready_head,
+                                   daemon->eready_tail,
+                                   pos);
+                      pos->epoll_state |= MHD_EPOLL_STATE_IN_EREADY_EDLL;
+                    }
                 }
             }
         }
@@ -3929,12 +3933,10 @@ MHD_epoll (struct MHD_Daemon *daemon,
   while (NULL != (pos = prev))
     {
          prev = pos->prevE;
-         /* FIXME: use (0 != pos->epoll_state & MHD_EPOLL_STATE_READ_READY) ? 
MHD_YES : MHD_NO
-          * and (0 != pos->epoll_state & MHD_EPOLL_STATE_WRITE_READY) ? 
MHD_YES : MHD_NO */
       call_handlers (pos,
-                     (MHD_EVENT_LOOP_INFO_READ == pos->event_loop_info) ? 
MHD_YES : MHD_NO,
-                     (MHD_EVENT_LOOP_INFO_WRITE == pos->event_loop_info) ? 
MHD_YES : MHD_NO,
-                     MHD_NO);
+                     0 != (pos->epoll_state & MHD_EPOLL_STATE_READ_READY),
+                     0 != (pos->epoll_state & MHD_EPOLL_STATE_WRITE_READY),
+                     0 != (pos->epoll_state & MHD_EPOLL_STATE_ERROR));
       if (MHD_EPOLL_STATE_IN_EREADY_EDLL ==
             (pos->epoll_state & (MHD_EPOLL_STATE_SUSPENDED | 
MHD_EPOLL_STATE_IN_EREADY_EDLL)))
         {
diff --git a/src/microhttpd/internal.h b/src/microhttpd/internal.h
index 95163461..4f2eac38 100644
--- a/src/microhttpd/internal.h
+++ b/src/microhttpd/internal.h
@@ -155,7 +155,12 @@ enum MHD_EpollState
   /**
    * Is this connection currently suspended?
    */
-  MHD_EPOLL_STATE_SUSPENDED = 16
+  MHD_EPOLL_STATE_SUSPENDED = 16,
+
+  /**
+   * Is this connection in some error state?
+   */
+  MHD_EPOLL_STATE_ERROR = 128
 };
 
 
diff --git a/src/microhttpd/mhd_sockets.h b/src/microhttpd/mhd_sockets.h
index d160dbcd..6b3261c3 100644
--- a/src/microhttpd/mhd_sockets.h
+++ b/src/microhttpd/mhd_sockets.h
@@ -339,6 +339,36 @@
 #  else  /* MHD_WINSOCK_SOCKETS */
 #    define MHD_sys_poll_ WSAPoll
 #  endif /* MHD_WINSOCK_SOCKETS */
+
+#  ifdef POLLPRI
+#    define MHD_POLLPRI_OR_ZERO POLLPRI
+#  else  /* ! POLLPRI */
+#    define MHD_POLLPRI_OR_ZERO 0
+#  endif /* ! POLLPRI */
+#  ifdef POLLRDBAND
+#    define MHD_POLLRDBAND_OR_ZERO POLLRDBAND
+#  else  /* ! POLLRDBAND */
+#    define MHD_POLLRDBAND_OR_ZERO 0
+#  endif /* ! POLLRDBAND */
+#  ifdef POLLNVAL
+#    define MHD_POLLNVAL_OR_ZERO POLLNVAL
+#  else  /* ! POLLNVAL */
+#    define MHD_POLLNVAL_OR_ZERO 0
+#  endif /* ! POLLNVAL */
+
+/* MHD_POLL_EVENTS_ERR_DISC is 'events' mask for errors and disconnect.
+ * Note: Out-of-band data is treated as error. */
+#  if defined(_WIN32)
+#    define MHD_POLL_EVENTS_ERR_DISC POLLRDBAND
+#  elif defined(__linux__)
+#    define MHD_POLL_EVENTS_ERR_DISC POLLPRI
+#  else /* ! __linux__ */
+#    define MHD_POLL_EVENTS_ERR_DISC (MHD_POLLPRI_OR_ZERO | 
MHD_POLLRDBAND_OR_ZERO)
+#  endif /* ! __linux__ */
+/* MHD_POLL_REVENTS_ERR_DISC is 'revents' mask for errors and disconnect.
+ * Note: Out-of-band data is treated as error. */
+#  define MHD_POLL_REVENTS_ERR_DISC \
+     (MHD_POLLPRI_OR_ZERO | MHD_POLLRDBAND_OR_ZERO | MHD_POLLNVAL_OR_ZERO | 
POLLERR | POLLHUP)
 #endif /* HAVE_POLL */
 
 #define MHD_SCKT_MISSING_ERR_CODE_ 31450

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



reply via email to

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