gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r6241 - GNUnet/src/util/network


From: gnunet
Subject: [GNUnet-SVN] r6241 - GNUnet/src/util/network
Date: Sun, 10 Feb 2008 22:34:09 -0700 (MST)

Author: grothoff
Date: 2008-02-10 22:34:09 -0700 (Sun, 10 Feb 2008)
New Revision: 6241

Modified:
   GNUnet/src/util/network/select.c
Log:
fixing handling of timeouts


Modified: GNUnet/src/util/network/select.c
===================================================================
--- GNUnet/src/util/network/select.c    2008-02-11 05:02:34 UTC (rev 6240)
+++ GNUnet/src/util/network/select.c    2008-02-11 05:34:09 UTC (rev 6241)
@@ -433,6 +433,8 @@
 selectThread (void *ctx)
 {
   struct GNUNET_SelectHandle *sh = ctx;
+  GNUNET_CronTime now;
+  GNUNET_CronTime timeout;
   char *clientAddr;
   fd_set readSet;
   fd_set errorSet;
@@ -448,6 +450,7 @@
   Session *session;
   size_t size;
   int old_errno;
+  struct timeval tv;
 
   if (sh->max_addr_len != 0)
     clientAddr = GNUNET_malloc (sh->max_addr_len);
@@ -518,8 +521,23 @@
                 add_to_select_set (sock, &writeSet, &max);      /* do we have 
a pending write request? */
             }
         }
+      timeout = -1;
+      now = GNUNET_get_time();
+      for (i = 0; i < sh->sessionCount; i++)
+        {
+          session = sh->sessions[i];
+         if (session->timeout != 0) 
+           {
+             if (now > session->lastUse + session->timeout)
+               timeout = 0;
+             else
+               timeout = MIN(timeout, session->lastUse + session->timeout - 
now);
+            }
+        }
       GNUNET_mutex_unlock (sh->lock);
-      ret = SELECT (max + 1, &readSet, &writeSet, &errorSet, NULL);
+      tv.tv_sec = timeout / GNUNET_CRON_SECONDS;
+      tv.tv_usec = (timeout % GNUNET_CRON_SECONDS) * 1000 * 1000;
+      ret = SELECT (max + 1, &readSet, &writeSet, &errorSet, (timeout == -1) ? 
NULL : &tv);
       old_errno = errno;
       GNUNET_mutex_lock (sh->lock);
       if ((ret == -1) && ((old_errno == EAGAIN) || (old_errno == EINTR)))
@@ -607,6 +625,7 @@
                 {
                   session = GNUNET_malloc (sizeof (Session));
                   memset (session, 0, sizeof (Session));
+                 session->timeout = sh->timeout;
                   session->sock = sock;
                   session->sock_ctx = sctx;
                   session->lastUse = GNUNET_get_time ();
@@ -762,6 +781,7 @@
                                       GNUNET_GE_BULK, "read");
             }
         }
+      now = GNUNET_get_time();
       for (i = 0; i < sh->sessionCount; i++)
         {
           session = sh->sessions[i];
@@ -784,10 +804,8 @@
               i--;
               continue;
             }
-          if (((sh->timeout != 0) &&
-               (GNUNET_get_time () > session->lastUse + sh->timeout)) ||
-              ((session->timeout != 0) &&
-               (GNUNET_get_time () > session->lastUse + session->timeout)))
+          if ( (session->timeout != 0) &&
+               (now > session->lastUse + session->timeout) )
             {
               destroySession (sh, session);
               i--;





reply via email to

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