*/
struct GNUNET_CLIENT_Connection *client;
+ /**
+ * Currently pending transmission request.
+ */
+ struct GNUNET_CLIENT_TransmitHandle *th;
+
/**
* Head of the linked list of pending actions (first action
* to be performed).
*/
struct ActionItem *current;
- /**
- * Should this handle be destroyed once we've processed
- * all actions?
- */
- int do_destroy;
};
/**
- * Actually free the handle.
+ * Destroy a handle (free all state associated with
+ * it).
*/
-static void
-do_destroy (struct GNUNET_STATISTICS_Handle *h)
+void
+GNUNET_STATISTICS_destroy (struct GNUNET_STATISTICS_Handle *h)
{
- GNUNET_assert (h->action_head == NULL);
- GNUNET_assert (h->current == NULL);
+ struct ActionItem *pos;
+ if (NULL != h->th)
+ {
+ GNUNET_CLIENT_notify_transmit_ready_cancel (h->th);
+ h->th = NULL;
+ }
+ if (h->current != NULL)
+ free_action_item (h->current);
+ while (NULL != (pos = h->action_head))
+ {
+ h->action_head = pos->next;
+ free_action_item (pos);
+ }
if (h->client != NULL)
{
GNUNET_CLIENT_disconnect (h->client);
}
-/**
- * Destroy a handle (free all state associated with
- * it).
- */
-void
-GNUNET_STATISTICS_destroy (struct GNUNET_STATISTICS_Handle *handle)
-{
- GNUNET_assert (handle->do_destroy == GNUNET_NO);
- if ((handle->action_head != NULL) || (handle->current != NULL))
- {
- handle->do_destroy = GNUNET_YES;
- return;
- }
- do_destroy (handle);
-}
-
-
/**
* Process the message.
*
if (msg == NULL)
{
- GNUNET_CLIENT_disconnect (h->client);
- h->client = NULL;
+ if (NULL != h->client)
+ {
+ GNUNET_CLIENT_disconnect (h->client);
+ h->client = NULL;
+ }
#if DEBUG_STATISTICS
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
"Error receiving statistics from service, is the service running?\n" );
GNUNET_break (0);
break;
}
- GNUNET_CLIENT_disconnect (h->client);
- h->client = NULL;
+ if (NULL != h->client)
+ {
+ GNUNET_CLIENT_disconnect (h->client);
+ h->client = NULL;
+ }
finish (h, GNUNET_SYSERR);
}
struct GNUNET_STATISTICS_Handle *handle = cls;
size_t ret;
+ handle->th = NULL;
switch (handle->current->type)
{
case ACTION_GET:
/* schedule next action */
h->current = h->action_head;
if (NULL == h->current)
- {
- /* no pending network action, check destroy! */
- if (h->do_destroy != GNUNET_YES)
- return;
- do_destroy (h);
- return;
- }
+ return;
h->action_head = h->action_head->next;
if (NULL == h->action_head)
h->action_tail = NULL;
h->current->next = NULL;
-
timeout = GNUNET_TIME_absolute_get_remaining (h->current->timeout);
if (NULL ==
- GNUNET_CLIENT_notify_transmit_ready (h->client,
- h->current->msize,
- timeout,
- GNUNET_YES,
- &transmit_action, h))
+ (h->th = GNUNET_CLIENT_notify_transmit_ready (h->client,
+ h->current->msize,
+ timeout,
+ GNUNET_YES,
+ &transmit_action, h)))
{
#if DEBUG_STATISTICS
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,