gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r28915 - in libmicrohttpd: . src/include src/microhttpd src


From: gnunet
Subject: [GNUnet-SVN] r28915 - in libmicrohttpd: . src/include src/microhttpd src/testcurl
Date: Fri, 30 Aug 2013 13:54:57 +0200

Author: grothoff
Date: 2013-08-30 13:54:56 +0200 (Fri, 30 Aug 2013)
New Revision: 28915

Modified:
   libmicrohttpd/ChangeLog
   libmicrohttpd/src/include/microhttpd.h
   libmicrohttpd/src/microhttpd/connection.c
   libmicrohttpd/src/microhttpd/daemon.c
   libmicrohttpd/src/testcurl/test_post.c
Log:
towards fixing #3008

Modified: libmicrohttpd/ChangeLog
===================================================================
--- libmicrohttpd/ChangeLog     2013-08-30 11:41:26 UTC (rev 28914)
+++ libmicrohttpd/ChangeLog     2013-08-30 11:54:56 UTC (rev 28915)
@@ -1,3 +1,10 @@
+Fri Aug 30 13:53:04 CEST 2013
+       Started to implement #3008 (RFC 2616, section 8.1.4
+       says HTTP server SHOULD terminate connection if the
+       client closes it for writing via TCP FIN, so we should
+       to continue to try to read and react differently
+       if recv() returns zero). -CG
+
 Wed Aug 28 18:40:47 CEST 2013
        Fix #3007 (build issue if messages are disabled). -CG
 

Modified: libmicrohttpd/src/include/microhttpd.h
===================================================================
--- libmicrohttpd/src/include/microhttpd.h      2013-08-30 11:41:26 UTC (rev 
28914)
+++ libmicrohttpd/src/include/microhttpd.h      2013-08-30 11:54:56 UTC (rev 
28915)
@@ -120,7 +120,7 @@
 /**
  * Current version of the library.
  */
-#define MHD_VERSION 0x00092201
+#define MHD_VERSION 0x00092202
 
 /**
  * MHD-internal return code for "YES".
@@ -882,8 +882,16 @@
    * data.
    * @ingroup request
    */
-  MHD_REQUEST_TERMINATED_READ_ERROR = 4
+  MHD_REQUEST_TERMINATED_READ_ERROR = 4,
 
+  /**
+   * The client terminated the connection by closing the socket
+   * for writing (TCP half-closed); MHD aborted sending the
+   * response according to RFC 2616, section 8.1.4.
+   * @ingroup request
+   */
+  MHD_REQUEST_TERMINATED_CLIENT_ABORT = 5
+
 };
 
 

Modified: libmicrohttpd/src/microhttpd/connection.c
===================================================================
--- libmicrohttpd/src/microhttpd/connection.c   2013-08-30 11:41:26 UTC (rev 
28914)
+++ libmicrohttpd/src/microhttpd/connection.c   2013-08-30 11:54:56 UTC (rev 
28915)
@@ -1494,7 +1494,6 @@
 
   if (connection->read_buffer_size == connection->read_buffer_offset)
     return MHD_NO;
-
   bytes_read = connection->recv_cls (connection,
                                      &connection->read_buffer
                                      [connection->read_buffer_offset],
@@ -1520,11 +1519,11 @@
     }
   if (0 == bytes_read)
     {
-      /* other side closed connection */
+      /* other side closed connection; RFC 2616, section 8.1.4 suggests
+        we should then shutdown ourselves as well. */
       connection->read_closed = MHD_YES;
-      /* shutdown is not required here, as the other side already
-        knows; so flagging this internally should suffice */
-      /* SHUTDOWN (connection->socket_fd, SHUT_RD); */
+      MHD_connection_close (connection,
+                           MHD_REQUEST_TERMINATED_CLIENT_ABORT);
       return MHD_YES;
     }
   connection->read_buffer_offset += bytes_read;
@@ -2465,6 +2464,15 @@
        }
       break;
     case MHD_EVENT_LOOP_INFO_WRITE:
+      if ( (connection->read_buffer_size > connection->read_buffer_offset) && 
+          (0 != (connection->epoll_state & MHD_EPOLL_STATE_READ_READY)) &&
+          (0 == (connection->epoll_state & MHD_EPOLL_STATE_IN_EREADY_EDLL)) )
+       {
+         EDLL_insert (daemon->eready_head,
+                      daemon->eready_tail,
+                      connection);
+         connection->epoll_state |= MHD_EPOLL_STATE_IN_EREADY_EDLL;
+       }
       if ( (0 != (connection->epoll_state & MHD_EPOLL_STATE_WRITE_READY)) &&
           (0 == (connection->epoll_state & MHD_EPOLL_STATE_IN_EREADY_EDLL)) )
        {
@@ -2498,8 +2506,8 @@
 
 #if EPOLL_SUPPORT
 /**
- * Perform epoll processing, possibly moving the connection back into
- * the epoll set if needed.
+ * Perform epoll() processing, possibly moving the connection back into
+ * the epoll() set if needed.
  *
  * @param connection connection to process
  * @return MHD_YES if we should continue to process the
@@ -2514,7 +2522,8 @@
        (0 == (connection->epoll_state & MHD_EPOLL_STATE_IN_EPOLL_SET)) &&
        ( (0 == (connection->epoll_state & MHD_EPOLL_STATE_WRITE_READY)) ||
         ( (0 == (connection->epoll_state & MHD_EPOLL_STATE_READ_READY)) &&
-          (MHD_EVENT_LOOP_INFO_READ == connection->event_loop_info) &&
+          ( (MHD_EVENT_LOOP_INFO_READ == connection->event_loop_info) ||
+            (connection->read_buffer_size > connection->read_buffer_offset) ) 
&&
           (MHD_NO == connection->read_closed) ) ) )
     {
       /* add to epoll set */
@@ -2694,11 +2703,8 @@
         (0 == strcasecmp (connection->method,
                           MHD_HTTP_METHOD_PUT))) )
     {
-      /* response was queued "early",
-         refuse to read body / footers or further
-         requests! */
-      if (0 == (connection->daemon->options & MHD_USE_EPOLL_TURBO))
-       (void) SHUTDOWN (connection->socket_fd, SHUT_RD);
+      /* response was queued "early", refuse to read body / footers or
+         further requests! */
       connection->read_closed = MHD_YES;
       connection->state = MHD_CONNECTION_FOOTERS_RECEIVED;
     }

Modified: libmicrohttpd/src/microhttpd/daemon.c
===================================================================
--- libmicrohttpd/src/microhttpd/daemon.c       2013-08-30 11:41:26 UTC (rev 
28914)
+++ libmicrohttpd/src/microhttpd/daemon.c       2013-08-30 11:54:56 UTC (rev 
28915)
@@ -615,9 +615,12 @@
          break;
        case MHD_EVENT_LOOP_INFO_WRITE:
          add_to_fd_set (pos->socket_fd, write_fd_set, max_fd);
+         if (pos->read_buffer_size > pos->read_buffer_offset)
+           add_to_fd_set (pos->socket_fd, read_fd_set, max_fd);
          break;
        case MHD_EVENT_LOOP_INFO_BLOCK:
-         /* not in any FD set */
+         if (pos->read_buffer_size > pos->read_buffer_offset)
+           add_to_fd_set (pos->socket_fd, read_fd_set, max_fd);
          break;
        case MHD_EVENT_LOOP_INFO_CLEANUP:
          /* this should never happen */
@@ -693,8 +696,12 @@
              break;
            case MHD_EVENT_LOOP_INFO_WRITE:
              add_to_fd_set (con->socket_fd, &ws, &max);
+             if (con->read_buffer_size > con->read_buffer_offset)
+               add_to_fd_set (con->socket_fd, &rs, &max);
              break;
            case MHD_EVENT_LOOP_INFO_BLOCK:
+             if (con->read_buffer_size > con->read_buffer_offset)
+               add_to_fd_set (con->socket_fd, &rs, &max);
              tv.tv_sec = 0;
              tv.tv_usec = 0;
              tvp = &tv;
@@ -741,8 +748,12 @@
              break;
            case MHD_EVENT_LOOP_INFO_WRITE:
              p[0].events |= POLLOUT;
+             if (con->read_buffer_size > con->read_buffer_offset)
+               p[0].events |= POLLIN;  
              break;
            case MHD_EVENT_LOOP_INFO_BLOCK:
+             if (con->read_buffer_size > con->read_buffer_offset)
+               p[0].events |= POLLIN;  
              tv.tv_sec = 0;
              tv.tv_usec = 0;
              tvp = &tv;
@@ -1774,11 +1785,16 @@
                pos->read_handler (pos);
              break;
            case MHD_EVENT_LOOP_INFO_WRITE:
+             if ( (FD_ISSET (ds, read_fd_set)) &&
+                  (pos->read_buffer_size > pos->read_buffer_offset) )
+               pos->read_handler (pos);
              if (FD_ISSET (ds, write_fd_set))
                pos->write_handler (pos);
              break;
            case MHD_EVENT_LOOP_INFO_BLOCK:
-             /* only idle handler */
+             if ( (FD_ISSET (ds, read_fd_set)) &&
+                  (pos->read_buffer_size > pos->read_buffer_offset) )
+               pos->read_handler (pos);
              break;
            case MHD_EVENT_LOOP_INFO_CLEANUP:
              /* should never happen */
@@ -1903,9 +1919,7 @@
   /* count number of connections and thus determine poll set size */
   num_connections = 0;
   for (pos = daemon->connections_head; NULL != pos; pos = pos->next)
-    if ( (MHD_EVENT_LOOP_INFO_READ == pos->event_loop_info) ||
-        (MHD_EVENT_LOOP_INFO_WRITE == pos->event_loop_info) )
-      num_connections++;
+    num_connections++;
   {
     struct pollfd p[2 + num_connections];
     MHD_UNSIGNED_LONG_LONG ltimeout;
@@ -1953,9 +1967,12 @@
            break;
          case MHD_EVENT_LOOP_INFO_WRITE:
            p[poll_server+i].events |= POLLOUT;
+           if (pos->read_buffer_size > pos->read_buffer_offset)
+             p[poll_server+i].events |= POLLIN;        
            break;
          case MHD_EVENT_LOOP_INFO_BLOCK:
-           /* not in poll */
+           if (pos->read_buffer_size > pos->read_buffer_offset)
+             p[poll_server+i].events |= POLLIN;        
            break;
          case MHD_EVENT_LOOP_INFO_CLEANUP:
            /* should never happen */
@@ -2005,12 +2022,16 @@
            if (p[poll_server+i].fd != pos->socket_fd)
              break; /* fd mismatch, something else happened, retry later ... */
            /* normal handling */
+           if (0 != (p[poll_server+i].revents & POLLIN)) 
+             pos->read_handler (pos);
            if (0 != (p[poll_server+i].revents & POLLOUT)) 
              pos->write_handler (pos);
            pos->idle_handler (pos);
            i++;
            break;
          case MHD_EVENT_LOOP_INFO_BLOCK:
+           if (0 != (p[poll_server+i].revents & POLLIN)) 
+             pos->read_handler (pos);
            pos->idle_handler (pos);
            break;
          case MHD_EVENT_LOOP_INFO_CLEANUP:
@@ -2234,7 +2255,8 @@
              if (0 != (events[i].events & EPOLLIN))
                {
                  pos->epoll_state |= MHD_EPOLL_STATE_READ_READY;
-                 if ( (MHD_EVENT_LOOP_INFO_READ == pos->event_loop_info) &&
+                 if ( ( (MHD_EVENT_LOOP_INFO_READ == pos->event_loop_info) ||
+                        (pos->read_buffer_size > pos->read_buffer_offset) ) &&
                       (0 == (pos->epoll_state & 
MHD_EPOLL_STATE_IN_EREADY_EDLL) ) )
                    {
                      EDLL_insert (daemon->eready_head, 

Modified: libmicrohttpd/src/testcurl/test_post.c
===================================================================
--- libmicrohttpd/src/testcurl/test_post.c      2013-08-30 11:41:26 UTC (rev 
28914)
+++ libmicrohttpd/src/testcurl/test_post.c      2013-08-30 11:54:56 UTC (rev 
28915)
@@ -481,6 +481,7 @@
   size_t pos;
 };
 
+
 static size_t 
 readBuffer(void *p, size_t size, size_t nmemb, void *opaque)
 {
@@ -497,6 +498,7 @@
   return required/size;
 }
 
+
 static size_t 
 slowReadBuffer(void *p, size_t size, size_t nmemb, void *opaque)
 {
@@ -504,6 +506,7 @@
   return readBuffer(p, size, nmemb, opaque);
 }
 
+
 #define FLAG_EXPECT_CONTINUE 1
 #define FLAG_CHUNKED 2
 #define FLAG_FORM_DATA 4
@@ -604,6 +607,7 @@
   return result;
 }
 
+
 static int
 testMultithreadedPostCancel()
 {




reply via email to

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