gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] [libmicrohttpd] GNU libmicrohttpd branch master updated. aa


From: gitolite
Subject: [GNUnet-SVN] [libmicrohttpd] GNU libmicrohttpd branch master updated. aa4da2538f101e1070b35dae41323197166fb21c
Date: Mon, 24 Oct 2016 14:52:29 +0200 (CEST)

The branch, master has been updated
       via  aa4da2538f101e1070b35dae41323197166fb21c (commit)
       via  08c81c49061149a4d47787058c5be84f52c60af0 (commit)
       via  a41dc5dce6553e422959def98e6787909a31bdc5 (commit)
       via  634cb0abd867bee5668d4501a4b63b950e5b481c (commit)
       via  3e15e43b1fa979a53eab353fa95dc2ed10fcb17c (commit)
       via  0701ed2e8a521a55c3ce8c2137e360a71ec2db9b (commit)
       via  1ab20f6fb92f1b0a55c37cfc94b3dabfcbd100d4 (commit)
      from  9d0ae2e223d9da00b710f0eb797343d2390f64c5 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit aa4da2538f101e1070b35dae41323197166fb21c
Author: Evgeny Grin (Karlson2k) <address@hidden>
Date:   Sun Oct 23 22:28:15 2016 +0300

    Upgrade: use socketpair only in non-blocking mode

commit 08c81c49061149a4d47787058c5be84f52c60af0
Author: Evgeny Grin (Karlson2k) <address@hidden>
Date:   Sun Oct 23 22:23:34 2016 +0300

    Upgrade: fixed SO_NOSIGPIPE on socketpair.

commit a41dc5dce6553e422959def98e6787909a31bdc5
Author: Evgeny Grin (Karlson2k) <address@hidden>
Date:   Sun Oct 23 22:03:34 2016 +0300

    mhd_sockets.h: added MHD_socket_nosignal_() macro for Darwin and *BSD

commit 634cb0abd867bee5668d4501a4b63b950e5b481c
Author: Evgeny Grin (Karlson2k) <address@hidden>
Date:   Sun Oct 23 19:43:17 2016 +0300

    Cleanup minor improvement: signal select()'s thread at right moment.

commit 3e15e43b1fa979a53eab353fa95dc2ed10fcb17c
Author: Evgeny Grin (Karlson2k) <address@hidden>
Date:   Sun Oct 23 19:07:38 2016 +0300

    Added some remarks about functions' thread safety.

commit 0701ed2e8a521a55c3ce8c2137e360a71ec2db9b
Author: Evgeny Grin (Karlson2k) <address@hidden>
Date:   Sun Oct 23 19:37:14 2016 +0300

    Minor improvement of thread-safety.

commit 1ab20f6fb92f1b0a55c37cfc94b3dabfcbd100d4
Author: Evgeny Grin (Karlson2k) <address@hidden>
Date:   Sun Oct 23 19:10:20 2016 +0300

    Destroy response when it's not needed.

-----------------------------------------------------------------------

Summary of changes:
 src/microhttpd/connection.c  | 47 +++++++++++++++++++++++++++++++-------------
 src/microhttpd/connection.h  |  4 ++++
 src/microhttpd/daemon.c      | 42 ++++++++++++++++++++++-----------------
 src/microhttpd/mhd_sockets.c | 15 ++++----------
 src/microhttpd/mhd_sockets.h | 12 +++++++++++
 src/microhttpd/response.c    | 44 +++++++++++++++++++++++++++++++++++++----
 src/microhttpd/response.h    |  6 +++---
 7 files changed, 120 insertions(+), 50 deletions(-)

diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c
index da76261..52b67b0 100644
--- a/src/microhttpd/connection.c
+++ b/src/microhttpd/connection.c
@@ -492,6 +492,8 @@ need_100_continue (struct MHD_Connection *connection)
 /**
  * Close the given connection and give the
  * specified termination code to the user.
+ * @remark To be called only from thread that
+ * process connection's recv(), send() and response.
  *
  * @param connection connection to close
  * @param termination_code termination reason to give
@@ -501,6 +503,7 @@ MHD_connection_close_ (struct MHD_Connection *connection,
                        enum MHD_RequestTerminationCode termination_code)
 {
   struct MHD_Daemon *daemon;
+  struct MHD_Response * const resp = connection->response;
 
   daemon = connection->daemon;
   if (0 == (connection->daemon->options & MHD_USE_EPOLL_TURBO))
@@ -508,6 +511,11 @@ MHD_connection_close_ (struct MHD_Connection *connection,
               SHUT_WR);
   connection->state = MHD_CONNECTION_CLOSED;
   connection->event_loop_info = MHD_EVENT_LOOP_INFO_CLEANUP;
+  if (NULL != resp)
+    {
+      connection->response = NULL;
+      MHD_destroy_response (resp);
+    }
   if ( (NULL != daemon->notify_completed) &&
        (MHD_YES == connection->client_aware) )
     daemon->notify_completed (daemon->notify_completed_cls,
@@ -515,19 +523,6 @@ MHD_connection_close_ (struct MHD_Connection *connection,
                              &connection->client_context,
                              termination_code);
   connection->client_aware = MHD_NO;
-
-  /* if we were at the connection limit before and are in
-     thread-per-connection mode, signal the main thread
-     to resume accepting connections */
-  if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
-       (MHD_ITC_IS_VALID_ (daemon->itc)) &&
-       (! MHD_itc_activate_ (daemon->itc, "c")) )
-    {
-#ifdef HAVE_MESSAGES
-      MHD_DLOG (daemon,
-                _("Failed to signal end of connection via inter-thread 
communication channel"));
-#endif
-    }
 }
 
 
@@ -2557,6 +2552,8 @@ MHD_connection_handle_write (struct MHD_Connection 
*connection)
 /**
  * Clean up the state of the given connection and move it into the
  * clean up queue for final disposal.
+ * @remark To be called only from thread that process connection's
+ * recv(), send() and response.
  *
  * @param connection handle for the connection to clean up
  */
@@ -2600,13 +2597,28 @@ cleanup_connection (struct MHD_Connection *connection)
   connection->resuming = MHD_NO;
   connection->in_idle = MHD_NO;
   if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION))
-    MHD_mutex_unlock_chk_(&daemon->cleanup_connection_mutex);
+    {
+      MHD_mutex_unlock_chk_(&daemon->cleanup_connection_mutex);
+      /* if we were at the connection limit before and are in
+         thread-per-connection mode, signal the main thread
+         to resume accepting connections */
+      if ( (MHD_ITC_IS_VALID_ (daemon->itc)) &&
+           (! MHD_itc_activate_ (daemon->itc, "c")) )
+        {
+#ifdef HAVE_MESSAGES
+          MHD_DLOG (daemon,
+                    _("Failed to signal end of connection via inter-thread 
communication channel"));
+#endif
+        }
+    }
 }
 
 
 /**
  * This function was created to handle per-connection processing that
  * has to happen even if the socket cannot be read or written to.
+ * @remark To be called only from thread that process connection's
+ * recv(), send() and response.
  *
  * @param connection connection to handle
  * @return #MHD_YES if we should continue to process the
@@ -2892,6 +2904,13 @@ MHD_connection_handle_idle (struct MHD_Connection 
*connection)
                   continue;
                 }
               connection->state = MHD_CONNECTION_UPGRADE;
+              /* Response is not required anymore for this conectnion. */
+              if (NULL != connection->response)
+                {
+                  struct MHD_Response * const resp_clr = connection->response;
+                  connection->response = NULL;
+                  MHD_destroy_response (resp_clr);
+                }
               continue;
             }
           if (MHD_NO != socket_flush_possible (connection))
diff --git a/src/microhttpd/connection.h b/src/microhttpd/connection.h
index 4067af7..0fce734 100644
--- a/src/microhttpd/connection.h
+++ b/src/microhttpd/connection.h
@@ -72,6 +72,8 @@ MHD_connection_handle_write (struct MHD_Connection 
*connection);
  * has to happen even if the socket cannot be read or written to.  All
  * implementations (multithreaded, external select, internal select)
  * call this function.
+ * @remark To be called only from thread that process connection's
+ * recv(), send() and response.
  *
  * @param connection connection to handle
  * @return MHD_YES if we should continue to process the
@@ -84,6 +86,8 @@ MHD_connection_handle_idle (struct MHD_Connection 
*connection);
 /**
  * Close the given connection and give the
  * specified termination code to the user.
+ * @remark To be called only from thread that
+ * process connection's recv(), send() and response.
  *
  * @param connection connection to close
  * @param termination_code termination reason to give
diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c
index be7c79a..03bc3a1 100644
--- a/src/microhttpd/daemon.c
+++ b/src/microhttpd/daemon.c
@@ -1789,9 +1789,6 @@ internal_add_connection (struct MHD_Daemon *daemon,
   unsigned int i;
   int eno;
   struct MHD_Daemon *worker;
-#if OSX
-  static int on = 1;
-#endif
 
   if (NULL != daemon->worker_pool)
     {
@@ -1833,6 +1830,24 @@ internal_add_connection (struct MHD_Daemon *daemon,
       return MHD_NO;
     }
 
+#ifdef MHD_socket_nosignal_
+  if (! MHD_socket_nosignal_ (client_socket))
+    {
+#ifdef HAVE_MESSAGES
+      MHD_DLOG (daemon,
+                _("Failed to set SO_NOSIGPIPE on accepted socket: %s\n"),
+                MHD_socket_last_strerr_());
+#endif
+#ifndef MSG_NOSIGNAL
+      /* Cannot use socket as it can produce SIGPIPE. */
+#ifdef ENOTSOCK
+      errno = ENOTSOCK;
+#endif /* ENOTSOCK */
+      return MHD_NO;
+#endif /* ! MSG_NOSIGNAL */
+    }
+#endif /* MHD_socket_nosignal_ */
+
 
 #ifdef HAVE_MESSAGES
 #if DEBUG_CONNECT
@@ -1880,18 +1895,6 @@ internal_add_connection (struct MHD_Daemon *daemon,
       return MHD_NO;
     }
 
-#if OSX
-#ifdef SOL_SOCKET
-#ifdef SO_NOSIGPIPE
-  setsockopt (client_socket,
-             SOL_SOCKET,
-              SO_NOSIGPIPE,
-             &on,
-              sizeof (on));
-#endif
-#endif
-#endif
-
   if (NULL == (connection = malloc (sizeof (struct MHD_Connection))))
     {
       eno = errno;
@@ -3683,6 +3686,8 @@ MHD_run (struct MHD_Daemon *daemon)
 /**
  * Close the given connection, remove it from all of its
  * DLLs and move it into the cleanup queue.
+ * @remark To be called only from thread that
+ * process daemon's select()/poll()/etc.
  *
  * @param pos connection to move to cleanup
  */
@@ -3691,10 +3696,12 @@ close_connection (struct MHD_Connection *pos)
 {
   struct MHD_Daemon *daemon = pos->daemon;
 
-  MHD_connection_close_ (pos,
-                         MHD_REQUEST_TERMINATED_DAEMON_SHUTDOWN);
+  pos->state = MHD_CONNECTION_CLOSED;
+  pos->event_loop_info = MHD_EVENT_LOOP_INFO_CLEANUP;
   if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION))
     return; /* must let thread to the rest */
+  MHD_connection_close_ (pos,
+                         MHD_REQUEST_TERMINATED_DAEMON_SHUTDOWN);
   if (pos->connection_timeout == pos->daemon->connection_timeout)
     XDLL_remove (daemon->normal_timeout_head,
                 daemon->normal_timeout_tail,
@@ -3706,7 +3713,6 @@ close_connection (struct MHD_Connection *pos)
   DLL_remove (daemon->connections_head,
              daemon->connections_tail,
              pos);
-  pos->event_loop_info = MHD_EVENT_LOOP_INFO_CLEANUP;
   DLL_insert (daemon->cleanup_head,
              daemon->cleanup_tail,
              pos);
diff --git a/src/microhttpd/mhd_sockets.c b/src/microhttpd/mhd_sockets.c
index 3bd48f5..9b60e22 100644
--- a/src/microhttpd/mhd_sockets.c
+++ b/src/microhttpd/mhd_sockets.c
@@ -473,9 +473,6 @@ MHD_socket_create_listen_ (int use_ipv6)
   int domain;
   MHD_socket fd;
   int cloexec_set;
-#if defined(OSX) && defined(SOL_SOCKET) && defined(SO_NOSIGPIPE)
-  static const int on_val = 1;
-#endif
 
 #ifdef HAVE_INET6
   domain = (use_ipv6) ? PF_INET6 : PF_INET;
@@ -510,19 +507,15 @@ MHD_socket_create_listen_ (int use_ipv6)
     }
   if (MHD_INVALID_SOCKET == fd)
     return MHD_INVALID_SOCKET;
-#if defined(OSX) && defined(SOL_SOCKET) && defined(SO_NOSIGPIPE)
-  if(0 != setsockopt(fd,
-                     SOL_SOCKET,
-                     SO_NOSIGPIPE,
-                     &on_val,
-                     sizeof (on_val)))
+#ifdef MHD_socket_nosignal_
+  if(! MHD_socket_nosignal_(fd))
     {
-      int err = MHD_socket_get_error_ ();
+      const int err = MHD_socket_get_error_ ();
       MHD_socket_close_ (fd);
       MHD_socket_fset_error_ (err);
       return MHD_INVALID_SOCKET;
     }
-#endif
+#endif /* MHD_socket_nosignal_ */
   if (! cloexec_set)
     (void) MHD_socket_noninheritable_ (fd);
 
diff --git a/src/microhttpd/mhd_sockets.h b/src/microhttpd/mhd_sockets.h
index 6fefd7d..d160dbc 100644
--- a/src/microhttpd/mhd_sockets.h
+++ b/src/microhttpd/mhd_sockets.h
@@ -702,6 +702,18 @@ int
 MHD_socket_noninheritable_ (MHD_socket sock);
 
 
+#if defined(SOL_SOCKET) && defined(SO_NOSIGPIPE)
+   static const int _MHD_socket_int_one = 1;
+/**
+ * Change socket options to no signal on remote disconnect.
+ *
+ * @param sock socket to manipulate
+ * @return non-zero if succeeded, zero otherwise
+ */
+#  define MHD_socket_nosignal_(sock) \
+    
(!setsockopt((sock),SOL_SOCKET,SO_NOSIGPIPE,&_MHD_socket_int_one,sizeof(_MHD_socket_int_one)))
+#endif /* SOL_SOCKET && SO_NOSIGPIPE */
+
 /**
  * Create a listen socket, with noninheritable flag if possible.
  *
diff --git a/src/microhttpd/response.c b/src/microhttpd/response.c
index d0c7223..09e73f9 100644
--- a/src/microhttpd/response.c
+++ b/src/microhttpd/response.c
@@ -698,6 +698,9 @@ MHD_upgrade_action (struct MHD_UpgradeResponseHandle *urh,
  * We are done sending the header of a given response to the client.
  * Now it is time to perform the upgrade and hand over the connection
  * to the application.
+ * @remark To be called only from thread that process connection's
+ * recv(), send() and response. Must be called right after sending
+ * response headers.
  *
  * @param response the response that was created for an upgrade
  * @param connection the specific connection we are upgrading
@@ -739,6 +742,10 @@ MHD_response_execute_upgrade_ (struct MHD_Response 
*response,
     size_t avail;
     char *buf;
     MHD_socket sv[2];
+#if defined(MHD_socket_nosignal_) || !defined(MHD_socket_pair_nblk_)
+    int res1;
+    int res2;
+#endif /* MHD_socket_nosignal_ || !MHD_socket_pair_nblk_ */
 
 #ifdef MHD_socket_pair_nblk_
     if (! MHD_socket_pair_nblk_ (sv))
@@ -752,16 +759,45 @@ MHD_response_execute_upgrade_ (struct MHD_Response 
*response,
         free (urh);
         return MHD_NO;
       }
-    if ( (! MHD_socket_nonblocking_(sv[0])) ||
-         (! MHD_socket_nonblocking_(sv[1])) )
+    res1 = MHD_socket_nonblocking_(sv[0]);
+    res2 = MHD_socket_nonblocking_(sv[1]);
+    if ( (! res1) || (! res2) )
       {
 #ifdef HAVE_MESSAGES
         MHD_DLOG (daemon,
-                 _("Failed to make loopback sockets non-blocking: %s\n"),
-                 MHD_socket_last_strerr_ ());
+                 _("Failed to make loopback sockets non-blocking.\n"));
 #endif
+        if (! res2)
+          {
+            /* Socketpair cannot be used. */
+            MHD_socket_close_chk_ (sv[0]);
+            MHD_socket_close_chk_ (sv[1]);
+            free (urh);
+            return MHD_NO;
+          }
       }
 #endif /* !MHD_socket_pair_nblk_ */
+#ifdef MHD_socket_nosignal_
+    res1 = MHD_socket_nosignal_(sv[0]);
+    res2 = MHD_socket_nosignal_(sv[1]);
+    if ( (! res1) || (! res2) )
+      {
+#ifdef HAVE_MESSAGES
+        MHD_DLOG (daemon,
+                  _("Failed to set SO_NOSIGPIPE on loopback sockets.\n"));
+#endif
+#ifndef MSG_NOSIGNAL
+        if (!res2)
+          {
+            /* Socketpair cannot be used. */
+            MHD_socket_close_chk_ (sv[0]);
+            MHD_socket_close_chk_ (sv[1]);
+            free (urh);
+            return MHD_NO;
+          }
+#endif /* ! MSG_NOSIGNAL */
+      }
+#endif /* MHD_socket_nosignal_ */
     if ( (! MHD_SCKT_FD_FITS_FDSET_ (sv[1],
                                      NULL)) &&
          (0 == (daemon->options & (MHD_USE_POLL | MHD_USE_EPOLL))) )
diff --git a/src/microhttpd/response.h b/src/microhttpd/response.h
index ce7e131..3f4717d 100644
--- a/src/microhttpd/response.h
+++ b/src/microhttpd/response.h
@@ -40,15 +40,15 @@ MHD_increment_response_rc (struct MHD_Response *response);
  * We are done sending the header of a given response
  * to the client.  Now it is time to perform the upgrade
  * and hand over the connection to the application.
+ * @remark To be called only from thread that process connection's
+ * recv(), send() and response. Must be called right after sending
+ * response headers.
  *
  * @param response the response that was created for an upgrade
  * @param connection the specific connection we are upgrading
  * @return #MHD_YES on success, #MHD_NO on failure (will cause
  *        connection to be closed)
  */
-// FIXME: This function will need to be called at the right place(s)
-// in the connection processing (just after we are done sending the header)
-// (for responses that have the 'upgrade_header' callback set).
 int
 MHD_response_execute_upgrade_ (struct MHD_Response *response,
                                struct MHD_Connection *connection);


hooks/post-receive
-- 
GNU libmicrohttpd



reply via email to

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