gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] [libmicrohttpd] 09/10: try_ready_chunked_body(): remove use


From: gnunet
Subject: [GNUnet-SVN] [libmicrohttpd] 09/10: try_ready_chunked_body(): remove useless loop, use know free memory size instead of guessing
Date: Mon, 17 Jun 2019 20:35:52 +0200

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

karlson2k pushed a commit to branch master
in repository libmicrohttpd.

commit a275ae63537380c41cfe145ec4e00dd796e0992c
Author: Evgeny Grin (Karlson2k) <address@hidden>
AuthorDate: Sun Jun 16 21:55:53 2019 +0300

    try_ready_chunked_body(): remove useless loop, use know free memory
    size instead of guessing
---
 src/microhttpd/connection.c | 34 +++++++++++++++-------------------
 1 file changed, 15 insertions(+), 19 deletions(-)

diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c
index 525e6a8c..a97844c2 100644
--- a/src/microhttpd/connection.c
+++ b/src/microhttpd/connection.c
@@ -1342,9 +1342,7 @@ static int
 try_ready_chunked_body (struct MHD_Connection *connection)
 {
   ssize_t ret;
-  char *buf;
   struct MHD_Response *response;
-  size_t size;
   char cbuf[10];                /* 10: max strlen of "%x\r\n" */
   int cblen;
 
@@ -1353,28 +1351,26 @@ try_ready_chunked_body (struct MHD_Connection 
*connection)
     return MHD_YES;
   if (0 == connection->write_buffer_size)
     {
-      size = MHD_MIN (connection->daemon->pool_size,
-                      2 * (0xFFFFFF + sizeof(cbuf) + 2));
-      do
+      size_t size;
+
+      size = MHD_pool_get_free (connection->pool);
+      if (size < 128)
         {
-          size /= 2;
-          if (size < 128)
-            {
 #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
-              MHD_mutex_unlock_chk_ (&response->mutex);
+          MHD_mutex_unlock_chk_ (&response->mutex);
 #endif
-              /* not enough memory */
-              CONNECTION_CLOSE_ERROR (connection,
-                                     _("Closing connection (out of 
memory)\n"));
-              return MHD_NO;
-            }
-          buf = MHD_pool_allocate (connection->pool,
-                                   size,
-                                   false);
+          /* not enough memory */
+          CONNECTION_CLOSE_ERROR (connection,
+                                  _("Closing connection (out of memory)\n"));
+          return MHD_NO;
         }
-      while (NULL == buf);
+      if ( (2 * (0xFFFFFF + sizeof(cbuf) + 2)) < size)
+        size = 2 * (0xFFFFFF + sizeof(cbuf) + 2);
+      connection->write_buffer = MHD_pool_allocate (connection->pool,
+                                                    size,
+                                                    false);
+      mhd_assert (NULL != connection->write_buffer);
       connection->write_buffer_size = size;
-      connection->write_buffer = buf;
     }
 
   if (0 == response->total_size)

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



reply via email to

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