gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r5614 - in GNUnet/src: include transports


From: gnunet
Subject: [GNUnet-SVN] r5614 - in GNUnet/src: include transports
Date: Sat, 8 Sep 2007 18:01:33 -0600 (MDT)

Author: grothoff
Date: 2007-09-08 18:01:31 -0600 (Sat, 08 Sep 2007)
New Revision: 5614

Modified:
   GNUnet/src/include/gnunet_util_network.h
   GNUnet/src/transports/http.c
   GNUnet/src/transports/test.c
   GNUnet/src/transports/test_repeat.c
Log:
fmt

Modified: GNUnet/src/include/gnunet_util_network.h
===================================================================
--- GNUnet/src/include/gnunet_util_network.h    2007-09-08 23:52:46 UTC (rev 
5613)
+++ GNUnet/src/include/gnunet_util_network.h    2007-09-09 00:01:31 UTC (rev 
5614)
@@ -527,8 +527,7 @@
  * to non-blocking IO.
  * @return OK on success
  */
-int network_make_pipe_nonblocking(struct GE_Context * ectx,
-                                 int pipe);
+int network_make_pipe_nonblocking (struct GE_Context *ectx, int pipe);
 
 #if 0                           /* keep Emacsens' auto-indent happy */
 {

Modified: GNUnet/src/transports/http.c
===================================================================
--- GNUnet/src/transports/http.c        2007-09-08 23:52:46 UTC (rev 5613)
+++ GNUnet/src/transports/http.c        2007-09-09 00:01:31 UTC (rev 5614)
@@ -192,12 +192,13 @@
 /**
  * Server-side data for a GET request.
  */
-struct MHDGetData {
-  
+struct MHDGetData
+{
+
   /**
    * This is a linked list.
    */
-  struct MHDGetData * next;
+  struct MHDGetData *next;
 
   /**
    * mutex for synchronized access to struct
@@ -208,7 +209,7 @@
    * MHD connection handle for this request.
    */
   struct MHD_Connection *session;
-  
+
   /**
    * GET session response handle
    */
@@ -217,13 +218,13 @@
   /**
    * My HTTP session.
    */
-  struct HTTPSession * httpsession;
+  struct HTTPSession *httpsession;
 
   /**
    * The write buffer (for sending GET response)
    */
   char *wbuff;
-  
+
   /**
    * What was the last time we were able to
    * transmit data using the current get handle?
@@ -234,12 +235,12 @@
    * Current write position in wbuff
    */
   unsigned int woff;
-  
+
   /**
    * Number of valid bytes in wbuff (starting at woff)
    */
   unsigned int wpos;
-  
+
   /**
    * Size of the write buffer.
    */
@@ -305,7 +306,7 @@
        * Active GET requests (linked list; most
        * recent received GET is the head of the list).
        */
-      struct MHDGetData * gets;
+      struct MHDGetData *gets;
 #endif
 
     } server;
@@ -600,17 +601,16 @@
       httpsession->cs.server.puts = NULL;
 #if DO_GET
       gpos = httpsession->cs.server.gets;
-      while (gpos != NULL) 
-       {
-         GROW (gpos->wbuff, 
-               gpos->wsize, 0);
+      while (gpos != NULL)
+        {
+          GROW (gpos->wbuff, gpos->wsize, 0);
           r = gpos->get;
           gpos->get = NULL;
           /* contentReaderFreeCallback WILL
              destroy session->lock/tesssion */
-         gnext = gpos->next;
-         MHD_destroy_response (r); 
-         gpos = gnext;
+          gnext = gpos->next;
+          MHD_destroy_response (r);
+          gpos = gnext;
         }
       httpsession->cs.server.gets = NULL;
 #endif
@@ -625,43 +625,48 @@
  * the respective transport state.
  */
 static void
-requestCompletedCallback(void * unused,
-                        struct MHD_Connection * session,
-                        void ** httpSessionCache) {
-  HTTPSession * httpsession = *httpSessionCache;
-  struct MHDPutData * pprev;
-  struct MHDPutData * ppos;
+requestCompletedCallback (void *unused,
+                          struct MHD_Connection *session,
+                          void **httpSessionCache)
+{
+  HTTPSession *httpsession = *httpSessionCache;
+  struct MHDPutData *pprev;
+  struct MHDPutData *ppos;
 #if DO_GET
-  struct MHDGetData * gprev;
-  struct MHDGetData * gpos;
+  struct MHDGetData *gprev;
+  struct MHDGetData *gpos;
 #endif
 
   if (httpsession == NULL)
-    return; /* oops */
-  GE_ASSERT(NULL, !httpsession->is_client);
+    return;                     /* oops */
+  GE_ASSERT (NULL, !httpsession->is_client);
   pprev = NULL;
   ppos = httpsession->cs.server.puts;
-  while (ppos != NULL) {
-    if (ppos->session == session) {
-      ppos->last_activity = 0;
-      signal_select();
-      return;
+  while (ppos != NULL)
+    {
+      if (ppos->session == session)
+        {
+          ppos->last_activity = 0;
+          signal_select ();
+          return;
+        }
+      pprev = ppos;
+      ppos = ppos->next;
     }
-    pprev = ppos;
-    ppos = ppos->next;
-  }
 #if DO_GET
   gprev = NULL;
   gpos = httpsession->cs.server.gets;
-  while (gpos != NULL) {
-    if (gpos->session == session) {
-      gpos->last_get_activity = 0;
-      signal_select();
-      return;
+  while (gpos != NULL)
+    {
+      if (gpos->session == session)
+        {
+          gpos->last_get_activity = 0;
+          signal_select ();
+          return;
+        }
+      gprev = gpos;
+      gpos = gpos->next;
     }
-    gprev = gpos;
-    gpos = gpos->next;
-  }
 #endif
 }
 
@@ -862,7 +867,7 @@
 static int
 contentReaderCallback (void *cls, size_t pos, char *buf, int max)
 {
-  struct MHDGetData * mgd = cls;
+  struct MHDGetData *mgd = cls;
   cron_t now;
 
   MUTEX_LOCK (mgd->lock);
@@ -884,9 +889,8 @@
 #endif
   if (stats != NULL)
     stats->change (stat_bytesSent, max);
-  if ( (max == 0) &&
-       (mgd->httpsession->cs.server.gets != mgd) )
-    return -1; /* end of response (another GET replaces this one) */
+  if ((max == 0) && (mgd->httpsession->cs.server.gets != mgd))
+    return -1;                  /* end of response (another GET replaces this 
one) */
   return max;
 }
 #endif
@@ -899,13 +903,11 @@
 static void
 contentReaderFreeCallback (void *cls)
 {
-  struct MHDGetData * mgd = cls;
+  struct MHDGetData *mgd = cls;
 
   GE_ASSERT (NULL, mgd->get == NULL);
-  MUTEX_DESTROY(mgd->lock);
-  GROW (mgd->wbuff,
-       mgd->wsize,
-       0);
+  MUTEX_DESTROY (mgd->lock);
+  GROW (mgd->wbuff, mgd->wsize, 0);
   FREE (mgd);
 }
 #endif
@@ -925,13 +927,13 @@
                        const char *version,
                        const char *upload_data,
                        unsigned int *upload_data_size,
-                      void **httpSessionCache)
+                       void **httpSessionCache)
 {
   TSession *tsession;
   struct MHDPutData *put;
   struct MHDGetData *get;
   HTTPSession *httpSession;
-  struct MHD_Response * response;
+  struct MHD_Response *response;
   HashCode512 client;
   int i;
   unsigned int have;
@@ -950,19 +952,20 @@
 
   /* check if we already have a session for this */
   httpSession = *httpSessionCache;
-  if (httpSession == NULL) 
+  if (httpSession == NULL)
     {
       MUTEX_LOCK (httplock);
       for (i = 0; i < tsessionCount; i++)
-       {
-         tsession = tsessions[i];
-         httpSession = tsession->internal;
-         if ((0 == memcmp (&httpSession->sender, &client, sizeof 
(HashCode512)))
-             && (httpSession->is_client == NO))
-           break;
-         tsession = NULL;
-         httpSession = NULL;
-       }
+        {
+          tsession = tsessions[i];
+          httpSession = tsession->internal;
+          if ((0 ==
+               memcmp (&httpSession->sender, &client, sizeof (HashCode512)))
+              && (httpSession->is_client == NO))
+            break;
+          tsession = NULL;
+          httpSession = NULL;
+        }
       MUTEX_UNLOCK (httplock);
     }
   /* create new session if necessary */
@@ -1000,19 +1003,19 @@
 
       /* handle get; create response object if we do not 
          have one already */
-      get = MALLOC(sizeof(struct MHDGetData));
-      memset(get, 0, sizeof(struct MHDGetData));
-      get->lock = MUTEX_CREATE(NO);      
+      get = MALLOC (sizeof (struct MHDGetData));
+      memset (get, 0, sizeof (struct MHDGetData));
+      get->lock = MUTEX_CREATE (NO);
       get->next = httpSession->cs.server.gets;
       httpSession->cs.server.gets = get;
       get->session = session;
       get->httpsession = httpSession;
-      get->last_get_activity = get_time();
+      get->last_get_activity = get_time ();
       get->get = MHD_create_response_from_callback (-1,
-                                                   64 * 1024,
-                                                   contentReaderCallback,
-                                                   get,
-                                                   contentReaderFreeCallback);
+                                                    64 * 1024,
+                                                    contentReaderCallback,
+                                                    get,
+                                                    contentReaderFreeCallback);
       MHD_queue_response (session, MHD_HTTP_OK, get->get);
       MUTEX_UNLOCK (httpSession->lock);
       return MHD_YES;
@@ -1483,7 +1486,7 @@
 httpTestWouldTry (TSession * tsession, const unsigned int size, int important)
 {
   HTTPSession *httpSession = tsession->internal;
-  struct MHDGetData * get;
+  struct MHDGetData *get;
   int ret;
 
   if (size >= MAX_BUFFER_SIZE - sizeof (MESSAGE_HEADER))
@@ -1506,21 +1509,20 @@
   else
     {
       /* server */
-      MUTEX_LOCK(httpSession->lock);
+      MUTEX_LOCK (httpSession->lock);
       get = httpSession->cs.server.gets;
       if (get == NULL)
-       ret = NO;      
-      else {
-       if (get->wsize == 0)
-         ret = YES;
-       else
-         if ( (get->wpos + size > get->wsize)
-              && (important != YES) )
-           ret = NO;
-         else
-           ret = YES;
-      }
-      MUTEX_UNLOCK(httpSession->lock);
+        ret = NO;
+      else
+        {
+          if (get->wsize == 0)
+            ret = YES;
+          else if ((get->wpos + size > get->wsize) && (important != YES))
+            ret = NO;
+          else
+            ret = YES;
+        }
+      MUTEX_UNLOCK (httpSession->lock);
       return ret;
     }
 }
@@ -1605,14 +1607,14 @@
 #if DO_GET
   MUTEX_LOCK (httpSession->lock);
   getData = httpSession->cs.server.gets;
-  if (getData == NULL) {
-    MUTEX_UNLOCK (httpSession->lock);
-    return SYSERR;    
-  }
-  MUTEX_LOCK(getData->lock);
+  if (getData == NULL)
+    {
+      MUTEX_UNLOCK (httpSession->lock);
+      return SYSERR;
+    }
+  MUTEX_LOCK (getData->lock);
   if (getData->wsize == 0)
-    GROW (getData->wbuff, getData->wsize,
-          HTTP_BUF_SIZE);
+    GROW (getData->wbuff, getData->wsize, HTTP_BUF_SIZE);
   size += sizeof (MESSAGE_HEADER);
   if (getData->wpos + size > getData->wsize)
     {
@@ -1624,9 +1626,7 @@
           return NO;
         }
       tmp = MALLOC (getData->wpos + size);
-      memcpy (tmp,
-              &getData->wbuff[getData->woff],
-              getData->wpos);
+      memcpy (tmp, &getData->wbuff[getData->woff], getData->wpos);
       hdr = (MESSAGE_HEADER *) & tmp[getData->wpos];
       hdr->type = htons (0);
       hdr->size = htons (size);
@@ -1640,17 +1640,15 @@
   else
     {
       /* fits without growing */
-      if (getData->wpos + getData->woff + size >
-          getData->wsize)
+      if (getData->wpos + getData->woff + size > getData->wsize)
         {
           /* need to compact first */
           memmove (getData->wbuff,
-                   &getData->wbuff[getData->woff],
-                   getData->wpos);
+                   &getData->wbuff[getData->woff], getData->wpos);
           getData->woff = 0;
         }
       /* append */
-      hdr = (MESSAGE_HEADER *) &getData->
+      hdr = (MESSAGE_HEADER *) & getData->
         wbuff[getData->woff + getData->wpos];
       hdr->size = htons (size);
       hdr->type = htons (0);
@@ -1679,7 +1677,7 @@
   struct MHDPutData *mpos;
   struct MHDPutData *mprev;
 #if DO_GET
-  struct MHD_Response * r;
+  struct MHD_Response *r;
   struct MHDGetData *gpos;
   struct MHDGetData *gnext;
 #endif
@@ -1772,26 +1770,28 @@
 
           /* ! s->is_client */
 #if DO_GET
-         gpos = s->cs.server.gets;
-         while (gpos != NULL) {
-           gnext = gpos->next;
-           gpos->next = NULL;
-           if ( (gpos->last_get_activity + HTTP_TIMEOUT < now) ||
-                (gpos != s->cs.server.gets) ) {
-             if (gpos == s->cs.server.gets)
-               s->cs.server.gets = NULL;
-             r = gpos->get;
-             gpos->get = NULL;
-             MHD_destroy_response (r);
-           }
-           gpos = gnext;
-         }
+          gpos = s->cs.server.gets;
+          while (gpos != NULL)
+            {
+              gnext = gpos->next;
+              gpos->next = NULL;
+              if ((gpos->last_get_activity + HTTP_TIMEOUT < now) ||
+                  (gpos != s->cs.server.gets))
+                {
+                  if (gpos == s->cs.server.gets)
+                    s->cs.server.gets = NULL;
+                  r = gpos->get;
+                  gpos->get = NULL;
+                  MHD_destroy_response (r);
+                }
+              gpos = gnext;
+            }
 #endif
           if (
 #if DO_GET
-             (s->cs.server.gets == NULL) &&
+               (s->cs.server.gets == NULL) &&
 #endif
-             (s->users == 0))
+               (s->users == 0))
             {
               MUTEX_UNLOCK (s->lock);
 #if DO_GET
@@ -1923,10 +1923,10 @@
                                      MHD_OPTION_CONNECTION_MEMORY_LIMIT,
                                      (unsigned int) 1024 * 128,
                                      MHD_OPTION_CONNECTION_LIMIT,
-                                     (unsigned int) 128, 
-                                    MHD_OPTION_NOTIFY_COMPLETED,
-                                    &requestCompletedCallback, NULL,
-                                    MHD_OPTION_END);
+                                     (unsigned int) 128,
+                                     MHD_OPTION_NOTIFY_COMPLETED,
+                                     &requestCompletedCallback, NULL,
+                                     MHD_OPTION_END);
     }
   if (0 != PIPE (signal_pipe))
     {
@@ -1936,8 +1936,7 @@
       mhd_daemon = NULL;
       return SYSERR;
     }
-  network_make_pipe_nonblocking(coreAPI->ectx,
-                               signal_pipe[0]);
+  network_make_pipe_nonblocking (coreAPI->ectx, signal_pipe[0]);
   http_running = YES;
   curl_thread = PTHREAD_CREATE (&curl_runner, NULL, 32 * 1024);
   if (curl_thread == NULL)

Modified: GNUnet/src/transports/test.c
===================================================================
--- GNUnet/src/transports/test.c        2007-09-08 23:52:46 UTC (rev 5613)
+++ GNUnet/src/transports/test.c        2007-09-09 00:01:31 UTC (rev 5614)
@@ -121,7 +121,7 @@
           if (OK != transport->connect (hello, &tsession, NO))
             {
               FREE (hello);
-             FREE (mp->msg);
+              FREE (mp->msg);
               FREE (mp);
               error_count++;
               return;

Modified: GNUnet/src/transports/test_repeat.c
===================================================================
--- GNUnet/src/transports/test_repeat.c 2007-09-08 23:52:46 UTC (rev 5613)
+++ GNUnet/src/transports/test_repeat.c 2007-09-09 00:01:31 UTC (rev 5614)
@@ -123,7 +123,7 @@
           if (OK != transport->connect (hello, &tsession, NO))
             {
               FREE (hello);
-             FREE (mp->msg);
+              FREE (mp->msg);
               FREE (mp);
               error_count++;
               return;
@@ -268,43 +268,51 @@
     }
   else
     {
-      for (xround=0;xround<XROUNDS;xround++) {
-       /* client - initiate requests */
-       hello = transport->createhello ();
-       /* HACK hello -- change port! */
-       ((unsigned short *) &hello[1])[2] =
-         htons (ntohs (((unsigned short *) &hello[1])[2]) + OFFSET);
-       if (OK != transport->connect (hello, &tsession, NO))
-         {
-           FREE (hello);
-           transport->stopTransportServer ();
-           os_plugin_unload (plugin);
-           goto cleanup;
-         }
-       FREE (hello);
-       pos = 0;
-       while (pos < ROUNDS)
-         {
-           if (OK == transport->send (tsession,
-                                      expectedValue,
-                                      expectedSize,
-                                      pos > ROUNDS / 2 ? YES : NO))
-             pos++;
-         }
-       pos = 0;
-       while ((pos++ < 100) && (msg_count < ROUNDS * (xround+1) )) 
-         PTHREAD_SLEEP (50 * cronMILLIS);      
-       if (msg_count < ROUNDS * (xround + 1))
-         {
-           if (NULL == strstr (argv[0], "udp"))
-            res = SYSERR;
-           else
-             fprintf (stderr,
-                      "WARNING: only %u/%u messages received (maybe ok, try 
again?)\n",
-                      msg_count, ROUNDS);
+      for (xround = 0; xround < XROUNDS; xround++)
+        {
+          fprintf (stderr, ".");
+          /* client - initiate requests */
+          hello = transport->createhello ();
+          /* HACK hello -- change port! */
+          ((unsigned short *) &hello[1])[2] =
+            htons (ntohs (((unsigned short *) &hello[1])[2]) + OFFSET);
+          if (OK != transport->connect (hello, &tsession, NO))
+            {
+              FREE (hello);
+              transport->stopTransportServer ();
+              os_plugin_unload (plugin);
+              goto cleanup;
+            }
+          FREE (hello);
+          pos = 0;
+          while (pos < ROUNDS)
+            {
+              if (OK == transport->send (tsession,
+                                         expectedValue,
+                                         expectedSize,
+                                         pos > ROUNDS / 2 ? YES : NO))
+                pos++;
+            }
+          pos = 0;
+          while ((pos++ < 100) && (msg_count < ROUNDS * (xround + 1)))
+            PTHREAD_SLEEP (50 * cronMILLIS);
+          if (msg_count < ROUNDS * (xround + 1))
+            {
+              if (NULL == strstr (argv[0], "udp"))
+                res = SYSERR;
+              else
+                fprintf (stderr,
+                         "WARNING: only %u/%u messages received (maybe ok, try 
again?)\n",
+                         msg_count, ROUNDS);
+            }
+          transport->disconnect (tsession);
+          if ((xround % 3) == 0)
+            {
+              transport->stopTransportServer ();
+              transport->startTransportServer ();
+            }
         }
-       transport->disconnect (tsession);
-      }
+      fprintf (stderr, "\n");
     }
 
   transport->stopTransportServer ();
@@ -329,7 +337,8 @@
     {
       fprintf (stderr,
                "Test failed (%u/%u %s)!\n",
-               msg_count, ROUNDS * XROUNDS, pid == 0 ? "messages" : "replies");
+               msg_count, ROUNDS * XROUNDS,
+               pid == 0 ? "messages" : "replies");
       return 2;
     }
   return 0;





reply via email to

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