gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] [libmicrohttpd] branch master updated (3e7a55e9 -> 7934cc07


From: gnunet
Subject: [GNUnet-SVN] [libmicrohttpd] branch master updated (3e7a55e9 -> 7934cc07)
Date: Sun, 27 Aug 2017 20:46:55 +0200

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

karlson2k pushed a change to branch master
in repository libmicrohttpd.

    from 3e7a55e9 updates to proposed API based on discussions with EG
     new 4fc783ec mhd_threads: added thread ID support
     new 95394267 mhd_threads: added MHD_thread_ID_match_current_()
     new 7934cc07 MHD_queue_response(): check for correct thread ID

The 3 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  | 14 +++++++++++---
 src/microhttpd/daemon.c      | 10 ++++++----
 src/microhttpd/internal.h    |  4 ++--
 src/microhttpd/mhd_threads.c | 28 ++++++++++++----------------
 src/microhttpd/mhd_threads.h | 42 ++++++++++++++++++++++++++++++++++++++++--
 5 files changed, 71 insertions(+), 27 deletions(-)

diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c
index bbebfc57..95823992 100644
--- a/src/microhttpd/connection.c
+++ b/src/microhttpd/connection.c
@@ -3769,9 +3769,7 @@ MHD_queue_response (struct MHD_Connection *connection,
                     unsigned int status_code,
                     struct MHD_Response *response)
 {
-#ifdef UPGRADE_SUPPORT
   struct MHD_Daemon *daemon;
-#endif /* UPGRADE_SUPPORT */
 
   if ( (NULL == connection) ||
        (NULL == response) ||
@@ -3779,8 +3777,18 @@ MHD_queue_response (struct MHD_Connection *connection,
        ( (MHD_CONNECTION_HEADERS_PROCESSED != connection->state) &&
         (MHD_CONNECTION_FOOTERS_RECEIVED != connection->state) ) )
     return MHD_NO;
-#ifdef UPGRADE_SUPPORT
   daemon = connection->daemon;
+  if ( (!connection->suspended) &&
+       (0 != (daemon->options & MHD_USE_INTERNAL_POLLING_THREAD)) &&
+       (!MHD_thread_ID_match_current_(connection->pid.ID)) )
+    {
+#ifdef HAVE_MESSAGES
+      MHD_DLOG (daemon,
+                _("Attempted to queue response on wrong thread!\n"));
+#endif
+      return MHD_NO;
+    }
+#ifdef UPGRADE_SUPPORT
   if ( (NULL != response->upgrade_handler) &&
        (0 == (daemon->options & MHD_ALLOW_UPGRADE)) )
     {
diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c
index 88dabed5..51b05d8e 100644
--- a/src/microhttpd/daemon.c
+++ b/src/microhttpd/daemon.c
@@ -2397,6 +2397,8 @@ internal_add_connection (struct MHD_Daemon *daemon,
          goto cleanup;
         }
     }
+  else
+    connection->pid = daemon->pid;
 #ifdef EPOLL_SUPPORT
   if (0 != (daemon->options & MHD_USE_EPOLL))
     {
@@ -2962,7 +2964,7 @@ MHD_cleanup_connections (struct MHD_Daemon *daemon)
 
       if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
           (! pos->thread_joined) &&
-           (! MHD_join_thread_ (pos->pid)) )
+           (! MHD_join_thread_ (pos->pid.handle)) )
         MHD_PANIC (_("Failed to join a thread\n"));
 #ifdef UPGRADE_SUPPORT
       cleanup_upgraded_connection (pos);
@@ -6131,7 +6133,7 @@ close_all_connections (struct MHD_Daemon *daemon)
         if (! pos->thread_joined)
           {
             MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex);
-            if (! MHD_join_thread_ (pos->pid))
+            if (! MHD_join_thread_ (pos->pid.handle))
               MHD_PANIC (_("Failed to join a thread\n"));
             MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex);
             pos->thread_joined = true;
@@ -6218,7 +6220,7 @@ MHD_stop_daemon (struct MHD_Daemon *daemon)
           /* Start harvesting. */
           for (i = 0; i < daemon->worker_pool_size; ++i)
             {
-              if (! MHD_join_thread_ (daemon->worker_pool[i].pid))
+              if (! MHD_join_thread_ (daemon->worker_pool[i].pid.handle))
                 MHD_PANIC (_("Failed to join a thread\n"));
 #ifdef EPOLL_SUPPORT
               if (-1 != daemon->worker_pool[i].epoll_fd)
@@ -6252,7 +6254,7 @@ MHD_stop_daemon (struct MHD_Daemon *daemon)
                                  SHUT_RDWR);
             }
 #endif
-          if (! MHD_join_thread_ (daemon->pid))
+          if (! MHD_join_thread_ (daemon->pid.handle))
             {
               MHD_PANIC (_("Failed to join a thread\n"));
             }
diff --git a/src/microhttpd/internal.h b/src/microhttpd/internal.h
index 85fe2487..602a5d4f 100644
--- a/src/microhttpd/internal.h
+++ b/src/microhttpd/internal.h
@@ -755,7 +755,7 @@ struct MHD_Connection
    * Thread handle for this connection (if we are using
    * one thread per connection).
    */
-  MHD_thread_handle_ pid;
+  MHD_thread_handle_ID_ pid;
 
   /**
    * Size of @e read_buffer (in bytes).  This value indicates
@@ -1442,7 +1442,7 @@ struct MHD_Daemon
   /**
    * The select thread handle (if we have internal select)
    */
-  MHD_thread_handle_ pid;
+  MHD_thread_handle_ID_ pid;
 
   /**
    * Mutex for per-IP connection counts.
diff --git a/src/microhttpd/mhd_threads.c b/src/microhttpd/mhd_threads.c
index dffbfd00..477080cf 100644
--- a/src/microhttpd/mhd_threads.c
+++ b/src/microhttpd/mhd_threads.c
@@ -38,14 +38,6 @@
 #include <errno.h>
 
 
-
-#if defined(MHD_USE_POSIX_THREADS)
-typedef pthread_t MHD_thread_ID_;
-#elif defined(MHD_USE_W32_THREADS)
-typedef DWORD MHD_thread_ID_;
-#endif
-
-
 #ifndef MHD_USE_THREAD_NAME_
 
 #define MHD_set_thread_name_(t, n) (void)
@@ -183,7 +175,7 @@ MHD_set_thread_name_(const MHD_thread_ID_ thread_id,
  * @return non-zero on success; zero otherwise (with errno set)
  */
 int
-MHD_create_thread_ (MHD_thread_handle_ *thread,
+MHD_create_thread_ (MHD_thread_handle_ID_ *thread,
                     size_t stack_size,
                     MHD_THREAD_START_ROUTINE_ start_routine,
                     void *arg)
@@ -200,7 +192,7 @@ MHD_create_thread_ (MHD_thread_handle_ *thread,
           res = pthread_attr_setstacksize (&attr,
                                            stack_size);
           if (0 == res)
-              res = pthread_create (thread,
+              res = pthread_create (&(thread->handle),
                                     &attr,
                                     start_routine,
                                     arg);
@@ -208,7 +200,7 @@ MHD_create_thread_ (MHD_thread_handle_ *thread,
         }
     }
   else
-    res = pthread_create (thread,
+    res = pthread_create (&(thread->handle),
                           NULL,
                           start_routine,
                           arg);
@@ -218,6 +210,7 @@ MHD_create_thread_ (MHD_thread_handle_ *thread,
 
   return !res;
 #elif defined(MHD_USE_W32_THREADS)
+  unsigned int thread_ID;
 #if SIZE_MAX != UINT_MAX
   if (stack_size > UINT_MAX)
     {
@@ -226,15 +219,18 @@ MHD_create_thread_ (MHD_thread_handle_ *thread,
     }
 #endif /* SIZE_MAX != UINT_MAX */
 
-  *thread = (HANDLE) _beginthreadex (NULL,
+  thread->handle = (MHD_thread_handle_)
+                     _beginthreadex (NULL,
                                      (unsigned int) stack_size,
                                      start_routine,
                                      arg,
                                      0,
-                                     NULL);
-  if ((MHD_thread_handle_)-1 == (*thread))
+                                     &thread_ID);
+
+  if ((MHD_thread_handle_)-1 == thread->handle)
     return 0;
 
+  thread->ID = (MHD_thread_ID_)thread_ID;
   return !0;
 #endif
 }
@@ -294,7 +290,7 @@ named_thread_starter (void *data)
  * @return non-zero on success; zero otherwise (with errno set)
  */
 int
-MHD_create_named_thread_ (MHD_thread_handle_ *thread,
+MHD_create_named_thread_ (MHD_thread_handle_ID_ *thread,
                           const char* thread_name,
                           size_t stack_size,
                           MHD_THREAD_START_ROUTINE_ start_routine,
@@ -323,7 +319,7 @@ MHD_create_named_thread_ (MHD_thread_handle_ *thread,
         res = pthread_attr_setstacksize (&attr,
                                          stack_size);
       if (0 == res)
-          res = pthread_create (thread,
+          res = pthread_create (&(thread->handle),
                                 &attr,
                                 start_routine,
                                 arg);
diff --git a/src/microhttpd/mhd_threads.h b/src/microhttpd/mhd_threads.h
index 988344b6..d5424659 100644
--- a/src/microhttpd/mhd_threads.h
+++ b/src/microhttpd/mhd_threads.h
@@ -86,6 +86,28 @@
 #endif
 
 #if defined(MHD_USE_POSIX_THREADS)
+  typedef pthread_t MHD_thread_ID_;
+#elif defined(MHD_USE_W32_THREADS)
+  typedef DWORD MHD_thread_ID_;
+#endif
+
+#if defined(MHD_USE_POSIX_THREADS)
+  union _MHD_thread_handle_ID_
+  {
+    MHD_thread_handle_  handle;
+    MHD_thread_ID_      ID;
+  };
+  typedef union _MHD_thread_handle_ID_ MHD_thread_handle_ID_;
+#elif defined(MHD_USE_W32_THREADS)
+  struct _MHD_thread_handle_ID_
+  {
+    MHD_thread_handle_  handle;
+    MHD_thread_ID_      ID;
+  };
+  typedef struct _MHD_thread_handle_ID_ MHD_thread_handle_ID_;
+#endif
+
+#if defined(MHD_USE_POSIX_THREADS)
 /**
  * Wait until specified thread is ended and free thread handle on success.
  * @param thread handle to watch
@@ -101,6 +123,22 @@
 #define MHD_join_thread_(thread) (WAIT_OBJECT_0 == 
WaitForSingleObject((thread), INFINITE) ? (CloseHandle((thread)), !0) : 0)
 #endif
 
+#if defined(MHD_USE_POSIX_THREADS)
+/**
+ * Check whether provided thread ID match current thread.
+ * @param ID thread ID to match
+ * @return nonzero on match, zero otherwise
+ */
+#define MHD_thread_ID_match_current_(ID) (pthread_equal((ID), pthread_self()))
+#elif defined(MHD_USE_W32_THREADS)
+/**
+ * Check whether provided thread ID match current thread.
+ * @param ID thread ID to match
+ * @return nonzero on match, zero otherwise
+ */
+#define MHD_thread_ID_match_current_(ID) (GetCurrentThreadId() == (ID))
+#endif
+
 /**
  * Signature of main function for a thread.
  *
@@ -123,7 +161,7 @@ typedef MHD_THRD_RTRN_TYPE_
  * @return non-zero on success; zero otherwise
  */
 int
-MHD_create_thread_ (MHD_thread_handle_ *thread,
+MHD_create_thread_ (MHD_thread_handle_ID_ *thread,
                     size_t stack_size,
                     MHD_THREAD_START_ROUTINE_ start_routine,
                     void *arg);
@@ -142,7 +180,7 @@ MHD_create_thread_ (MHD_thread_handle_ *thread,
  * @return non-zero on success; zero otherwise
  */
 int
-MHD_create_named_thread_ (MHD_thread_handle_ *thread,
+MHD_create_named_thread_ (MHD_thread_handle_ID_ *thread,
                           const char* thread_name,
                           size_t stack_size,
                           MHD_THREAD_START_ROUTINE_ start_routine,

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



reply via email to

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