gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] [libmicrohttpd] branch master updated (dd2d724c -> d686cb08


From: gnunet
Subject: [GNUnet-SVN] [libmicrohttpd] branch master updated (dd2d724c -> d686cb08)
Date: Sun, 26 Feb 2017 22:25:34 +0100

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

karlson2k pushed a change to branch master
in repository libmicrohttpd.

    from dd2d724c Reworked handling "already ready" situations: * busy-waiting 
for write if TLS connection is in MHD_EVENT_LOOP_INFO_WRITE mode and data is 
pending in TLS buffers * removed calculation of number of TLS read-ready 
connections * simplified and unified processing if any connection is in 
MHD_EVENT_LOOP_INFO_BLOCK mode
     new 961df2c7 process_urh(): simple optimization
     new d686cb08 Fixed: EINTERRUPTED and GNUTLS_E_INTERRUPTED must not clear 
read/write ready flag

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/microhttpd/daemon.c | 75 ++++++++++++++++++++++++++-----------------------
 1 file changed, 40 insertions(+), 35 deletions(-)

diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c
index b93367b8..00ad2ed6 100644
--- a/src/microhttpd/daemon.c
+++ b/src/microhttpd/daemon.c
@@ -436,7 +436,8 @@ recv_tls_adapter (struct MHD_Connection *connection,
     {
       MHD_socket_set_error_ (MHD_SCKT_EINTR_);
 #ifdef EPOLL_SUPPORT
-      connection->epoll_state &= ~MHD_EPOLL_STATE_READ_READY;
+      if (GNUTLS_E_AGAIN == res)
+        connection->epoll_state &= ~MHD_EPOLL_STATE_READ_READY;
 #endif
       return -1;
     }
@@ -480,7 +481,8 @@ send_tls_adapter (struct MHD_Connection *connection,
     {
       MHD_socket_set_error_ (MHD_SCKT_EINTR_);
 #ifdef EPOLL_SUPPORT
-      connection->epoll_state &= ~MHD_EPOLL_STATE_WRITE_READY;
+      if (GNUTLS_E_AGAIN == res)
+        connection->epoll_state &= ~MHD_EPOLL_STATE_WRITE_READY;
 #endif
       return -1;
     }
@@ -1012,13 +1014,19 @@ MHD_cleanup_upgraded_connection_ (struct MHD_Connection 
*connection)
 static void
 process_urh (struct MHD_UpgradeResponseHandle *urh)
 {
-  if (urh->connection->daemon->shutdown)
+  /* Help compiler to optimize:
+   * pointers to 'connection' and 'daemon' are not changed
+   * during this processing, so no need to chain dereference
+   * each time. */
+  struct MHD_Connection * const connection = urh->connection;
+  struct MHD_Daemon * const daemon = connection->daemon;
+  if (daemon->shutdown)
     {
       /* Daemon shutting down, application will not receive any more data. */
 #ifdef HAVE_MESSAGES
       if (! urh->was_closed)
         {
-          MHD_DLOG (urh->connection->daemon,
+          MHD_DLOG (daemon,
                     _("Initiated daemon shutdown while \"upgraded\" connection 
was not closed.\n"));
         }
 #endif
@@ -1031,7 +1039,7 @@ process_urh (struct MHD_UpgradeResponseHandle *urh)
       if (0 < urh->in_buffer_used)
         {
 #ifdef HAVE_MESSAGES
-          MHD_DLOG (urh->connection->daemon,
+          MHD_DLOG (daemon,
                     _("Failed to forward to application " 
MHD_UNSIGNED_LONG_LONG_PRINTF \
                         " bytes of data received from remote side: application 
shut down socket\n"),
                     (MHD_UNSIGNED_LONG_LONG) urh->in_buffer_used);
@@ -1043,12 +1051,12 @@ process_urh (struct MHD_UpgradeResponseHandle *urh)
       urh->mhd.celi &= ~MHD_EPOLL_STATE_WRITE_READY;
       /* Reading from remote client is not required anymore. */
       urh->app.celi &= ~MHD_EPOLL_STATE_READ_READY;
-      urh->connection->tls_read_ready = false;
+      connection->tls_read_ready = false;
     }
 
   /* handle reading from TLS client and writing to application */
   if ( ( (0 != (MHD_EPOLL_STATE_READ_READY & urh->app.celi)) ||
-         (urh->connection->tls_read_ready) ) &&
+         (connection->tls_read_ready) ) &&
        (urh->in_buffer_used < urh->in_buffer_size) )
     {
       ssize_t res;
@@ -1058,24 +1066,22 @@ process_urh (struct MHD_UpgradeResponseHandle *urh)
       if (buf_size > SSIZE_MAX)
         buf_size = SSIZE_MAX;
 
-      urh->connection->tls_read_ready = false;
-      res = gnutls_record_recv (urh->connection->tls_session,
+      connection->tls_read_ready = false;
+      res = gnutls_record_recv (connection->tls_session,
                                 &urh->in_buffer[urh->in_buffer_used],
                                 buf_size);
-      if ( (GNUTLS_E_AGAIN == res) ||
-           (GNUTLS_E_INTERRUPTED == res) )
-        {
-          urh->app.celi &= ~MHD_EPOLL_STATE_READ_READY;
-        }
+      if (GNUTLS_E_AGAIN == res)
+        urh->app.celi &= ~MHD_EPOLL_STATE_READ_READY;
       else if (res > 0)
         {
           urh->in_buffer_used += res;
-          if (0 < gnutls_record_check_pending (urh->connection->tls_session))
+          if (0 < gnutls_record_check_pending (connection->tls_session))
             {
-              urh->connection->tls_read_ready = true;
+              connection->tls_read_ready = true;
             }
         }
-      else if (0 >= res)
+      else if ( (0 >= res ) &&
+                (GNUTLS_E_INTERRUPTED != res) )
         {
           /* Connection was shut down or got unrecoverable error.
            * signal by shrinking buffer so no more attempts will be
@@ -1101,17 +1107,17 @@ process_urh (struct MHD_UpgradeResponseHandle *urh)
         {
           int err = MHD_socket_get_error_ ();
 
-          if ( (MHD_SCKT_ERR_IS_EINTR_ (err)) ||
-               (MHD_SCKT_ERR_IS_EAGAIN_ (err)) )
+          if (MHD_SCKT_ERR_IS_EAGAIN_ (err))
             urh->mhd.celi &= ~MHD_EPOLL_STATE_WRITE_READY;
-          else if (! MHD_SCKT_ERR_IS_LOW_RESOURCES_(err))
+          else if ( (! MHD_SCKT_ERR_IS_EINTR_ (err)) &&
+                    (! MHD_SCKT_ERR_IS_LOW_RESOURCES_(err)) )
             {
               /* persistent / unrecoverable error, treat as
                  if connection was shut down.
                  Do not try to receive to 'in_buffer' and
                  discard any unsent data. */
 #ifdef HAVE_MESSAGES
-              MHD_DLOG (urh->connection->daemon,
+              MHD_DLOG (daemon,
                         _("Failed to forward to application " 
MHD_UNSIGNED_LONG_LONG_PRINTF \
                             " bytes of data received from remote side: %s\n"),
                         (MHD_UNSIGNED_LONG_LONG) urh->in_buffer_used,
@@ -1121,7 +1127,7 @@ process_urh (struct MHD_UpgradeResponseHandle *urh)
               urh->in_buffer_used = 0;
               urh->mhd.celi &= ~MHD_EPOLL_STATE_WRITE_READY;
               urh->app.celi &= ~MHD_EPOLL_STATE_READ_READY;
-              urh->connection->tls_read_ready = false;
+              connection->tls_read_ready = false;
             }
         }
       else
@@ -1172,10 +1178,10 @@ process_urh (struct MHD_UpgradeResponseHandle *urh)
           else
             {
               const int err = MHD_socket_get_error_ ();
-              if ( (MHD_SCKT_ERR_IS_EINTR_ (err)) ||
-                   (MHD_SCKT_ERR_IS_EAGAIN_ (err)) )
+              if (MHD_SCKT_ERR_IS_EAGAIN_ (err))
                 urh->mhd.celi &= ~MHD_EPOLL_STATE_READ_READY;
-              else if (! MHD_SCKT_ERR_IS_LOW_RESOURCES_(err))
+              else if ( (! MHD_SCKT_ERR_IS_EINTR_ (err)) &&
+                        (! MHD_SCKT_ERR_IS_LOW_RESOURCES_(err)) )
                 {
                   /* persistent / unrecoverable error, treat as
                      if connection was shut down */
@@ -1207,11 +1213,10 @@ process_urh (struct MHD_UpgradeResponseHandle *urh)
       if (data_size > SSIZE_MAX)
         data_size = SSIZE_MAX;
 
-      res = gnutls_record_send (urh->connection->tls_session,
+      res = gnutls_record_send (connection->tls_session,
                                 urh->out_buffer,
                                 data_size);
-      if ( (GNUTLS_E_AGAIN == res) ||
-           (GNUTLS_E_INTERRUPTED == res) )
+      if (GNUTLS_E_AGAIN == res)
         {
           urh->app.celi &= ~MHD_EPOLL_STATE_WRITE_READY;
         }
@@ -1229,14 +1234,14 @@ process_urh (struct MHD_UpgradeResponseHandle *urh)
               urh->out_buffer_used = 0;
             }
         }
-      else
+      else if (GNUTLS_E_INTERRUPTED != res)
         {
           /* persistent / unrecoverable error, treat as
              if connection was shut down.
              Do not try to receive to 'out_buffer' and
              discard any unsent data. */
 #ifdef HAVE_MESSAGES
-          MHD_DLOG (urh->connection->daemon,
+          MHD_DLOG (daemon,
                     _("Failed to forward to remote client " 
MHD_UNSIGNED_LONG_LONG_PRINTF \
                         " bytes of data received from application: %s\n"),
                     (MHD_UNSIGNED_LONG_LONG) urh->out_buffer_used,
@@ -1251,19 +1256,19 @@ process_urh (struct MHD_UpgradeResponseHandle *urh)
 
   /* Check whether data is present in TLS buffers
    * and incoming forward buffer have some space. */
-  if ( (urh->connection->tls_read_ready) &&
+  if ( (connection->tls_read_ready) &&
        (urh->in_buffer_used < urh->in_buffer_size) &&
-       (0 == (urh->connection->daemon->options & 
MHD_USE_THREAD_PER_CONNECTION)) )
-    urh->connection->daemon->data_already_pending = true;
+       (0 == (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) )
+    daemon->data_already_pending = true;
 
-  if ( (urh->connection->daemon->shutdown) &&
+  if ( (daemon->shutdown) &&
        ( (0 != urh->out_buffer_size) ||
          (0 != urh->out_buffer_used) ) )
     {
       /* Daemon shutting down, discard any remaining forward data. */
 #ifdef HAVE_MESSAGES
       if (0 < urh->out_buffer_used)
-        MHD_DLOG (urh->connection->daemon,
+        MHD_DLOG (daemon,
                   _("Failed to forward to remote client " 
MHD_UNSIGNED_LONG_LONG_PRINTF \
                       " bytes of data received from application: daemon shut 
down\n"),
                   (MHD_UNSIGNED_LONG_LONG) urh->out_buffer_used);

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



reply via email to

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