+ if (NULL != h->th)
+ return; /* do not finish destruction just yet */
+ }
+ while (NULL != (pos = h->action_head))
+ {
+ GNUNET_CONTAINER_DLL_remove (h->action_head,
+ h->action_tail,
+ pos);
+ free_action_item (pos);
+ }
+ do_disconnect (h);
+ for (i = 0; i < h->watches_size; i++)
+ {
+ if (NULL == h->watches[i])
+ continue;
+ GNUNET_free (h->watches[i]->subsystem);
+ GNUNET_free (h->watches[i]->name);
+ GNUNET_free (h->watches[i]);
+ }
+ GNUNET_array_grow (h->watches, h->watches_size, 0);
+ GNUNET_free (h->subsystem);
+ GNUNET_free (h);
+}
+
+
+/**
+ * Function called to transmit TEST message to service to
+ * confirm that the service has received all of our 'SET'
+ * messages (during statistics disconnect/shutdown).
+ *
+ * @param cls the 'struct GNUNET_STATISTICS_Handle'
+ * @param size how many bytes can we write to buf
+ * @param buf where to write requests to the service
+ * @return number of bytes written to buf
+ */
+static size_t
+transmit_test_on_shutdown (void *cls,
+ size_t size,
+ void *buf)
+{
+ struct GNUNET_STATISTICS_Handle *h = cls;
+ struct GNUNET_MessageHeader hdr;
+
+ h->th = NULL;
+ if (NULL == buf)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("Failed to receive acknowledgement from statistics service, some statistics might have been lost!\n"));
+ h->do_destroy = GNUNET_NO;
+ GNUNET_SCHEDULER_add_continuation (&destroy_task, h,
+ GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ return 0;
+ }
+ hdr.type = htons (GNUNET_MESSAGE_TYPE_TEST);
+ hdr.size = htons (sizeof (struct GNUNET_MessageHeader));
+ memcpy (buf, &hdr, sizeof (hdr));
+ if (GNUNET_YES != h->receiving)
+ {
+ h->receiving = GNUNET_YES;
+ GNUNET_CLIENT_receive (h->client, &receive_stats, h,
+ GNUNET_TIME_UNIT_FOREVER_REL);
+ }
+ return sizeof (struct GNUNET_MessageHeader);