-indentation
[oweals/gnunet.git] / src / testbed / gnunet-service-testbed_connectionpool.c
index 158c9ec3a21c8705df954d041d0c29b12f11c37d..6d9a279727f2e818f3bee11fc707db542085d567 100644 (file)
@@ -286,6 +286,11 @@ destroy_pooled_connection (struct PooledConnection *entry)
                    GNUNET_CONTAINER_multihashmap32_remove (map,
                                                            entry->index,
                                                            entry));
+  if (GNUNET_SCHEDULER_NO_TASK != entry->notify_task)
+  {
+    GNUNET_SCHEDULER_cancel (entry->notify_task);
+    entry->notify_task = GNUNET_SCHEDULER_NO_TASK;
+  }
   LOG_DEBUG ("Cleaning up handles of a pooled connection\n");
   if (NULL != entry->handle_transport)
     GNUNET_assert (NULL != entry->op_transport);
@@ -435,7 +440,7 @@ connection_ready (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 
 /**
  * Function called from peer connect notify callbacks from CORE and TRANSPORT
- * connections. This function calls the pendning peer connect notify callbacks
+ * connections. This function calls the pending peer connect notify callbacks
  * which are queued in an entry.
  *
  * @param cls the #PooledConnection object
@@ -729,7 +734,7 @@ GST_connection_pool_destroy ()
  *
  * @note @a connect_notify_cb will not be called if @a target is
  * already connected @a service level. Use
- * GNUNET_TRANSPORT_check_neighbour_connected() or a similar function from the
+ * GNUNET_TRANSPORT_check_peer_connected() or a similar function from the
  * respective @a service's API to check if the target peer is already connected or
  * not. @a connect_notify_cb will be called only once or never (in case @a target
  * cannot be connected or is already connected).
@@ -880,16 +885,26 @@ GST_connection_pool_get_handle_done (struct GST_ConnectionPool_GetHandle *gh)
              gh,
              gh->service, entry->index);
   if (!gh->connection_ready_called)
+  {
     GNUNET_CONTAINER_DLL_remove (entry->head_waiting, entry->tail_waiting, gh);
+    if ( (NULL == search_waiting (entry, entry->head_waiting))
+         && (GNUNET_SCHEDULER_NO_TASK != entry->notify_task) )
+    {
+      GNUNET_SCHEDULER_cancel (entry->notify_task);
+      entry->notify_task = GNUNET_SCHEDULER_NO_TASK;
+    }
+  }
   if (gh->notify_waiting)
-  { 
+  {
     GNUNET_CONTAINER_DLL_remove (entry->head_notify, entry->tail_notify, gh);
     gh->notify_waiting = 0;
   }
   GNUNET_free (gh);
   gh = NULL;
   GNUNET_assert (!entry->in_lru);
-  if ( (!entry->in_pool) && (NULL != map) )
+  if (!entry->in_pool)
+    GNUNET_CONTAINER_DLL_remove (head_not_pooled, tail_not_pooled, entry);
+  if (NULL != map)
   {
     if (GNUNET_YES == GNUNET_CONTAINER_multihashmap32_contains (map,
                                                                 entry->index))
@@ -900,7 +915,6 @@ GST_connection_pool_get_handle_done (struct GST_ConnectionPool_GetHandle *gh)
         goto unallocate;
       destroy_pooled_connection (head_lru);
     }
-    GNUNET_CONTAINER_DLL_remove (head_not_pooled, tail_not_pooled, entry);
     GNUNET_assert (GNUNET_OK ==
                    GNUNET_CONTAINER_multihashmap32_put (map,
                                                         entry->index,
@@ -908,6 +922,7 @@ GST_connection_pool_get_handle_done (struct GST_ConnectionPool_GetHandle *gh)
                                                         GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
     entry->in_pool = GNUNET_YES;
   }
+
  unallocate:
   GNUNET_assert (0 < entry->demand);
   entry->demand--;