adding configure code for --enable-benchmarks, --enable-expensive-tests, some clean up
[oweals/gnunet.git] / src / datastore / datastore_api.c
index 65c14f67336c7e354028264e6464defaeaa33042..a3196530eab54a1f65c0dc9bf65e8370b7719f7f 100644 (file)
@@ -315,6 +315,11 @@ GNUNET_DATASTORE_disconnect (struct GNUNET_DATASTORE_Handle *h,
 {
   struct GNUNET_DATASTORE_QueueEntry *qe;
 
+  if (NULL != h->th)
+    {
+      GNUNET_CLIENT_notify_transmit_ready_cancel (h->th);
+      h->th = NULL;
+    }
   if (h->client != NULL)
     {
       GNUNET_CLIENT_disconnect (h->client, GNUNET_NO);
@@ -325,11 +330,6 @@ GNUNET_DATASTORE_disconnect (struct GNUNET_DATASTORE_Handle *h,
       GNUNET_SCHEDULER_cancel (h->reconnect_task);
       h->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
     }
-  if (NULL != h->th)
-    {
-      GNUNET_CLIENT_notify_transmit_ready_cancel (h->th);
-      h->th = NULL;
-    }
   while (NULL != (qe = h->queue_head))
     {
       GNUNET_assert (NULL != qe->response_proc);
@@ -377,7 +377,7 @@ timeout_queue_entry (void *cls,
                            1,
                            GNUNET_NO);
   qe->task = GNUNET_SCHEDULER_NO_TASK;
-  GNUNET_assert (qe->was_transmitted == GNUNET_NO);
+  GNUNET_assert (qe->was_transmitted == GNUNET_NO); 
   qe->response_proc (qe->h, NULL);
 }
 
@@ -570,6 +570,37 @@ do_disconnect (struct GNUNET_DATASTORE_Handle *h)
 }
 
 
+/**
+ * Function called whenever we receive a message from
+ * the service.  Calls the appropriate handler.
+ *
+ * @param cls the 'struct GNUNET_DATASTORE_Handle'
+ * @param msg the received message
+ */
+static void 
+receive_cb (void *cls,
+           const struct GNUNET_MessageHeader *msg)
+{
+  struct GNUNET_DATASTORE_Handle *h = cls;
+  struct GNUNET_DATASTORE_QueueEntry *qe;
+
+  h->in_receive = GNUNET_NO;
+  if (h->skip_next_messages > 0)
+    {
+      h->skip_next_messages--;
+      process_queue (h);
+      return;
+   } 
+  if (NULL == (qe = h->queue_head))
+    {
+      GNUNET_break (0);
+      process_queue (h);
+      return; 
+    }
+  qe->response_proc (h, msg);
+}
+
+
 /**
  * Transmit request from queue to datastore service.
  *
@@ -618,7 +649,7 @@ transmit_request (void *cls,
   GNUNET_assert (GNUNET_NO == h->in_receive);
   h->in_receive = GNUNET_YES;
   GNUNET_CLIENT_receive (h->client,
-                        qe->response_proc,
+                        &receive_cb,
                         h,
                         GNUNET_TIME_absolute_get_remaining (qe->timeout));
   GNUNET_STATISTICS_update (h->stats,
@@ -753,13 +784,6 @@ process_status_message (void *cls,
   int32_t status;
   int was_transmitted;
 
-  h->in_receive = GNUNET_NO;
-  if (h->skip_next_messages > 0)
-    {
-      h->skip_next_messages--;
-      process_queue (h);
-      return;
-   } 
   if (NULL == (qe = h->queue_head))
     {
       GNUNET_break (0);
@@ -1228,13 +1252,6 @@ process_result_message (void *cls,
   struct ResultContext rc;
   const struct DataMessage *dm;
 
-  h->in_receive = GNUNET_NO;
-  if (h->skip_next_messages > 0)
-    {
-      h->skip_next_messages--;
-      process_queue (h);
-      return;
-    }
   if (msg == NULL)
     {
       qe = h->queue_head;