gnunet-svn
[Top][All Lists]
Advanced

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

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


From: gnunet
Subject: [GNUnet-SVN] r5245 - GNUnet/src/util/network
Date: Thu, 5 Jul 2007 00:10:56 -0600 (MDT)

Author: grothoff
Date: 2007-07-05 00:10:55 -0600 (Thu, 05 Jul 2007)
New Revision: 5245

Modified:
   GNUnet/src/util/network/select.c
Log:
cleanup

Modified: GNUnet/src/util/network/select.c
===================================================================
--- GNUnet/src/util/network/select.c    2007-07-05 06:08:09 UTC (rev 5244)
+++ GNUnet/src/util/network/select.c    2007-07-05 06:10:55 UTC (rev 5245)
@@ -1054,50 +1054,7 @@
   return OK;
 }
 
-/**
- * Would select queue or send the given message at this time?
- *
- * @param mayBlock if YES, blocks this thread until message
- *        has been sent
- * @param size size of the message
- * @param force message is important, queue even if
- *        there is not enough space
- * @return OK if the message would be sent or queued,
- *         NO if there was not enough memory to queue it,
- *         SYSERR if the sock does not belong with this select
- */
-int select_would_try(struct SelectHandle * sh,
-                    struct SocketHandle * sock,
-                    unsigned int size,
-                    int mayBlock,
-                    int force) {
-  Session * session;
-  int i;
 
-  session = NULL;
-  MUTEX_LOCK(sh->lock);
-  for (i=0;i<sh->sessionCount;i++)
-    if (sh->sessions[i]->sock == sock) {
-      session = sh->sessions[i];
-      break;
-    }
-  if (session == NULL) {
-    MUTEX_UNLOCK(sh->lock);
-    return SYSERR;
-  }
-  GE_ASSERT(NULL, session->wapos >= session->wspos);
-  if ( (sh->memory_quota > 0) &&
-       (session->wapos - session->wspos + size > sh->memory_quota) &&
-       (force == NO) ) {
-    /* not enough free space, not allowed to grow that much */
-    MUTEX_UNLOCK(sh->lock);
-    return NO;
-  }
-  MUTEX_UNLOCK(sh->lock);
-  return YES;
-}
-
-
 /**
  */
 int select_update_closure(struct SelectHandle * sh,
@@ -1158,6 +1115,17 @@
   return OK;
 }
 
+static Session * findSession(struct SelectHandle * sh,
+                            struct SocketHandle * sock) {
+  int i;
+
+  session = NULL;
+  for (i=0;i<sh->sessionCount;i++)
+    if (sh->sessions[i]->sock == sock) 
+      return sh->sessions[i];
+  return NULL;
+}
+
 /**
  * Close the associated socket and remove it from the
  * set of sockets managed by select.
@@ -1165,7 +1133,6 @@
 int select_disconnect(struct SelectHandle * sh,
                      struct SocketHandle * sock) {
   Session * session;
-  int i;
 
 #if DEBUG_SELECT
   GE_LOG(sh->ectx,
@@ -1174,13 +1141,9 @@
         sock,
         sh);   
 #endif
-  session = NULL;
   MUTEX_LOCK(sh->lock);
-  for (i=0;i<sh->sessionCount;i++)
-    if (sh->sessions[i]->sock == sock) {
-      session = sh->sessions[i];
-      break;
-    }
+  session = findSession(sh,
+                       sock);
   if (session == NULL) {
     MUTEX_UNLOCK(sh->lock);
     return SYSERR;
@@ -1200,15 +1163,10 @@
                          struct SocketHandle * sock,
                          cron_t timeout) {
   Session * session;
-  int i;
-  
-  session = NULL;
+
   MUTEX_LOCK(sh->lock);
-  for (i=0;i<sh->sessionCount;i++)
-    if (sh->sessions[i]->sock == sock) {
-      session = sh->sessions[i];
-      break;
-    }
+  session = findSession(sh,
+                       sock);
   if (session == NULL) {
     MUTEX_UNLOCK(sh->lock);
     return SYSERR;
@@ -1217,3 +1175,43 @@
   MUTEX_UNLOCK(sh->lock);
   return OK;
 }
+
+
+/**
+ * Would select queue or send the given message at this time?
+ *
+ * @param mayBlock if YES, blocks this thread until message
+ *        has been sent
+ * @param size size of the message
+ * @param force message is important, queue even if
+ *        there is not enough space
+ * @return OK if the message would be sent or queued,
+ *         NO if there was not enough memory to queue it,
+ *         SYSERR if the sock does not belong with this select
+ */
+int select_would_try(struct SelectHandle * sh,
+                    struct SocketHandle * sock,
+                    unsigned int size,
+                    int mayBlock,
+                    int force) {
+  Session * session;
+
+  MUTEX_LOCK(sh->lock);
+  session = findSession(sh,
+                       sock);
+  if (session == NULL) {
+    MUTEX_UNLOCK(sh->lock);
+    return SYSERR;
+  }
+  GE_ASSERT(NULL,
+           session->wapos >= session->wspos);
+  if ( (sh->memory_quota > 0) &&
+       (session->wapos - session->wspos + size > sh->memory_quota) &&
+       (force == NO) ) {
+    /* not enough free space, not allowed to grow that much */
+    MUTEX_UNLOCK(sh->lock);
+    return NO;
+  }
+  MUTEX_UNLOCK(sh->lock);
+  return YES;
+}





reply via email to

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