diff options
author | Christian Grothoff <christian@grothoff.org> | 2009-10-25 10:24:57 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2009-10-25 10:24:57 +0000 |
commit | 896b68310ed985d4966a7697d4ed91e3f618e82c (patch) | |
tree | d05f14c3ea6a3b9af4ac877728c653f9d377be0e /src/statistics/statistics_api.c | |
parent | 166ceb17b22ae4321056dc975573264f0d2d0e96 (diff) | |
download | gnunet-896b68310ed985d4966a7697d4ed91e3f618e82c.tar.gz gnunet-896b68310ed985d4966a7697d4ed91e3f618e82c.zip |
fix
Diffstat (limited to 'src/statistics/statistics_api.c')
-rw-r--r-- | src/statistics/statistics_api.c | 83 |
1 files changed, 39 insertions, 44 deletions
diff --git a/src/statistics/statistics_api.c b/src/statistics/statistics_api.c index cc0a1b11a..49709cc72 100644 --- a/src/statistics/statistics_api.c +++ b/src/statistics/statistics_api.c | |||
@@ -139,6 +139,11 @@ struct GNUNET_STATISTICS_Handle | |||
139 | struct GNUNET_CLIENT_Connection *client; | 139 | struct GNUNET_CLIENT_Connection *client; |
140 | 140 | ||
141 | /** | 141 | /** |
142 | * Currently pending transmission request. | ||
143 | */ | ||
144 | struct GNUNET_CLIENT_TransmitHandle *th; | ||
145 | |||
146 | /** | ||
142 | * Head of the linked list of pending actions (first action | 147 | * Head of the linked list of pending actions (first action |
143 | * to be performed). | 148 | * to be performed). |
144 | */ | 149 | */ |
@@ -156,11 +161,6 @@ struct GNUNET_STATISTICS_Handle | |||
156 | */ | 161 | */ |
157 | struct ActionItem *current; | 162 | struct ActionItem *current; |
158 | 163 | ||
159 | /** | ||
160 | * Should this handle be destroyed once we've processed | ||
161 | * all actions? | ||
162 | */ | ||
163 | int do_destroy; | ||
164 | 164 | ||
165 | }; | 165 | }; |
166 | 166 | ||
@@ -226,13 +226,25 @@ GNUNET_STATISTICS_create (struct GNUNET_SCHEDULER_Handle *sched, | |||
226 | 226 | ||
227 | 227 | ||
228 | /** | 228 | /** |
229 | * Actually free the handle. | 229 | * Destroy a handle (free all state associated with |
230 | * it). | ||
230 | */ | 231 | */ |
231 | static void | 232 | void |
232 | do_destroy (struct GNUNET_STATISTICS_Handle *h) | 233 | GNUNET_STATISTICS_destroy (struct GNUNET_STATISTICS_Handle *h) |
233 | { | 234 | { |
234 | GNUNET_assert (h->action_head == NULL); | 235 | struct ActionItem *pos; |
235 | GNUNET_assert (h->current == NULL); | 236 | if (NULL != h->th) |
237 | { | ||
238 | GNUNET_CLIENT_notify_transmit_ready_cancel (h->th); | ||
239 | h->th = NULL; | ||
240 | } | ||
241 | if (h->current != NULL) | ||
242 | free_action_item (h->current); | ||
243 | while (NULL != (pos = h->action_head)) | ||
244 | { | ||
245 | h->action_head = pos->next; | ||
246 | free_action_item (pos); | ||
247 | } | ||
236 | if (h->client != NULL) | 248 | if (h->client != NULL) |
237 | { | 249 | { |
238 | GNUNET_CLIENT_disconnect (h->client); | 250 | GNUNET_CLIENT_disconnect (h->client); |
@@ -244,23 +256,6 @@ do_destroy (struct GNUNET_STATISTICS_Handle *h) | |||
244 | 256 | ||
245 | 257 | ||
246 | /** | 258 | /** |
247 | * Destroy a handle (free all state associated with | ||
248 | * it). | ||
249 | */ | ||
250 | void | ||
251 | GNUNET_STATISTICS_destroy (struct GNUNET_STATISTICS_Handle *handle) | ||
252 | { | ||
253 | GNUNET_assert (handle->do_destroy == GNUNET_NO); | ||
254 | if ((handle->action_head != NULL) || (handle->current != NULL)) | ||
255 | { | ||
256 | handle->do_destroy = GNUNET_YES; | ||
257 | return; | ||
258 | } | ||
259 | do_destroy (handle); | ||
260 | } | ||
261 | |||
262 | |||
263 | /** | ||
264 | * Process the message. | 259 | * Process the message. |
265 | * | 260 | * |
266 | * @return GNUNET_OK if the message was well-formed | 261 | * @return GNUNET_OK if the message was well-formed |
@@ -348,8 +343,11 @@ receive_stats (void *cls, const struct GNUNET_MessageHeader *msg) | |||
348 | 343 | ||
349 | if (msg == NULL) | 344 | if (msg == NULL) |
350 | { | 345 | { |
351 | GNUNET_CLIENT_disconnect (h->client); | 346 | if (NULL != h->client) |
352 | h->client = NULL; | 347 | { |
348 | GNUNET_CLIENT_disconnect (h->client); | ||
349 | h->client = NULL; | ||
350 | } | ||
353 | #if DEBUG_STATISTICS | 351 | #if DEBUG_STATISTICS |
354 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, | 352 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, |
355 | "Error receiving statistics from service, is the service running?\n" ); | 353 | "Error receiving statistics from service, is the service running?\n" ); |
@@ -383,8 +381,11 @@ receive_stats (void *cls, const struct GNUNET_MessageHeader *msg) | |||
383 | GNUNET_break (0); | 381 | GNUNET_break (0); |
384 | break; | 382 | break; |
385 | } | 383 | } |
386 | GNUNET_CLIENT_disconnect (h->client); | 384 | if (NULL != h->client) |
387 | h->client = NULL; | 385 | { |
386 | GNUNET_CLIENT_disconnect (h->client); | ||
387 | h->client = NULL; | ||
388 | } | ||
388 | finish (h, GNUNET_SYSERR); | 389 | finish (h, GNUNET_SYSERR); |
389 | } | 390 | } |
390 | 391 | ||
@@ -486,6 +487,7 @@ transmit_action (void *cls, size_t size, void *buf) | |||
486 | struct GNUNET_STATISTICS_Handle *handle = cls; | 487 | struct GNUNET_STATISTICS_Handle *handle = cls; |
487 | size_t ret; | 488 | size_t ret; |
488 | 489 | ||
490 | handle->th = NULL; | ||
489 | switch (handle->current->type) | 491 | switch (handle->current->type) |
490 | { | 492 | { |
491 | case ACTION_GET: | 493 | case ACTION_GET: |
@@ -523,25 +525,18 @@ schedule_action (struct GNUNET_STATISTICS_Handle *h) | |||
523 | /* schedule next action */ | 525 | /* schedule next action */ |
524 | h->current = h->action_head; | 526 | h->current = h->action_head; |
525 | if (NULL == h->current) | 527 | if (NULL == h->current) |
526 | { | 528 | return; |
527 | /* no pending network action, check destroy! */ | ||
528 | if (h->do_destroy != GNUNET_YES) | ||
529 | return; | ||
530 | do_destroy (h); | ||
531 | return; | ||
532 | } | ||
533 | h->action_head = h->action_head->next; | 529 | h->action_head = h->action_head->next; |
534 | if (NULL == h->action_head) | 530 | if (NULL == h->action_head) |
535 | h->action_tail = NULL; | 531 | h->action_tail = NULL; |
536 | h->current->next = NULL; | 532 | h->current->next = NULL; |
537 | |||
538 | timeout = GNUNET_TIME_absolute_get_remaining (h->current->timeout); | 533 | timeout = GNUNET_TIME_absolute_get_remaining (h->current->timeout); |
539 | if (NULL == | 534 | if (NULL == |
540 | GNUNET_CLIENT_notify_transmit_ready (h->client, | 535 | (h->th = GNUNET_CLIENT_notify_transmit_ready (h->client, |
541 | h->current->msize, | 536 | h->current->msize, |
542 | timeout, | 537 | timeout, |
543 | GNUNET_YES, | 538 | GNUNET_YES, |
544 | &transmit_action, h)) | 539 | &transmit_action, h))) |
545 | { | 540 | { |
546 | #if DEBUG_STATISTICS | 541 | #if DEBUG_STATISTICS |
547 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 542 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |