gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r5515 - libmicrohttpd/src/daemon


From: gnunet
Subject: [GNUnet-SVN] r5515 - libmicrohttpd/src/daemon
Date: Sun, 19 Aug 2007 02:45:52 -0600 (MDT)

Author: grothoff
Date: 2007-08-19 02:45:43 -0600 (Sun, 19 Aug 2007)
New Revision: 5515

Modified:
   libmicrohttpd/src/daemon/connection.c
   libmicrohttpd/src/daemon/daemon.c
Log:
more logging and fix in usec calculation

Modified: libmicrohttpd/src/daemon/connection.c
===================================================================
--- libmicrohttpd/src/daemon/connection.c       2007-08-19 04:15:14 UTC (rev 
5514)
+++ libmicrohttpd/src/daemon/connection.c       2007-08-19 08:45:43 UTC (rev 
5515)
@@ -43,6 +43,19 @@
 #define REQUEST_TOO_BIG ""
 
 /**
+ * Add extra debug messages with reasons for closing connections
+ * (non-error reasons).
+ */ 
+#define DEBUG_CLOSE 0
+
+
+/**
+ * Should all data send be printed to stderr?
+ */
+#define DEBUG_SEND_DATA 0
+
+
+/**
  * Get all of the headers from the request.
  *
  * @param iterator callback to call on each header;
@@ -179,6 +192,10 @@
   if (ret == -1)
     {
       /* end of message, signal other side by closing! */
+#if DEBUG_CLOSE
+      MHD_DLOG (connection->daemon,
+               "Closing connection (end of response)\n");
+#endif
       response->total_size = connection->messagePos;
       CLOSE (connection->socket_fd);
       connection->socket_fd = -1;
@@ -693,6 +710,8 @@
   MHD_parse_cookie_header (connection);
   return;
 DIE:
+  MHD_DLOG (connection->daemon,
+           "Closing connection (problem parsing headers)\n");
   CLOSE (connection->socket_fd);
   connection->socket_fd = -1;
 }
@@ -930,6 +949,10 @@
       connection->read_close = MHD_YES;
       if (connection->readLoc > 0)
         MHD_call_connection_handler (connection);
+#if DEBUG_CLOSE
+      MHD_DLOG (connection->daemon,
+                "Shutting down connection for reading (other side closed 
connection)\n");
+#endif
       shutdown (connection->socket_fd, SHUT_RD);
       return MHD_YES;
     }
@@ -1096,7 +1119,12 @@
           connection->socket_fd = -1;
           return MHD_YES;
         }
-      connection->continuePos += ret;
+#if DEBUG_SEND_DATA
+      fprintf(stderr,
+             "Sent 100 continue response: `%.*s'\n",
+             ret,
+             &HTTP_100_CONTINUE[connection->continuePos]);
+#endif
       return MHD_YES;
     }
   response = connection->response;
@@ -1111,6 +1139,8 @@
           (MHD_NO == MHD_build_header_response (connection)))
         {
           /* oops - close! */
+         MHD_DLOG (connection->daemon, 
+                   "Closing connection (failed to create response header)\n");
           CLOSE (connection->socket_fd);
           connection->socket_fd = -1;
           return MHD_NO;
@@ -1128,6 +1158,12 @@
           connection->socket_fd = -1;
           return MHD_YES;
         }
+#if DEBUG_SEND_DATA
+      fprintf(stderr,
+             "Sent HEADER response: `%.*s'\n",
+             ret,
+             &connection->write_buffer[connection->writePos]);
+#endif
       connection->writePos += ret;
       if (connection->writeLoc == connection->writePos)
         {
@@ -1173,6 +1209,12 @@
       connection->socket_fd = -1;
       return MHD_YES;
     }
+#if DEBUG_SEND_DATA
+  fprintf(stderr,
+         "Sent DATA response: `%.*s'\n",
+         ret,
+         &response->data[connection->messagePos - response->data_start]);
+#endif
   connection->messagePos += ret;
   if (connection->messagePos > response->total_size)
     abort ();                   /* internal error */
@@ -1196,8 +1238,13 @@
           (0 != strcasecmp (MHD_HTTP_VERSION_1_1, connection->version)))
         {
           /* closed for reading => close for good! */
-          if (connection->socket_fd != -1)
+          if (connection->socket_fd != -1) {
+#if DEBUG_CLOSE
+           MHD_DLOG (connection->daemon,
+                     "Closing connection (http 1.0 or end-of-stream for 
unknown content length)\n");
+#endif
             CLOSE (connection->socket_fd);
+         }
           connection->socket_fd = -1;
         }
       connection->version = NULL;

Modified: libmicrohttpd/src/daemon/daemon.c
===================================================================
--- libmicrohttpd/src/daemon/daemon.c   2007-08-19 04:15:14 UTC (rev 5514)
+++ libmicrohttpd/src/daemon/daemon.c   2007-08-19 08:45:43 UTC (rev 5515)
@@ -41,6 +41,12 @@
 #define MHD_POOL_SIZE_DEFAULT (1024 * 1024)
 
 /**
+ * Print extra messages with reasons for closing
+ * sockets? (only adds non-error messages). 
+ */
+#define DEBUG_CLOSE 0
+
+/**
  * Register an access handler for all URIs beginning with uri_prefix.
  *
  * @param uri_prefix
@@ -218,6 +224,10 @@
     }
   if (con->socket_fd != -1)
     {
+#if DEBUG_CLOSE
+      MHD_DLOG (con->daemon, 
+               "Processing thread terminating, closing connection\n");
+#endif
       CLOSE (con->socket_fd);
       con->socket_fd = -1;
     }
@@ -263,6 +273,10 @@
   if ((daemon->apc != NULL) &&
       (MHD_NO == daemon->apc (daemon->apc_cls, addr, addrlen)))
     {
+#if DEBUG_CLOSE
+      MHD_DLOG (daemon, 
+               "Connection rejected, closing connection\n");
+#endif
       CLOSE (s);
       return MHD_YES;
     }
@@ -334,6 +348,10 @@
     {
       if ((pos->last_activity < timeout) && (pos->socket_fd != -1))
         {
+#if DEBUG_CLOSE
+         MHD_DLOG (daemon, 
+                   "Connection timed out, closing connection\n");
+#endif
           CLOSE (pos->socket_fd);
           pos->socket_fd = -1;
         }
@@ -470,7 +488,7 @@
           /* ltimeout is in ms */
           if (MHD_YES == MHD_get_timeout (daemon, &ltimeout))
             {
-              timeout.tv_usec = (ltimeout % 1000) * 1000 * 1000;
+              timeout.tv_usec = (ltimeout % 1000) * 1000;
               timeout.tv_sec = ltimeout / 1000;
               may_block = MHD_NO;
             }
@@ -705,6 +723,10 @@
   daemon->shutdown = MHD_YES;
   fd = daemon->socket_fd;
   daemon->socket_fd = -1;
+#if DEBUG_CLOSE
+  MHD_DLOG (daemon, 
+           "MHD shutdown, closing listen socket\n");
+#endif
   CLOSE (fd);
   if ((0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) ||
       (0 != (daemon->options & MHD_USE_SELECT_INTERNALLY)))
@@ -716,6 +738,10 @@
     {
       if (-1 != daemon->connections->socket_fd)
         {
+#if DEBUG_CLOSE
+         MHD_DLOG (daemon, 
+                   "MHD shutdown, closing active connections\n");
+#endif
           CLOSE (daemon->connections->socket_fd);
           daemon->connections->socket_fd = -1;
         }





reply via email to

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