From f9e8f6651beac8e654a03fe5092c92076c52dc78 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Tue, 31 May 2011 00:15:15 +0000 Subject: [PATCH] nicer --- src/datastore/datastore_api.c | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/src/datastore/datastore_api.c b/src/datastore/datastore_api.c index 6bf9abaca..624d0cad7 100644 --- a/src/datastore/datastore_api.c +++ b/src/datastore/datastore_api.c @@ -371,7 +371,6 @@ timeout_queue_entry (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { struct GNUNET_DATASTORE_QueueEntry *qe = cls; - int in_receive; GNUNET_STATISTICS_update (qe->h->stats, gettext_noop ("# queue entry timeouts"), @@ -379,9 +378,7 @@ timeout_queue_entry (void *cls, GNUNET_NO); qe->task = GNUNET_SCHEDULER_NO_TASK; GNUNET_assert (qe->was_transmitted == GNUNET_NO); - in_receive = qe->h->in_receive; qe->response_proc (qe->h, NULL); - qe->h->in_receive = in_receive; } @@ -411,7 +408,6 @@ make_queue_entry (struct GNUNET_DATASTORE_Handle *h, struct GNUNET_DATASTORE_QueueEntry *ret; struct GNUNET_DATASTORE_QueueEntry *pos; unsigned int c; - int in_receive; c = 0; pos = h->queue_head; @@ -466,7 +462,6 @@ make_queue_entry (struct GNUNET_DATASTORE_Handle *h, ret->task = GNUNET_SCHEDULER_add_delayed (timeout, &timeout_queue_entry, ret); - in_receive = h->in_receive; pos = ret->next; while (pos != NULL) { @@ -491,7 +486,6 @@ make_queue_entry (struct GNUNET_DATASTORE_Handle *h, } pos = pos->next; } - h->in_receive = in_receive; return ret; } @@ -576,6 +570,31 @@ 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 (NULL == (qe = h->queue_head)) + { + GNUNET_break (0); + process_queue (h); + return; + } + qe->response_proc (h, msg); +} + + /** * Transmit request from queue to datastore service. * @@ -624,7 +643,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, @@ -759,7 +778,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--; @@ -1234,7 +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--; -- 2.25.1