-do not crash on exit if we are not connected to statistics while trying to submit...
authorChristian Grothoff <christian@grothoff.org>
Mon, 19 Dec 2011 20:48:41 +0000 (20:48 +0000)
committerChristian Grothoff <christian@grothoff.org>
Mon, 19 Dec 2011 20:48:41 +0000 (20:48 +0000)
src/statistics/statistics_api.c

index ca435a3713dbe965b3fcc9a7e1aab449e6b79209..f4f91538a1509df6964fc0b7def7c496b3b98be0 100644 (file)
@@ -904,12 +904,25 @@ GNUNET_STATISTICS_destroy (struct GNUNET_STATISTICS_Handle *h, int sync_first)
     h->do_destroy = GNUNET_YES;
     if ((h->current != NULL) && (h->th == NULL))
     {
-      timeout = GNUNET_TIME_absolute_get_remaining (h->current->timeout);
-      h->th =
+      if (NULL == h->client)
+      {
+       /* instant-connect (regardless of back-off) to submit final value */
+       if (GNUNET_SCHEDULER_NO_TASK != h->backoff_task)
+       {
+         GNUNET_SCHEDULER_cancel (h->backoff_task);
+         h->backoff_task = GNUNET_SCHEDULER_NO_TASK;
+       }
+       h->client = GNUNET_CLIENT_connect ("statistics", h->cfg);
+      }
+      if (NULL != h->client)
+      {
+       timeout = GNUNET_TIME_absolute_get_remaining (h->current->timeout);
+       h->th =
           GNUNET_CLIENT_notify_transmit_ready (h->client, h->current->msize,
                                                timeout, GNUNET_YES,
                                                &transmit_action, h);
-      GNUNET_assert (NULL != h->th);
+       GNUNET_assert (NULL != h->th);
+      }
     }
     if (h->th != NULL)
       return;