gnunet-svn
[Top][All Lists]
Advanced

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

[libmicrohttpd] branch master updated (52b79898 -> ad9fc5c6)


From: gnunet
Subject: [libmicrohttpd] branch master updated (52b79898 -> ad9fc5c6)
Date: Wed, 24 Nov 2021 19:08:13 +0100

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

karlson2k pushed a change to branch master
in repository libmicrohttpd.

    from 52b79898 test_client_put_stop: use content longer than 15 bytes
     new 85dbd8dc test_client_put_stop: use TCP_NODELAY for client
     new 71cff2d6 process_request_body(): replaced 'int' with 'bool'
     new 5b73b66e process_request_body(): removed redundant check
     new 2f18a668 process_request_body(): unify checks for chunked upload
     new 52c6a341 process_request_body(): removed unneeded check
     new eebf9c28 process_request_body(): removed one more unneeded check
     new 8a69a449 process_request_body(): fixed: do not skip chunk closure when 
too few data available
     new 6d7825e8 process_request_body(): do not process when no more data is 
available
     new f2540786 process_request_body(): minor improvement of code readability
     new f8ed2082 process_request_body(): fixed: removed wrong special handling 
of the termination chunk
     new ad9fc5c6 process_request_body(): added assert

The 11 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           | 66 ++++++++++++++++++-----------------
 src/microhttpd/internal.h             |  7 ++--
 src/microhttpd/test_client_put_stop.c |  9 +++++
 3 files changed, 47 insertions(+), 35 deletions(-)

diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c
index 442189a4..bbe363bd 100644
--- a/src/microhttpd/connection.c
+++ b/src/microhttpd/connection.c
@@ -3077,7 +3077,7 @@ process_request_body (struct MHD_Connection *connection)
 {
   struct MHD_Daemon *daemon = connection->daemon;
   size_t available;
-  int instant_retry;
+  bool instant_retry;
   char *buffer_head;
 
   if (NULL != connection->response)
@@ -3107,23 +3107,26 @@ process_request_body (struct MHD_Connection *connection)
     size_t left_unprocessed;
     size_t processed_size;
 
-    instant_retry = MHD_NO;
-    if ( (connection->have_chunked_upload) &&
-         (MHD_SIZE_UNKNOWN == connection->remaining_upload_size) )
+    instant_retry = false;
+    if (connection->have_chunked_upload)
     {
+      mhd_assert (MHD_SIZE_UNKNOWN == connection->remaining_upload_size);
       if ( (connection->current_chunk_offset ==
             connection->current_chunk_size) &&
-           (0LLU != connection->current_chunk_offset) &&
-           (available >= 2) )
+           (0 != connection->current_chunk_size) )
       {
         size_t i;
+        mhd_assert (0 != available);
         /* skip new line at the *end* of a chunk */
         i = 0;
-        if ( ('\r' == buffer_head[i]) &&
-             ('\n' == buffer_head[i + 1]) )
+        if ( (2 <= available) &&
+             ('\r' == buffer_head[0]) &&
+             ('\n' == buffer_head[1]) )
           i += 2;                        /* skip CRLF */
-        else if ('\n' == buffer_head[i]) /* TODO: Add MHD option to disallow */
+        else if ('\n' == buffer_head[0]) /* TODO: Add MHD option to disallow */
           i++;                           /* skip bare LF */
+        else if (2 > available)
+          break;                         /* need more upload data */
         if (0 == i)
         {
           /* malformed encoding */
@@ -3136,11 +3139,14 @@ process_request_body (struct MHD_Connection *connection)
         buffer_head += i;
         connection->current_chunk_offset = 0;
         connection->current_chunk_size = 0;
+        if (0 == available)
+          break;
       }
-      if (connection->current_chunk_offset <
-          connection->current_chunk_size)
+      if (0 != connection->current_chunk_size)
       {
         uint64_t cur_chunk_left;
+        mhd_assert (connection->current_chunk_offset < \
+                    connection->current_chunk_size);
         /* we are in the middle of a chunk, give
            as much as possible to the client (without
            crossing chunk boundaries) */
@@ -3152,7 +3158,7 @@ process_request_body (struct MHD_Connection *connection)
         {         /* cur_chunk_left <= (size_t)available */
           to_be_processed = (size_t) cur_chunk_left;
           if (available > to_be_processed)
-            instant_retry = MHD_YES;
+            instant_retry = true;
         }
       }
       else
@@ -3188,10 +3194,7 @@ process_request_body (struct MHD_Connection *connection)
         /* take '\n' into account; if '\n' is the unavailable
            character, we will need to wait until we have it
            before going further */
-        if ( (i + 1 >= available) &&
-             ! ( (1 == i) &&
-                 (2 == available) &&
-                 ('0' == buffer_head[0]) ) )
+        if (i + 1 >= available)
           break;                /* need more data... */
         i++;
         malformed = (end_size >= 16);
@@ -3222,7 +3225,7 @@ process_request_body (struct MHD_Connection *connection)
         connection->current_chunk_offset = 0;
 
         if (available > 0)
-          instant_retry = MHD_YES;
+          instant_retry = true;
         if (0LLU == connection->current_chunk_size)
         {
           connection->remaining_upload_size = 0;
@@ -3234,20 +3237,12 @@ process_request_body (struct MHD_Connection *connection)
     else
     {
       /* no chunked encoding, give all to the client */
-      if ( (0 != connection->remaining_upload_size) &&
-           (MHD_SIZE_UNKNOWN != connection->remaining_upload_size) &&
-           (connection->remaining_upload_size < available) )
-      {
+      mhd_assert (MHD_SIZE_UNKNOWN != connection->remaining_upload_size);
+      mhd_assert (0 != connection->remaining_upload_size);
+      if (connection->remaining_upload_size < available)
         to_be_processed = (size_t) connection->remaining_upload_size;
-      }
       else
-      {
-        /**
-         * 1. no chunked encoding, give all to the client
-         * 2. client may send large chunked data, but only a smaller part is 
available at one time.
-         */
         to_be_processed = available;
-      }
     }
     left_unprocessed = to_be_processed;
     connection->client_aware = true;
@@ -3279,7 +3274,7 @@ process_request_body (struct MHD_Connection *connection)
                  );
     if (0 != left_unprocessed)
     {
-      instant_retry = MHD_NO; /* client did not process everything */
+      instant_retry = false; /* client did not process everything */
 #ifdef HAVE_MESSAGES
       /* client did not process all upload data, complain if
          the setup was incorrect, which may prevent us from
@@ -3297,16 +3292,23 @@ process_request_body (struct MHD_Connection *connection)
     /* dh left "processed" bytes in buffer for next time... */
     buffer_head += processed_size;
     available -= processed_size;
-    if (MHD_SIZE_UNKNOWN != connection->remaining_upload_size)
+    if (! connection->have_chunked_upload)
+    {
+      mhd_assert (MHD_SIZE_UNKNOWN != connection->remaining_upload_size);
       connection->remaining_upload_size -= processed_size;
-  }
-  while (MHD_NO != instant_retry);
+    }
+    else
+      mhd_assert (MHD_SIZE_UNKNOWN == connection->remaining_upload_size);
+  } while (instant_retry);
   /* TODO: zero out reused memory region */
   if ( (available > 0) &&
        (buffer_head != connection->read_buffer) )
     memmove (connection->read_buffer,
              buffer_head,
              available);
+  else
+    mhd_assert ((0 == available) || \
+                (connection->read_buffer_offset == available));
   connection->read_buffer_offset = available;
 }
 
diff --git a/src/microhttpd/internal.h b/src/microhttpd/internal.h
index da981c80..45c17441 100644
--- a/src/microhttpd/internal.h
+++ b/src/microhttpd/internal.h
@@ -1292,9 +1292,10 @@ struct MHD_Connection
 
   /**
    * If we are receiving with chunked encoding, where are we right
-   * now?  Set to 0 if we are waiting to receive the chunk size;
-   * otherwise, this is the size of the current chunk.  A value of
-   * zero is also used when we're at the end of the chunks.
+   * now?
+   * Set to 0 if we are waiting to receive the chunk size;
+   * otherwise, this is the size of the current chunk.
+   * A value of zero is also used when we're at the end of the chunks.
    */
   uint64_t current_chunk_size;
 
diff --git a/src/microhttpd/test_client_put_stop.c 
b/src/microhttpd/test_client_put_stop.c
index 7d1c66c0..814e8418 100644
--- a/src/microhttpd/test_client_put_stop.c
+++ b/src/microhttpd/test_client_put_stop.c
@@ -326,6 +326,15 @@ _MHD_dumbClient_create (unsigned int port, const char 
*method, const char *url,
   else
     make_blocking (clnt->sckt);
 
+  if (1)
+  { /* Always set TCP NODELAY */
+    const MHD_SCKT_OPT_BOOL_ on_val = 1;
+
+    if (0 != setsockopt (clnt->sckt, IPPROTO_TCP, TCP_NODELAY,
+                         (const void *) &on_val, sizeof (on_val)))
+      externalErrorExitDesc ("Cannot set TCP_NODELAY option");
+  }
+
   clnt->port = port;
 
   if (NULL != method)

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

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