X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=src%2Fstatistics%2Fstatistics_api.c;h=04e85a07e95323b65d2026990c05d66c836e306b;hb=e0ca7357cd0bfedc5c29cb731b56279fef8da059;hp=7bdd6a5c602f9696bf0b0eb70a5a8eaa3b326bb3;hpb=5edb234d215611914d8e9e9953fe4f0a4439c383;p=oweals%2Fgnunet.git diff --git a/src/statistics/statistics_api.c b/src/statistics/statistics_api.c index 7bdd6a5c6..04e85a07e 100644 --- a/src/statistics/statistics_api.c +++ b/src/statistics/statistics_api.c @@ -4,7 +4,7 @@ GNUnet is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 2, or (at your + by the Free Software Foundation; either version 3, or (at your option) any later version. GNUnet is distributed in the hope that it will be useful, but @@ -24,13 +24,10 @@ * @author Christian Grothoff */ #include "platform.h" -#include "gnunet_client_lib.h" +#include "gnunet_util_lib.h" #include "gnunet_constants.h" -#include "gnunet_container_lib.h" #include "gnunet_protocols.h" -#include "gnunet_server_lib.h" #include "gnunet_statistics_service.h" -#include "gnunet_strings_lib.h" #include "statistics.h" /** @@ -280,11 +277,11 @@ update_memory_statistics (struct GNUNET_STATISTICS_Handle *h) #if HAVE_MALLINFO { struct mallinfo mi; - + mi = mallinfo(); - current_heap_size = mi.uordblks + mi.fordblks; + current_heap_size = mi.uordblks + mi.fordblks; } -#endif +#endif #if HAVE_GETRUSAGE { struct rusage ru; @@ -292,7 +289,7 @@ update_memory_statistics (struct GNUNET_STATISTICS_Handle *h) if (0 == getrusage (RUSAGE_SELF, &ru)) { current_rss = 1024LL * ru.ru_maxrss; - } + } } #endif if (current_heap_size > h->peak_heap_size) @@ -346,7 +343,7 @@ schedule_watch_request (struct GNUNET_STATISTICS_Handle *h, GNUNET_break (0); return; } - ai = GNUNET_malloc (sizeof (struct GNUNET_STATISTICS_GetHandle)); + ai = GNUNET_new (struct GNUNET_STATISTICS_GetHandle); ai->sh = h; ai->subsystem = GNUNET_strdup (watch->subsystem); ai->name = GNUNET_strdup (watch->name); @@ -384,25 +381,26 @@ static void do_disconnect (struct GNUNET_STATISTICS_Handle *h) { struct GNUNET_STATISTICS_GetHandle *c; - + if (NULL != h->th) { GNUNET_CLIENT_notify_transmit_ready_cancel (h->th); h->th = NULL; - } - if (NULL != h->client) - { - GNUNET_CLIENT_disconnect (h->client); - h->client = NULL; } h->receiving = GNUNET_NO; if (NULL != (c = h->current)) { h->current = NULL; - if (NULL != c->cont) + if ( (NULL != c->cont) && + (GNUNET_YES != c->aborted) ) c->cont (c->cls, GNUNET_SYSERR); free_action_item (c); } + if (NULL != h->client) + { + GNUNET_CLIENT_disconnect (h->client); + h->client = NULL; + } } @@ -410,7 +408,7 @@ do_disconnect (struct GNUNET_STATISTICS_Handle *h) * Try to (re)connect to the statistics service. * * @param h statistics handle to reconnect - * @return GNUNET_YES on success, GNUNET_NO on failure. + * @return #GNUNET_YES on success, #GNUNET_NO on failure. */ static int try_connect (struct GNUNET_STATISTICS_Handle *h) @@ -423,10 +421,10 @@ try_connect (struct GNUNET_STATISTICS_Handle *h) return GNUNET_NO; if (NULL != h->client) return GNUNET_YES; - h->client = GNUNET_CLIENT_connect ("statistics", h->cfg); + h->client = GNUNET_CLIENT_connect ("statistics", h->cfg); if (NULL != h->client) { - gn = h->action_head; + gn = h->action_head; while (NULL != (gh = gn)) { gn = gh->next; @@ -435,7 +433,7 @@ try_connect (struct GNUNET_STATISTICS_Handle *h) GNUNET_CONTAINER_DLL_remove (h->action_head, h->action_tail, gh); - free_action_item (gh); + free_action_item (gh); } } for (i = 0; i < h->watches_size; i++) @@ -603,8 +601,8 @@ process_watch_value (struct GNUNET_STATISTICS_Handle *h, return GNUNET_SYSERR; } w = h->watches[wid]; - if (NULL == w) - return GNUNET_NO; + if (NULL == w) + return GNUNET_NO; (void) w->proc (w->proc_cls, w->subsystem, w->name, GNUNET_ntohll (wvm->value), 0 != (ntohl (wvm->flags) & GNUNET_STATISTICS_PERSIST_BIT)); @@ -676,7 +674,7 @@ receive_stats (void *cls, const struct GNUNET_MessageHeader *msg) else { h->receiving = GNUNET_NO; - } + } h->current = NULL; schedule_action (h); if (NULL != c->cont) @@ -688,7 +686,7 @@ receive_stats (void *cls, const struct GNUNET_MessageHeader *msg) { do_disconnect (h); reconnect_later (h); - return; + return; } /* finally, look for more! */ LOG (GNUNET_ERROR_TYPE_DEBUG, @@ -699,12 +697,12 @@ receive_stats (void *cls, const struct GNUNET_MessageHeader *msg) h->backoff = GNUNET_TIME_UNIT_MILLISECONDS; return; case GNUNET_MESSAGE_TYPE_STATISTICS_WATCH_VALUE: - if (GNUNET_OK != + if (GNUNET_OK != (ret = process_watch_value (h, msg))) { do_disconnect (h); if (GNUNET_NO == ret) - h->backoff = GNUNET_TIME_UNIT_MILLISECONDS; + h->backoff = GNUNET_TIME_UNIT_MILLISECONDS; reconnect_later (h); return; } @@ -712,7 +710,7 @@ receive_stats (void *cls, const struct GNUNET_MessageHeader *msg) GNUNET_assert (h->watches_size > 0); GNUNET_CLIENT_receive (h->client, &receive_stats, h, GNUNET_TIME_UNIT_FOREVER_REL); - return; + return; default: GNUNET_break (0); do_disconnect (h); @@ -934,7 +932,7 @@ GNUNET_STATISTICS_create (const char *subsystem, return NULL; GNUNET_assert (NULL != subsystem); GNUNET_assert (NULL != cfg); - ret = GNUNET_malloc (sizeof (struct GNUNET_STATISTICS_Handle)); + ret = GNUNET_new (struct GNUNET_STATISTICS_Handle); ret->cfg = cfg; ret->subsystem = GNUNET_strdup (subsystem); ret->backoff = GNUNET_TIME_UNIT_MILLISECONDS; @@ -978,7 +976,7 @@ GNUNET_STATISTICS_destroy (struct GNUNET_STATISTICS_Handle *h, int sync_first) h->current = NULL; } } - next = h->action_head; + next = h->action_head; while (NULL != (pos = next)) { next = pos->next; @@ -1020,7 +1018,7 @@ GNUNET_STATISTICS_destroy (struct GNUNET_STATISTICS_Handle *h, int sync_first) for (i = 0; i < h->watches_size; i++) { if (NULL == h->watches[i]) - continue; + continue; GNUNET_free (h->watches[i]->subsystem); GNUNET_free (h->watches[i]->name); GNUNET_free (h->watches[i]); @@ -1160,7 +1158,7 @@ GNUNET_STATISTICS_get (struct GNUNET_STATISTICS_Handle *handle, slen2 = strlen (name) + 1; GNUNET_assert (slen1 + slen2 + sizeof (struct GNUNET_MessageHeader) < GNUNET_SERVER_MAX_MESSAGE_SIZE); - ai = GNUNET_malloc (sizeof (struct GNUNET_STATISTICS_GetHandle)); + ai = GNUNET_new (struct GNUNET_STATISTICS_GetHandle); ai->sh = handle; ai->subsystem = GNUNET_strdup (subsystem); ai->name = GNUNET_strdup (name); @@ -1188,6 +1186,7 @@ GNUNET_STATISTICS_get_cancel (struct GNUNET_STATISTICS_GetHandle *gh) { if (NULL == gh) return; + gh->cont = NULL; if (gh->sh->current == gh) { gh->aborted = GNUNET_YES; @@ -1221,7 +1220,7 @@ GNUNET_STATISTICS_watch (struct GNUNET_STATISTICS_Handle *handle, if (NULL == handle) return GNUNET_SYSERR; - w = GNUNET_malloc (sizeof (struct GNUNET_STATISTICS_WatchEntry)); + w = GNUNET_new (struct GNUNET_STATISTICS_WatchEntry); w->subsystem = GNUNET_strdup (subsystem); w->name = GNUNET_strdup (name); w->proc = proc; @@ -1233,7 +1232,7 @@ GNUNET_STATISTICS_watch (struct GNUNET_STATISTICS_Handle *handle, /** - * Stop watching statistics from the peer. + * Stop watching statistics from the peer. * * @param handle identification of the statistics service * @param subsystem limit to the specified subsystem, never NULL @@ -1265,9 +1264,9 @@ GNUNET_STATISTICS_watch_cancel (struct GNUNET_STATISTICS_Handle *handle, GNUNET_free (w->name); GNUNET_free (w->subsystem); GNUNET_free (w); - handle->watches[i] = NULL; + handle->watches[i] = NULL; return GNUNET_OK; - } + } } return GNUNET_SYSERR; } @@ -1306,7 +1305,7 @@ add_setter_action (struct GNUNET_STATISTICS_Handle *h, const char *name, for (ai = h->action_head; NULL != ai; ai = ai->next) { if (! ( (0 == strcmp (ai->subsystem, h->subsystem)) && - (0 == strcmp (ai->name, name)) && + (0 == strcmp (ai->name, name)) && ( (ACTION_UPDATE == ai->type) || (ACTION_SET == ai->type) ) ) ) continue; @@ -1352,10 +1351,10 @@ add_setter_action (struct GNUNET_STATISTICS_Handle *h, const char *name, } ai->timeout = GNUNET_TIME_relative_to_absolute (SET_TRANSMIT_TIMEOUT); ai->make_persistent = make_persistent; - return; + return; } /* no existing entry matches, create a fresh one */ - ai = GNUNET_malloc (sizeof (struct GNUNET_STATISTICS_GetHandle)); + ai = GNUNET_new (struct GNUNET_STATISTICS_GetHandle); ai->sh = h; ai->subsystem = GNUNET_strdup (h->subsystem); ai->name = GNUNET_strdup (name);