Procházet zdrojové kódy

patch from FC to fix use of resume in combination with external select

Christian Grothoff před 10 roky
rodič
revize
9e87c9a225
5 změnil soubory, kde provedl 39 přidání a 22 odebrání
  1. 1 0
      AUTHORS
  2. 5 0
      ChangeLog
  3. 1 1
      src/include/microhttpd.h
  4. 6 0
      src/microhttpd/daemon.c
  5. 26 21
      src/testcurl/test_callback.c

+ 1 - 0
AUTHORS

@@ -54,6 +54,7 @@ Guy Martin <[email protected]>
 Robert Groenenberg <[email protected]>
 Denis Dowling <[email protected]>
 Louis Benoit <[email protected]>
+Flavio Coelin <[email protected]>
 
 Documentation contributions also came from:
 Marco Maggi <[email protected]>

+ 5 - 0
ChangeLog

@@ -1,3 +1,8 @@
+Wed Sep  2 16:50:31 CEST 2015
+ 	Call resume_suspended_connections() when the user is running
+	its own mainloop and calls MHD_run_from_select() to support
+	resuming connections with external select. -FC
+	
 Sun Aug 30 14:53:51 CEST 2015
 	Correct documentation as to when MHD_USE_EPOLL_LINUX_ONLY
 	is allowed. -CG

+ 1 - 1
src/include/microhttpd.h

@@ -130,7 +130,7 @@ typedef intptr_t ssize_t;
  * Current version of the library.
  * 0x01093001 = 1.9.30-1.
  */
-#define MHD_VERSION 0x00094210
+#define MHD_VERSION 0x00094211
 
 /**
  * MHD-internal return code for "YES".

+ 6 - 0
src/microhttpd/daemon.c

@@ -2220,6 +2220,12 @@ MHD_run_from_select (struct MHD_Daemon *daemon,
   char tmp;
   struct MHD_Connection *pos;
   struct MHD_Connection *next;
+  unsigned int mask = MHD_USE_SUSPEND_RESUME | MHD_USE_EPOLL_INTERNALLY_LINUX_ONLY |
+    MHD_USE_SELECT_INTERNALLY | MHD_USE_POLL_INTERNALLY | MHD_USE_THREAD_PER_CONNECTION;
+ 
+  /* Resuming external connections when using an extern mainloop  */
+  if (MHD_USE_SUSPEND_RESUME == (daemon->options & mask))
+    resume_suspended_connections (daemon);
 
 #if EPOLL_SUPPORT
   if (0 != (daemon->options & MHD_USE_EPOLL_LINUX_ONLY))

+ 26 - 21
src/testcurl/test_callback.c

@@ -17,59 +17,63 @@
      Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
      Boston, MA 02110-1301, USA.
 */
-
 /**
  * @file test_callback.c
  * @brief Testcase for MHD not calling the callback too often
- * @author Jan Seeger 
+ * @author Jan Seeger
  * @author Christian Grothoff
  */
-
-
 #include "MHD_config.h"
 #include "platform.h"
 #include <curl/curl.h>
 #include <microhttpd.h>
 
-struct callback_closure {
+struct callback_closure
+{
   unsigned int called;
 };
 
 
-static ssize_t 
-called_twice(void *cls, uint64_t pos, char *buf, size_t max) 
+static ssize_t
+called_twice(void *cls, uint64_t pos, char *buf, size_t max)
 {
   struct callback_closure *cls2 = cls;
-  
-  if (cls2->called == 0) 
+
+  if (cls2->called == 0)
     {
       memset(buf, 0, max);
       strcat(buf, "test");
       cls2->called = 1;
       return strlen(buf);
     }
-  if (cls2->called == 1) 
+  if (cls2->called == 1)
     {
       cls2->called = 2;
       return MHD_CONTENT_READER_END_OF_STREAM;
     }
-  fprintf(stderr, 
+  fprintf(stderr,
 	  "Handler called after returning END_OF_STREAM!\n");
   return MHD_CONTENT_READER_END_WITH_ERROR;
 }
 
 
 static int
-callback(void *cls, struct MHD_Connection *connection, const char *url,
-	 const char *method, const char *version, const char *upload_data,
-	 size_t *upload_data_size, void **con_cls) {
+callback(void *cls,
+         struct MHD_Connection *connection,
+         const char *url,
+	 const char *method,
+         const char *version,
+         const char *upload_data,
+	 size_t *upload_data_size,
+         void **con_cls)
+{
   struct callback_closure *cbc = calloc(1, sizeof(struct callback_closure));
   struct MHD_Response *r;
 
-  r = MHD_create_response_from_callback (MHD_SIZE_UNKNOWN, 1024, 
-					 &called_twice, cbc, 
+  r = MHD_create_response_from_callback (MHD_SIZE_UNKNOWN, 1024,
+					 &called_twice, cbc,
 					 &free);
-  MHD_queue_response(connection, 200, r);
+  MHD_queue_response(connection, MHD_HTTP_OK, r);
   MHD_destroy_response(r);
   return MHD_YES;
 }
@@ -82,7 +86,8 @@ discard_buffer (void *ptr, size_t size, size_t nmemb, void *ctx)
 }
 
 
-int main(int argc, char **argv) 
+int
+main(int argc, char **argv)
 {
   struct MHD_Daemon *d;
   fd_set rs;
@@ -97,11 +102,11 @@ int main(int argc, char **argv)
   struct timeval tv;
   int extra;
 
-  d = MHD_start_daemon(0, 
+  d = MHD_start_daemon(0,
 		       8000,
 		       NULL,
 		       NULL,
-		       callback,
+		       &callback,
 		       NULL,
 		       MHD_OPTION_END);
   c = curl_easy_init ();
@@ -145,7 +150,7 @@ int main(int argc, char **argv)
 	      curl_easy_cleanup (c);
 	      MHD_stop_daemon (d);
 	      return 3;
-	    }   
+	    }
 	}
       if (MHD_YES !=
 	  MHD_get_fdset(d, &rs, &ws, &es, &max))