aboutsummaryrefslogtreecommitdiff
path: root/src/statistics
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-05-03 14:03:39 +0000
committerChristian Grothoff <christian@grothoff.org>2012-05-03 14:03:39 +0000
commit6fd4d6dd8212e296066bb4b1008832b78596c34b (patch)
tree62126be7812db6c0a1c8a86fce302f5cc114b719 /src/statistics
parent802700f9006acaab256e4222d99c307b8e49aa86 (diff)
downloadgnunet-6fd4d6dd8212e296066bb4b1008832b78596c34b.tar.gz
gnunet-6fd4d6dd8212e296066bb4b1008832b78596c34b.zip
-fixing #2299
Diffstat (limited to 'src/statistics')
-rw-r--r--src/statistics/statistics_api.c64
1 files changed, 57 insertions, 7 deletions
diff --git a/src/statistics/statistics_api.c b/src/statistics/statistics_api.c
index 98316bafd..6ce10421a 100644
--- a/src/statistics/statistics_api.c
+++ b/src/statistics/statistics_api.c
@@ -559,6 +559,16 @@ process_watch_value (struct GNUNET_STATISTICS_Handle *h,
559} 559}
560 560
561 561
562static void
563destroy_task (void *cls,
564 const struct GNUNET_SCHEDULER_TaskContext *tc)
565{
566 struct GNUNET_STATISTICS_Handle *h = cls;
567
568 GNUNET_STATISTICS_destroy (h, GNUNET_YES);
569}
570
571
562/** 572/**
563 * Function called with messages from stats service. 573 * Function called with messages from stats service.
564 * 574 *
@@ -582,6 +592,19 @@ receive_stats (void *cls, const struct GNUNET_MessageHeader *msg)
582 } 592 }
583 switch (ntohs (msg->type)) 593 switch (ntohs (msg->type))
584 { 594 {
595 case GNUNET_MESSAGE_TYPE_TEST:
596 if (GNUNET_SYSERR != h->do_destroy)
597 {
598 /* not in shutdown, why do we get 'TEST'? */
599 GNUNET_break (0);
600 do_disconnect (h);
601 reconnect_later (h);
602 return;
603 }
604 h->do_destroy = GNUNET_NO;
605 GNUNET_SCHEDULER_add_continuation (&destroy_task, h,
606 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
607 break;
585 case GNUNET_MESSAGE_TYPE_STATISTICS_END: 608 case GNUNET_MESSAGE_TYPE_STATISTICS_END:
586 LOG (GNUNET_ERROR_TYPE_DEBUG, "Received end of statistics marker\n"); 609 LOG (GNUNET_ERROR_TYPE_DEBUG, "Received end of statistics marker\n");
587 if (NULL == (c = h->current)) 610 if (NULL == (c = h->current))
@@ -951,13 +974,37 @@ GNUNET_STATISTICS_destroy (struct GNUNET_STATISTICS_Handle *h, int sync_first)
951} 974}
952 975
953 976
954static void 977/**
955destroy_task (void *cls, 978 * Function called to transmit TEST message to service to
956 const struct GNUNET_SCHEDULER_TaskContext *tc) 979 * confirm that the service has received all of our 'SET'
980 * messages (during statistics disconnect/shutdown).
981 *
982 * @param cls the 'struct GNUNET_STATISTICS_Handle'
983 * @param size how many bytes can we write to buf
984 * @param buf where to write requests to the service
985 * @return number of bytes written to buf
986 */
987static size_t
988transmit_test_on_shutdown (void *cls,
989 size_t size,
990 void *buf)
957{ 991{
958 struct GNUNET_STATISTICS_Handle *h = cls; 992 struct GNUNET_STATISTICS_Handle *h = cls;
993 struct GNUNET_MessageHeader hdr;
959 994
960 GNUNET_STATISTICS_destroy (h, GNUNET_YES); 995 if (NULL == buf)
996 {
997 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
998 _("Failed to receive acknowledgement from statistics service, some statistics might have been lost!\n"));
999 h->do_destroy = GNUNET_NO;
1000 GNUNET_SCHEDULER_add_continuation (&destroy_task, h,
1001 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
1002 return 0;
1003 }
1004 hdr.type = htons (GNUNET_MESSAGE_TYPE_TEST);
1005 hdr.size = htons (sizeof (struct GNUNET_MessageHeader));
1006 memcpy (buf, &hdr, sizeof (hdr));
1007 return sizeof (struct GNUNET_MessageHeader);
961} 1008}
962 1009
963 1010
@@ -987,9 +1034,12 @@ schedule_action (struct GNUNET_STATISTICS_Handle *h)
987 { 1034 {
988 if (h->do_destroy) 1035 if (h->do_destroy)
989 { 1036 {
990 h->do_destroy = GNUNET_NO; 1037 h->do_destroy = GNUNET_SYSERR; /* in 'TEST' mode */
991 GNUNET_SCHEDULER_add_continuation (&destroy_task, h, 1038 h->th = GNUNET_CLIENT_notify_transmit_ready (h->client,
992 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 1039 sizeof (struct GNUNET_MessageHeader),
1040 SET_TRANSMIT_TIMEOUT,
1041 GNUNET_NO,
1042 &transmit_test_on_shutdown, h);
993 } 1043 }
994 return; 1044 return;
995 } 1045 }