gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r5032 - in libmicrohttpd: . src/daemon


From: gnunet
Subject: [GNUnet-SVN] r5032 - in libmicrohttpd: . src/daemon
Date: Wed, 13 Jun 2007 01:21:51 -0600 (MDT)

Author: grothoff
Date: 2007-06-13 01:21:51 -0600 (Wed, 13 Jun 2007)
New Revision: 5032

Modified:
   libmicrohttpd/README
   libmicrohttpd/src/daemon/daemon.c
   libmicrohttpd/src/daemon/session.c
Log:
added essential logging

Modified: libmicrohttpd/README
===================================================================
--- libmicrohttpd/README        2007-06-13 07:11:28 UTC (rev 5031)
+++ libmicrohttpd/README        2007-06-13 07:21:51 UTC (rev 5032)
@@ -10,7 +10,6 @@
 ===========
 daemon.c:
 - MHD_cleanup_session: major memory leaks (headers!)
-- add additional LOG messages for debugging
 
 session.c:
 - MHD_session_get_fdset (essentially not implemented)

Modified: libmicrohttpd/src/daemon/daemon.c
===================================================================
--- libmicrohttpd/src/daemon/daemon.c   2007-06-13 07:11:28 UTC (rev 5031)
+++ libmicrohttpd/src/daemon/daemon.c   2007-06-13 07:21:51 UTC (rev 5032)
@@ -415,8 +415,6 @@
                 void * dh_cls) {
   struct MHD_Daemon * retVal;
   int socket_fd;
-  int opt;
-  int res;
   struct sockaddr_in servaddr; 
 
   if ((options & MHD_USE_SSL) != 0) 
@@ -430,7 +428,10 @@
     return NULL;
   socket_fd = socket(AF_INET, SOCK_STREAM, 0);
   if (socket_fd < 0) {
-    /* FIXME: log error */
+    if ((options & MHD_USE_DEBUG) != 0)
+      fprintf(stderr,
+             "Call to socket failed: %s\n",
+             strerror(errno));
     return NULL;
   }
   memset(&servaddr,
@@ -441,22 +442,22 @@
   if (bind(socket_fd, 
           (struct sockaddr *)&servaddr, 
           sizeof(struct sockaddr_in)) < 0) {
-    /* FIXME: log error */
+    if ( (options & MHD_USE_DEBUG) != 0)
+      fprintf(stderr,
+             "Failed to bind to port %u: %s\n",
+             port,
+             strerror(errno));
     close(socket_fd);
     return NULL;
   }    
   if (listen(socket_fd, 20) < 0) {
-    /* FIXME: log error */
+    if ((options & MHD_USE_DEBUG) != 0)
+      fprintf(stderr,
+             "Failed to listen for connections: %s\n",
+             strerror(errno));
+    close(socket_fd);
     return NULL;        
   }    
-  opt = fcntl(socket_fd, F_GETFL, 0);
-  res = fcntl(socket_fd, F_SETFL, opt | O_NONBLOCK);
-  if (res < 0) {
-    /* FIXME: log error */
-    close(socket_fd);
-    return NULL;
-  }
-
   retVal = malloc(sizeof(struct MHD_Daemon));
   memset(retVal,
         0,
@@ -476,7 +477,9 @@
                            NULL, 
                            &MHD_select_thread, 
                            daemon)) ) {
-    /* FIXME: log error */
+    MHD_DLOG(retVal,
+            "Failed to create listen thread: %s\n",
+            strerror(errno));
     free(retVal);
     close(socket_fd);
     return NULL;    
@@ -512,3 +515,4 @@
   free(daemon);
 }
 
+/* end of daemon.c */

Modified: libmicrohttpd/src/daemon/session.c
===================================================================
--- libmicrohttpd/src/daemon/session.c  2007-06-13 07:11:28 UTC (rev 5031)
+++ libmicrohttpd/src/daemon/session.c  2007-06-13 07:21:51 UTC (rev 5032)
@@ -175,7 +175,9 @@
        session->read_buffer_size *= 2;
       } else {
        /* die, header far too long to be reasonable */
-       /* FIXME: log */
+       MHD_DLOG(session->daemon,
+                "Received excessively long header line (>%u), closing 
connection.\n",
+                4 * MHD_MAX_BUF_SIZE);
        close(session->socket_fd);
        session->socket_fd = -1;
       }
@@ -251,7 +253,8 @@
     colon = strstr(line, ": ");
     if (colon == NULL) {
       /* error in header line, die hard */
-      /* FIXME: log */
+      MHD_DLOG(session->daemon,
+              "Received malformed line (no colon), closing connection.\n");
       goto DIE;
     }
     /* zero-terminate header */
@@ -297,7 +300,9 @@
   unsigned int processed;
 
   if (session->bodyReceived) {
-    /* FIXME: LOG: why are we in select set? */
+    MHD_DLOG(session->daemon,
+            "Unexpected call to %s.\n",
+            __FUNCTION__);
     return MHD_NO; 
   }
   if (session->readLoc >= session->read_buffer_size) {
@@ -315,7 +320,9 @@
   if (bytes_read < 0) {
     if (errno == EINTR)
       return MHD_NO;
-    /* FIXME: log error */
+    MHD_DLOG(session->daemon,
+            "Failed to receive data: %s\n",
+            strerror(errno));
     return MHD_NO;
   }
   if (bytes_read == 0) {
@@ -409,7 +416,9 @@
 
   response = session->response;
   if(response == NULL) {
-    /* FIXME: LOG: why are we here? */
+    MHD_DLOG(session->daemon,
+            "Unexpected call to %s.\n",
+            __FUNCTION__);
     return MHD_NO;
   }
   if (! session->headersSent) {
@@ -422,7 +431,9 @@
     if (ret < 0) {
       if (errno == EINTR)
        return MHD_YES;
-      /* FIXME: log error */
+      MHD_DLOG(session->daemon,
+              "Failed to send data: %s\n",
+              strerror(errno));
       close(session->socket_fd);
       session->socket_fd = -1;
       return MHD_NO;
@@ -480,7 +491,9 @@
   if (ret == -1) {
     if (errno == EINTR)
       return MHD_YES;
-    /* FIXME: log */
+    MHD_DLOG(session->daemon,
+            "Failed to send data: %s\n",
+            strerror(errno));
     return MHD_NO;
   }
   session->messagePos += ret;





reply via email to

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