diff options
author | Sree Harsha Totakura <totakura@in.tum.de> | 2013-05-08 15:03:32 +0000 |
---|---|---|
committer | Sree Harsha Totakura <totakura@in.tum.de> | 2013-05-08 15:03:32 +0000 |
commit | 07ec41e414c2e47df842b83acc481c257ce4de15 (patch) | |
tree | ec542749bcde8b20426b98ae5c2428f6c158b271 /src | |
parent | d572acdffc00a8e70912558d99af608a00dc8cdd (diff) | |
download | gnunet-07ec41e414c2e47df842b83acc481c257ce4de15.tar.gz gnunet-07ec41e414c2e47df842b83acc481c257ce4de15.zip |
- have a timeout for cases where flushing takes too long
Diffstat (limited to 'src')
-rw-r--r-- | src/include/gnunet_testbed_logger_service.h | 6 | ||||
-rw-r--r-- | src/nse/gnunet-service-nse.c | 4 | ||||
-rw-r--r-- | src/testbed/test_testbed_logger_api.c | 3 | ||||
-rw-r--r-- | src/testbed/testbed_logger_api.c | 92 |
4 files changed, 98 insertions, 7 deletions
diff --git a/src/include/gnunet_testbed_logger_service.h b/src/include/gnunet_testbed_logger_service.h index 7359727b2..95783ea37 100644 --- a/src/include/gnunet_testbed_logger_service.h +++ b/src/include/gnunet_testbed_logger_service.h | |||
@@ -91,17 +91,21 @@ GNUNET_TESTBED_LOGGER_write (struct GNUNET_TESTBED_LOGGER_Handle *h, | |||
91 | * Flush the buffered data to the logger service | 91 | * Flush the buffered data to the logger service |
92 | * | 92 | * |
93 | * @param h the logger handle | 93 | * @param h the logger handle |
94 | * @param timeout how long to wait before calling the flust completion callback | ||
94 | * @param cb the callback to call after the data is flushed | 95 | * @param cb the callback to call after the data is flushed |
95 | * @param cb_cls the closure for the above callback | 96 | * @param cb_cls the closure for the above callback |
96 | */ | 97 | */ |
97 | void | 98 | void |
98 | GNUNET_TESTBED_LOGGER_flush (struct GNUNET_TESTBED_LOGGER_Handle *h, | 99 | GNUNET_TESTBED_LOGGER_flush (struct GNUNET_TESTBED_LOGGER_Handle *h, |
100 | struct GNUNET_TIME_Relative timeout, | ||
99 | GNUNET_TESTBED_LOGGER_FlushCompletion cb, | 101 | GNUNET_TESTBED_LOGGER_FlushCompletion cb, |
100 | void *cb_cls); | 102 | void *cb_cls); |
101 | 103 | ||
102 | 104 | ||
103 | /** | 105 | /** |
104 | * Cancel notification upon flush. | 106 | * Cancel notification upon flush. Should only be used when the flush |
107 | * completion callback given to GNUNET_TESTBED_LOGGER_flush() is not already | ||
108 | * called. | ||
105 | * | 109 | * |
106 | * @param h the logger handle | 110 | * @param h the logger handle |
107 | */ | 111 | */ |
diff --git a/src/nse/gnunet-service-nse.c b/src/nse/gnunet-service-nse.c index 433274372..e69555f37 100644 --- a/src/nse/gnunet-service-nse.c +++ b/src/nse/gnunet-service-nse.c | |||
@@ -1334,7 +1334,9 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1334 | my_private_key = NULL; | 1334 | my_private_key = NULL; |
1335 | } | 1335 | } |
1336 | #if ENABLE_NSE_HISTOGRAM | 1336 | #if ENABLE_NSE_HISTOGRAM |
1337 | GNUNET_TESTBED_LOGGER_flush (lh, &flush_comp_cb, NULL); /* actual shutdown delayed */ | 1337 | struct GNUNET_TIME_Relative timeout; |
1338 | timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30); | ||
1339 | GNUNET_TESTBED_LOGGER_flush (lh, timeout, &flush_comp_cb, NULL); | ||
1338 | #endif | 1340 | #endif |
1339 | } | 1341 | } |
1340 | 1342 | ||
diff --git a/src/testbed/test_testbed_logger_api.c b/src/testbed/test_testbed_logger_api.c index 438b131d0..bbc9e33d2 100644 --- a/src/testbed/test_testbed_logger_api.c +++ b/src/testbed/test_testbed_logger_api.c | |||
@@ -183,7 +183,8 @@ do_write (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
183 | GNUNET_TESTBED_LOGGER_write (h, buf, BSIZE); | 183 | GNUNET_TESTBED_LOGGER_write (h, buf, BSIZE); |
184 | if (0 == i++) | 184 | if (0 == i++) |
185 | return; | 185 | return; |
186 | GNUNET_TESTBED_LOGGER_flush (h, &flush_comp, &write_task); | 186 | GNUNET_TESTBED_LOGGER_flush (h, GNUNET_TIME_UNIT_FOREVER_REL, |
187 | &flush_comp, &write_task); | ||
187 | } | 188 | } |
188 | 189 | ||
189 | 190 | ||
diff --git a/src/testbed/testbed_logger_api.c b/src/testbed/testbed_logger_api.c index 674a170d3..24def4bcb 100644 --- a/src/testbed/testbed_logger_api.c +++ b/src/testbed/testbed_logger_api.c | |||
@@ -92,6 +92,9 @@ struct GNUNET_TESTBED_LOGGER_Handle | |||
92 | */ | 92 | */ |
93 | struct GNUNET_CLIENT_Connection *client; | 93 | struct GNUNET_CLIENT_Connection *client; |
94 | 94 | ||
95 | /** | ||
96 | * The transport handle | ||
97 | */ | ||
95 | struct GNUNET_CLIENT_TransmitHandle *th; | 98 | struct GNUNET_CLIENT_TransmitHandle *th; |
96 | 99 | ||
97 | /** | 100 | /** |
@@ -104,23 +107,63 @@ struct GNUNET_TESTBED_LOGGER_Handle | |||
104 | */ | 107 | */ |
105 | struct MessageQueue *mq_tail; | 108 | struct MessageQueue *mq_tail; |
106 | 109 | ||
107 | GNUNET_SCHEDULER_TaskIdentifier flush_completion_task; | 110 | /** |
108 | 111 | * Flush completion callback | |
112 | */ | ||
109 | GNUNET_TESTBED_LOGGER_FlushCompletion cb; | 113 | GNUNET_TESTBED_LOGGER_FlushCompletion cb; |
110 | 114 | ||
115 | /** | ||
116 | * Closure for the above callback | ||
117 | */ | ||
111 | void *cb_cls; | 118 | void *cb_cls; |
112 | 119 | ||
120 | /** | ||
121 | * Local buffer for data to be transmitted | ||
122 | */ | ||
113 | void *buf; | 123 | void *buf; |
114 | 124 | ||
125 | /** | ||
126 | * The size of the local buffer | ||
127 | */ | ||
115 | size_t bs; | 128 | size_t bs; |
116 | 129 | ||
130 | /** | ||
131 | * Number of bytes wrote since last flush | ||
132 | */ | ||
117 | size_t bwrote; | 133 | size_t bwrote; |
118 | 134 | ||
135 | /** | ||
136 | * How long after should we retry sending a message to the service? | ||
137 | */ | ||
119 | struct GNUNET_TIME_Relative retry_backoff; | 138 | struct GNUNET_TIME_Relative retry_backoff; |
139 | |||
140 | /** | ||
141 | * Task to call the flush completion callback | ||
142 | */ | ||
143 | GNUNET_SCHEDULER_TaskIdentifier flush_completion_task; | ||
144 | |||
145 | /** | ||
146 | * Task to be executed when flushing takes too long | ||
147 | */ | ||
148 | GNUNET_SCHEDULER_TaskIdentifier timeout_flush_task; | ||
120 | }; | 149 | }; |
121 | 150 | ||
122 | 151 | ||
123 | /** | 152 | /** |
153 | * Cancels the flush timeout task | ||
154 | * | ||
155 | * @param | ||
156 | * @return | ||
157 | */ | ||
158 | static void | ||
159 | cancel_timeout_flush (struct GNUNET_TESTBED_LOGGER_Handle *h) | ||
160 | { | ||
161 | GNUNET_SCHEDULER_cancel (h->timeout_flush_task); | ||
162 | h->timeout_flush_task = GNUNET_SCHEDULER_NO_TASK; | ||
163 | } | ||
164 | |||
165 | |||
166 | /** | ||
124 | * Task to call the flush completion notification | 167 | * Task to call the flush completion notification |
125 | * | 168 | * |
126 | * @param cls the logger handle | 169 | * @param cls the logger handle |
@@ -129,7 +172,7 @@ struct GNUNET_TESTBED_LOGGER_Handle | |||
129 | static void | 172 | static void |
130 | call_flush_completion (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 173 | call_flush_completion (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
131 | { | 174 | { |
132 | struct GNUNET_TESTBED_LOGGER_Handle *h = cls; | 175 | struct GNUNET_TESTBED_LOGGER_Handle *h = cls; |
133 | GNUNET_TESTBED_LOGGER_FlushCompletion cb; | 176 | GNUNET_TESTBED_LOGGER_FlushCompletion cb; |
134 | void *cb_cls; | 177 | void *cb_cls; |
135 | size_t bw; | 178 | size_t bw; |
@@ -141,6 +184,8 @@ call_flush_completion (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
141 | h->cb = NULL; | 184 | h->cb = NULL; |
142 | cb_cls = h->cb_cls; | 185 | cb_cls = h->cb_cls; |
143 | h->cb_cls = NULL; | 186 | h->cb_cls = NULL; |
187 | if (GNUNET_SCHEDULER_NO_TASK != h->timeout_flush_task) | ||
188 | cancel_timeout_flush (h); | ||
144 | if (NULL != cb) | 189 | if (NULL != cb) |
145 | cb (cb_cls, bw); | 190 | cb (cb_cls, bw); |
146 | } | 191 | } |
@@ -355,19 +400,54 @@ GNUNET_TESTBED_LOGGER_write (struct GNUNET_TESTBED_LOGGER_Handle *h, | |||
355 | 400 | ||
356 | 401 | ||
357 | /** | 402 | /** |
403 | * Task to be executed when flushing our local buffer takes longer than timeout | ||
404 | * given to GNUNET_TESTBED_LOGGER_flush(). The flush completion callback will | ||
405 | * be called with 0 as the amount of data sent. | ||
406 | * | ||
407 | * @param cls the logger handle | ||
408 | * @param tc scheduler task context | ||
409 | */ | ||
410 | static void | ||
411 | timeout_flush (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
412 | { | ||
413 | struct GNUNET_TESTBED_LOGGER_Handle *h = cls; | ||
414 | GNUNET_TESTBED_LOGGER_FlushCompletion cb; | ||
415 | void *cb_cls; | ||
416 | |||
417 | h->timeout_flush_task = GNUNET_SCHEDULER_NO_TASK; | ||
418 | cb = h->cb; | ||
419 | h->cb = NULL; | ||
420 | cb_cls = h->cb_cls; | ||
421 | h->cb_cls = NULL; | ||
422 | if (GNUNET_SCHEDULER_NO_TASK != h->flush_completion_task) | ||
423 | { | ||
424 | GNUNET_SCHEDULER_cancel (h->flush_completion_task); | ||
425 | h->flush_completion_task = GNUNET_SCHEDULER_NO_TASK; | ||
426 | } | ||
427 | if (NULL != cb) | ||
428 | cb (cb_cls, 0); | ||
429 | } | ||
430 | |||
431 | |||
432 | /** | ||
358 | * Flush the buffered data to the logger service | 433 | * Flush the buffered data to the logger service |
359 | * | 434 | * |
360 | * @param h the logger handle | 435 | * @param h the logger handle |
436 | * @param timeout how long to wait before calling the flust completion callback | ||
361 | * @param cb the callback to call after the data is flushed | 437 | * @param cb the callback to call after the data is flushed |
362 | * @param cb_cls the closure for the above callback | 438 | * @param cb_cls the closure for the above callback |
363 | */ | 439 | */ |
364 | void | 440 | void |
365 | GNUNET_TESTBED_LOGGER_flush (struct GNUNET_TESTBED_LOGGER_Handle *h, | 441 | GNUNET_TESTBED_LOGGER_flush (struct GNUNET_TESTBED_LOGGER_Handle *h, |
442 | struct GNUNET_TIME_Relative timeout, | ||
366 | GNUNET_TESTBED_LOGGER_FlushCompletion cb, | 443 | GNUNET_TESTBED_LOGGER_FlushCompletion cb, |
367 | void *cb_cls) | 444 | void *cb_cls) |
368 | { | 445 | { |
369 | h->cb = cb; | 446 | h->cb = cb; |
370 | h->cb_cls = cb_cls; | 447 | h->cb_cls = cb_cls; |
448 | GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == h->timeout_flush_task); | ||
449 | h->timeout_flush_task = | ||
450 | GNUNET_SCHEDULER_add_delayed (timeout, &timeout_flush, h); | ||
371 | if (NULL == h->buf) | 451 | if (NULL == h->buf) |
372 | { | 452 | { |
373 | trigger_flush_notification (h); | 453 | trigger_flush_notification (h); |
@@ -378,7 +458,9 @@ GNUNET_TESTBED_LOGGER_flush (struct GNUNET_TESTBED_LOGGER_Handle *h, | |||
378 | 458 | ||
379 | 459 | ||
380 | /** | 460 | /** |
381 | * Cancel notification upon flush. | 461 | * Cancel notification upon flush. Should only be used when the flush |
462 | * completion callback given to GNUNET_TESTBED_LOGGER_flush() is not already | ||
463 | * called. | ||
382 | * | 464 | * |
383 | * @param h the logger handle | 465 | * @param h the logger handle |
384 | */ | 466 | */ |
@@ -390,6 +472,8 @@ GNUNET_TESTBED_LOGGER_flush_cancel (struct GNUNET_TESTBED_LOGGER_Handle *h) | |||
390 | GNUNET_SCHEDULER_cancel (h->flush_completion_task); | 472 | GNUNET_SCHEDULER_cancel (h->flush_completion_task); |
391 | h->flush_completion_task = GNUNET_SCHEDULER_NO_TASK; | 473 | h->flush_completion_task = GNUNET_SCHEDULER_NO_TASK; |
392 | } | 474 | } |
475 | if (GNUNET_SCHEDULER_NO_TASK != h->timeout_flush_task) | ||
476 | cancel_timeout_flush (h); | ||
393 | h->cb = NULL; | 477 | h->cb = NULL; |
394 | h->cb_cls = NULL; | 478 | h->cb_cls = NULL; |
395 | } | 479 | } |