gnunet-svn
[Top][All Lists]
Advanced

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

[libmicrohttpd] branch master updated (cca1730f -> ff12c572)


From: gnunet
Subject: [libmicrohttpd] branch master updated (cca1730f -> ff12c572)
Date: Sun, 28 Nov 2021 17:44:33 +0100

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

karlson2k pushed a change to branch master
in repository libmicrohttpd.

    from cca1730f memorypool: minor doxy clarification
     new 5c478c5d test_client_put_stop: check for right reason
     new 13cc9afe Cosmetics: removed duplicated value
     new 679f259b If socket error is detected, try to detect the type of error 
before closing
     new dbf407c2 Fixed MHD_FEATURE_AUTOSUPPRESS_SIGPIPE return value
     new ff12c572 test_client_put_stop: suppress SIGPIPE on the client side

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/include/microhttpd.h              |  2 +-
 src/microhttpd/connection.c           | 20 +++++++++++----
 src/microhttpd/connection.h           |  6 +++--
 src/microhttpd/daemon.c               | 24 ++++++++++--------
 src/microhttpd/mhd_sockets.h          |  4 +--
 src/microhttpd/test_client_put_stop.c | 48 +++++++++++++++++++++++++++++++----
 6 files changed, 78 insertions(+), 26 deletions(-)

diff --git a/src/include/microhttpd.h b/src/include/microhttpd.h
index 6d9fa67d..3b755e5d 100644
--- a/src/include/microhttpd.h
+++ b/src/include/microhttpd.h
@@ -4543,7 +4543,7 @@ enum MHD_FEATURE
   MHD_FEATURE_AUTODETECT_BIND_PORT = 19,
 
   /**
-   * Get whether MHD support SIGPIPE suppression.
+   * Get whether MHD supports automatic SIGPIPE suppression.
    * If SIGPIPE suppression is not supported, application must handle
    * SIGPIPE signal by itself.
    */
diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c
index a009cddf..6963c228 100644
--- a/src/microhttpd/connection.c
+++ b/src/microhttpd/connection.c
@@ -3683,12 +3683,16 @@ MHD_update_last_activity_ (struct MHD_Connection 
*connection)
 
 /**
  * This function handles a particular connection when it has been
- * determined that there is data to be read off a socket.
+ * determined that there is data to be read off a socket. All
+ * implementations (multithreaded, external polling, internal polling)
+ * call this function to handle reads.
  *
  * @param connection connection to handle
+ * @param socket_error set to true if socket error was detected
  */
 void
-MHD_connection_handle_read (struct MHD_Connection *connection)
+MHD_connection_handle_read (struct MHD_Connection *connection,
+                            bool socket_error)
 {
   ssize_t bytes_read;
 
@@ -3721,10 +3725,15 @@ MHD_connection_handle_read (struct MHD_Connection 
*connection)
                                      [connection->read_buffer_offset],
                                      connection->read_buffer_size
                                      - connection->read_buffer_offset);
-  if (bytes_read < 0)
+  if ((bytes_read < 0) || socket_error)
   {
-    if (MHD_ERR_AGAIN_ == bytes_read)
+    if ((MHD_ERR_AGAIN_ == bytes_read) && ! socket_error)
       return;     /* No new data to process. */
+    if ((bytes_read > 0) && connection->sk_nonblck)
+    { /* Try to detect the socket error */
+      int dummy;
+      bytes_read = connection->recv_cls (connection, &dummy, sizeof (dummy));
+    }
     if (MHD_ERR_CONNRESET_ == bytes_read)
     {
       if ( (MHD_CONNECTION_INIT < connection->state) &&
@@ -3746,7 +3755,8 @@ MHD_connection_handle_read (struct MHD_Connection 
*connection)
       MHD_DLOG (connection->daemon,
                 _ ("Connection socket is closed when reading " \
                    "request due to the error: %s\n"),
-                str_conn_error_ (bytes_read));
+                (bytes_read < 0) ? str_conn_error_ (bytes_read) :
+                "detected connection closure");
 #endif
     CONNECTION_CLOSE_ERROR (connection,
                             NULL);
diff --git a/src/microhttpd/connection.h b/src/microhttpd/connection.h
index b21029e6..50816ce2 100644
--- a/src/microhttpd/connection.h
+++ b/src/microhttpd/connection.h
@@ -89,13 +89,15 @@ MHD_set_http_callbacks_ (struct MHD_Connection *connection);
 /**
  * This function handles a particular connection when it has been
  * determined that there is data to be read off a socket. All
- * implementations (multithreaded, external select, internal select)
+ * implementations (multithreaded, external polling, internal polling)
  * call this function to handle reads.
  *
  * @param connection connection to handle
+ * @param socket_error set to true if socket error was detected
  */
 void
-MHD_connection_handle_read (struct MHD_Connection *connection);
+MHD_connection_handle_read (struct MHD_Connection *connection,
+                            bool socket_error);
 
 
 /**
diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c
index 32334621..25ac0969 100644
--- a/src/microhttpd/daemon.c
+++ b/src/microhttpd/daemon.c
@@ -1213,15 +1213,18 @@ call_handlers (struct MHD_Connection *con,
   if (con->tls_read_ready)
     read_ready = true;
 #endif /* HTTPS_SUPPORT */
+  if ( (MHD_EVENT_LOOP_INFO_READ == con->event_loop_info) &&
+       (read_ready || (force_close && con->sk_nonblck)) )
+  {
+    MHD_connection_handle_read (con, force_close);
+    mhd_assert (! force_close || MHD_CONNECTION_CLOSED == con->state);
+    ret = MHD_connection_handle_idle (con);
+    if (force_close)
+      return ret;
+    states_info_processed = true;
+  }
   if (! force_close)
   {
-    if ( (MHD_EVENT_LOOP_INFO_READ == con->event_loop_info) &&
-         read_ready)
-    {
-      MHD_connection_handle_read (con);
-      ret = MHD_connection_handle_idle (con);
-      states_info_processed = true;
-    }
     /* No need to check value of 'ret' here as closed connection
      * cannot be in MHD_EVENT_LOOP_INFO_WRITE state. */
     if ( (MHD_EVENT_LOOP_INFO_WRITE == con->event_loop_info) &&
@@ -2176,8 +2179,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
-                                                | MHD_POLL_REVENTS_ERR_DISC))) 
))
+                         (0 != (p[0].revents & MHD_POLL_REVENTS_ERR_DISC)) ))
         goto exit;
     }
 #endif
@@ -8033,8 +8035,8 @@ MHD_is_feature_supported (enum MHD_FEATURE feature)
     return MHD_NO;
 #endif
   case MHD_FEATURE_AUTOSUPPRESS_SIGPIPE:
-#if defined(MHD_SEND_SPIPE_SUPPRESS_POSSIBLE) && \
-    defined(MHD_SEND_SPIPE_SUPPRESS_NEEDED)
+#if defined(MHD_SEND_SPIPE_SUPPRESS_POSSIBLE) || \
+    ! defined(MHD_SEND_SPIPE_SUPPRESS_NEEDED)
     return MHD_YES;
 #else
     return MHD_NO;
diff --git a/src/microhttpd/mhd_sockets.h b/src/microhttpd/mhd_sockets.h
index d46f10a9..35fdf6b4 100644
--- a/src/microhttpd/mhd_sockets.h
+++ b/src/microhttpd/mhd_sockets.h
@@ -926,8 +926,8 @@ static const int _MHD_socket_int_one = 1;
 /**
  * Indicate that SIGPIPE can be suppressed by MHD for normal send() by flags
  * or socket options.
- * If this macro is undefined, MHD cannot suppress SIGPIPE for normal
- * processing so sendfile() or writev() calls is not avoided.
+ * If this macro is undefined, MHD cannot suppress SIGPIPE for socket functions
+ * so sendfile() or writev() calls are avoided in application threads.
  */
 #define MHD_SEND_SPIPE_SUPPRESS_POSSIBLE   1
 #endif /* MHD_WINSOCK_SOCKETS || MHD_socket_nosignal_ || MSG_NOSIGNAL */
diff --git a/src/microhttpd/test_client_put_stop.c 
b/src/microhttpd/test_client_put_stop.c
index ce197190..81afa6bd 100644
--- a/src/microhttpd/test_client_put_stop.c
+++ b/src/microhttpd/test_client_put_stop.c
@@ -50,6 +50,10 @@
 #include <limits.h>
 #endif /* HAVE_LIMITS_H */
 
+#ifdef HAVE_SIGNAL_H
+#include <signal.h>
+#endif /* HAVE_SIGNAL_H */
+
 #include "mhd_sockets.h" /* only macros used */
 #include "test_helpers.h"
 #include "mhd_assert.h"
@@ -194,6 +198,16 @@ static int upl_chunked;             /**< Use chunked 
encoding for request body *
 static void
 test_global_init (void)
 {
+  if (MHD_YES != MHD_is_feature_supported (MHD_FEATURE_AUTOSUPPRESS_SIGPIPE))
+  {
+#if defined(HAVE_SIGNAL_H) && defined(SIGPIPE)
+    if (SIG_ERR == signal (SIGPIPE, SIG_IGN))
+      externalErrorExitDesc ("Error suppressing SIGPIPE signal");
+#else /* ! HAVE_SIGNAL_H || ! SIGPIPE */
+    fprintf (stderr, "Cannot suppress SIGPIPE signal.\n");
+    /* exit (77); */
+#endif
+  }
 }
 
 
@@ -319,8 +333,13 @@ _MHD_dumbClient_create (unsigned int port, const char 
*method, const char *url,
   clnt->sckt = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP);
   if (MHD_INVALID_SOCKET == clnt->sckt)
     externalErrorExitDesc ("Cannot create the client socket");
-  clnt->sckt_nonblock = 0;
 
+#ifdef MHD_socket_nosignal_
+  if (! MHD_socket_nosignal_ (clnt->sckt))
+    externalErrorExitDesc ("Cannot suppress SIGPIPE on the client socket");
+#endif /* MHD_socket_nosignal_ */
+
+  clnt->sckt_nonblock = 0;
   if (clnt->sckt_nonblock)
     make_nonblocking (clnt->sckt);
   else
@@ -537,8 +556,7 @@ _MHD_dumbClient_send_req (struct _MHD_dumbClient *clnt)
       (clnt->single_send_size < send_size))
     send_size = clnt->single_send_size;
 
-  res = send (clnt->sckt, (const void *) (clnt->send_buf + clnt->send_off),
-              send_size, 0);
+  res = MHD_send_ (clnt->sckt, clnt->send_buf + clnt->send_off, send_size);
 
   if (res < 0)
   {
@@ -1384,8 +1402,11 @@ performTestQueries (struct MHD_Daemon *d, int d_port,
   int ret = 0;          /* Return value */
   size_t req_total_size;
   size_t limit_send_size;
+  int expected_reason;
+  int found_right_reason;
 
-  /* Common parameters, to be individually overridden by specific test cases */
+  /* Common parameters, to be individually overridden by specific test cases
+   * if needed */
   qParam.queryPort = d_port;
   qParam.method = MHD_HTTP_METHOD_PUT;
   qParam.queryPath = EXPECTED_URI_BASE_PATH;
@@ -1415,6 +1436,10 @@ performTestQueries (struct MHD_Daemon *d, int d_port,
     _MHD_dumbClient_close (test_c);
   } while (0);
 
+  expected_reason = use_hard_close ?
+                    MHD_REQUEST_TERMINATED_READ_ERROR :
+                    MHD_REQUEST_TERMINATED_CLIENT_ABORT;
+  found_right_reason = 0;
   for (limit_send_size = 1; limit_send_size < req_total_size; 
limit_send_size++)
   {
     int test_succeed;
@@ -1452,7 +1477,11 @@ performTestQueries (struct MHD_Daemon *d, int d_port,
       else if (1 != sckt_result->num_finished)
         fprintf (stderr, "FAILED: Wrong number of sockets closed.");
       else
+      {
         test_succeed = 1;
+        if (expected_reason == term_result->term_reason)
+          found_right_reason = 1;
+      }
     }
 
     if (! test_succeed)
@@ -1477,6 +1506,14 @@ performTestQueries (struct MHD_Daemon *d, int d_port,
   free (term_result);
   free (sckt_result);
 
+  if (! found_right_reason)
+  {
+    fprintf (stderr, "FAILED: termination callback was not called with "
+             "expected (%s) reason.\n", term_reason_str (expected_reason));
+    fflush (stderr);
+    ret |= 1 << 1;
+  }
+
   return ret;
 }
 
@@ -1704,7 +1741,8 @@ main (int argc, char *const *argv)
 #endif /* ! SO_LINGER */
   if (1 != use_shutdown + use_close)
     return 99;
-  verbose = ! has_param (argc, argv, "-q") || has_param (argc, argv, 
"--quiet");
+  verbose =
+    ! (has_param (argc, argv, "-q") || has_param (argc, argv, "--quiet"));
 
   test_global_init ();
 

-- 
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]