gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] [libmicrohttpd] branch master updated (920e02df -> 796eda71


From: gnunet
Subject: [GNUnet-SVN] [libmicrohttpd] branch master updated (920e02df -> 796eda71)
Date: Sun, 04 Jun 2017 18:31:07 +0200

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

karlson2k pushed a change to branch master
in repository libmicrohttpd.

    from 920e02df Updated .gitignore
     new e1d7fc46 Refactoring: incorporate do_read() into 
MHD_connection_handle_read()
     new 796eda71 Refactoring: incorporate do_write() into 
MHD_connection_handle_write()

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/connection.c | 193 +++++++++++++++++++++-----------------------
 1 file changed, 90 insertions(+), 103 deletions(-)

diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c
index f1f2a80e..fd74207c 100644
--- a/src/microhttpd/connection.c
+++ b/src/microhttpd/connection.c
@@ -2327,101 +2327,6 @@ process_request_body (struct MHD_Connection *connection)
 
 
 /**
- * Try reading data from the socket into the read buffer of the
- * connection.
- *
- * @param connection connection we're processing
- * @return #MHD_YES if something changed,
- *         #MHD_NO if we were interrupted or if
- *                no space was available
- */
-static int
-do_read (struct MHD_Connection *connection)
-{
-  ssize_t bytes_read;
-
-  if (connection->read_buffer_size == connection->read_buffer_offset)
-    return MHD_NO;
-  bytes_read = connection->recv_cls (connection,
-                                     &connection->read_buffer
-                                     [connection->read_buffer_offset],
-                                     connection->read_buffer_size -
-                                     connection->read_buffer_offset);
-  if (bytes_read < 0)
-    {
-      const int err = MHD_socket_get_error_ ();
-      if (MHD_SCKT_ERR_IS_EINTR_ (err) ||
-          MHD_SCKT_ERR_IS_EAGAIN_ (err))
-         return MHD_NO;
-      if (MHD_SCKT_ERR_IS_REMOTE_DISCNN_ (err))
-        {
-           CONNECTION_CLOSE_ERROR (connection,
-                                   NULL);
-          return MHD_NO;
-       }
-      CONNECTION_CLOSE_ERROR (connection,
-                              NULL);
-      return MHD_YES;
-    }
-  if (0 == bytes_read)
-    {
-      /* other side closed connection; RFC 2616, section 8.1.4 suggests
-        we should then shutdown ourselves as well. */
-      connection->read_closed = true;
-      MHD_connection_close_ (connection,
-                             MHD_REQUEST_TERMINATED_CLIENT_ABORT);
-      return MHD_YES;
-    }
-  connection->read_buffer_offset += bytes_read;
-  return MHD_YES;
-}
-
-
-/**
- * Try writing data to the socket from the
- * write buffer of the connection.
- *
- * @param connection connection we're processing
- * @return #MHD_YES if something changed,
- *         #MHD_NO if we were interrupted
- */
-static int
-do_write (struct MHD_Connection *connection)
-{
-  ssize_t ret;
-  size_t max;
-
-  max = connection->write_buffer_append_offset - 
connection->write_buffer_send_offset;
-  ret = connection->send_cls (connection,
-                              &connection->write_buffer
-                              [connection->write_buffer_send_offset],
-                              max);
-
-  if (ret < 0)
-    {
-      const int err = MHD_socket_get_error_ ();
-      if (MHD_SCKT_ERR_IS_EINTR_ (err) ||
-          MHD_SCKT_ERR_IS_EAGAIN_ (err))
-        return MHD_NO;
-      CONNECTION_CLOSE_ERROR (connection,
-                              NULL);
-      return MHD_YES;
-    }
-#if DEBUG_SEND_DATA
-  fprintf (stderr,
-           _("Sent response: `%.*s'\n"),
-           ret,
-           &connection->write_buffer[connection->write_buffer_send_offset]);
-#endif
-  /* only increment if this wasn't a "sendfile" transmission without
-     buffer involvement! */
-  if (0 != max)
-    connection->write_buffer_send_offset += ret;
-  return MHD_YES;
-}
-
-
-/**
  * Check if we are done sending the write-buffer.
  * If so, transition into "next_state".
  *
@@ -2721,6 +2626,8 @@ MHD_update_last_activity_ (struct MHD_Connection 
*connection)
 int
 MHD_connection_handle_read (struct MHD_Connection *connection)
 {
+  ssize_t bytes_read;
+
   if ( (MHD_CONNECTION_CLOSED == connection->state) ||
        (connection->suspended) )
     return MHD_YES;
@@ -2729,8 +2636,43 @@ MHD_connection_handle_read (struct MHD_Connection 
*connection)
   if (connection->read_buffer_offset + connection->daemon->pool_increment >
       connection->read_buffer_size)
     try_grow_read_buffer (connection);
-  if (MHD_NO == do_read (connection))
-    return MHD_YES;
+
+  if (connection->read_buffer_size == connection->read_buffer_offset)
+    return MHD_YES; /* No space for receiving data. */
+  bytes_read = connection->recv_cls (connection,
+                                     &connection->read_buffer
+                                     [connection->read_buffer_offset],
+                                     connection->read_buffer_size -
+                                     connection->read_buffer_offset);
+  if (bytes_read < 0)
+    {
+      const int err = MHD_socket_get_error_ ();
+      if (MHD_SCKT_ERR_IS_EINTR_ (err) ||
+          MHD_SCKT_ERR_IS_EAGAIN_ (err))
+          return MHD_YES; /* No new data to process. */
+      if (MHD_SCKT_ERR_IS_REMOTE_DISCNN_ (err))
+        {
+           CONNECTION_CLOSE_ERROR (connection,
+                                   (MHD_CONNECTION_INIT == connection->state) ?
+                                     NULL :
+                                     _("Socket is unexpectedly disconnected 
when reading request.\n"));
+           return MHD_NO;
+        }
+      CONNECTION_CLOSE_ERROR (connection,
+                              (MHD_CONNECTION_INIT == connection->state) ?
+                                NULL :
+                                _("Connection socket is closed due to 
unexpected error when reading request.\n"));
+      return MHD_YES;
+    }
+
+  if (0 == bytes_read)
+    { /* Remote side closed connection. */
+      connection->read_closed = true;
+      MHD_connection_close_ (connection,
+                             MHD_REQUEST_TERMINATED_CLIENT_ABORT);
+      return MHD_YES;
+    }
+  connection->read_buffer_offset += bytes_read;
   MHD_update_last_activity_ (connection);
   while (1)
     {
@@ -2853,8 +2795,23 @@ MHD_connection_handle_write (struct MHD_Connection 
*connection)
           EXTRA_CHECK (0);
           break;
         case MHD_CONNECTION_HEADERS_SENDING:
-          if (MHD_NO != do_write (connection))
-            MHD_update_last_activity_ (connection);
+          ret = connection->send_cls (connection,
+                                      &connection->write_buffer
+                                      [connection->write_buffer_send_offset],
+                                      connection->write_buffer_append_offset -
+                                        connection->write_buffer_send_offset);
+          if (ret < 0)
+            {
+              const int err = MHD_socket_get_error_ ();
+              if (MHD_SCKT_ERR_IS_EINTR_ (err) ||
+                  MHD_SCKT_ERR_IS_EAGAIN_ (err))
+                break;
+              CONNECTION_CLOSE_ERROR (connection,
+                                      _("Connection was closed while sending 
response headers.\n"));
+              return MHD_YES;
+            }
+          connection->write_buffer_send_offset += ret;
+          MHD_update_last_activity_ (connection);
          if (MHD_CONNECTION_HEADERS_SENDING != connection->state)
             break;
           check_write_done (connection,
@@ -2924,8 +2881,23 @@ MHD_connection_handle_write (struct MHD_Connection 
*connection)
           EXTRA_CHECK (0);
           break;
         case MHD_CONNECTION_CHUNKED_BODY_READY:
-          if (MHD_NO != do_write (connection))
-            MHD_update_last_activity_ (connection);
+          ret = connection->send_cls (connection,
+                                      &connection->write_buffer
+                                      [connection->write_buffer_send_offset],
+                                      connection->write_buffer_append_offset -
+                                        connection->write_buffer_send_offset);
+          if (ret < 0)
+            {
+              const int err = MHD_socket_get_error_ ();
+              if (MHD_SCKT_ERR_IS_EINTR_ (err) ||
+                  MHD_SCKT_ERR_IS_EAGAIN_ (err))
+                break;
+              CONNECTION_CLOSE_ERROR (connection,
+                                      _("Connection was closed while sending 
response body.\n"));
+              return MHD_YES;
+            }
+          connection->write_buffer_send_offset += ret;
+          MHD_update_last_activity_ (connection);
          if (MHD_CONNECTION_CHUNKED_BODY_READY != connection->state)
             break;
           check_write_done (connection,
@@ -2939,8 +2911,23 @@ MHD_connection_handle_write (struct MHD_Connection 
*connection)
           EXTRA_CHECK (0);
           break;
         case MHD_CONNECTION_FOOTERS_SENDING:
-          if (MHD_NO != do_write (connection))
-            MHD_update_last_activity_ (connection);
+          ret = connection->send_cls (connection,
+                                      &connection->write_buffer
+                                      [connection->write_buffer_send_offset],
+                                      connection->write_buffer_append_offset -
+                                        connection->write_buffer_send_offset);
+          if (ret < 0)
+            {
+              const int err = MHD_socket_get_error_ ();
+              if (MHD_SCKT_ERR_IS_EINTR_ (err) ||
+                  MHD_SCKT_ERR_IS_EAGAIN_ (err))
+                break;
+              CONNECTION_CLOSE_ERROR (connection,
+                                      _("Connection was closed while sending 
response body.\n"));
+              return MHD_YES;
+            }
+          connection->write_buffer_send_offset += ret;
+          MHD_update_last_activity_ (connection);
          if (MHD_CONNECTION_FOOTERS_SENDING != connection->state)
            break;
           check_write_done (connection,

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



reply via email to

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