diff options
Diffstat (limited to 'src/cadet/gnunet-cadet.c')
-rw-r--r-- | src/cadet/gnunet-cadet.c | 61 |
1 files changed, 44 insertions, 17 deletions
diff --git a/src/cadet/gnunet-cadet.c b/src/cadet/gnunet-cadet.c index 34e0655d2..39adca60d 100644 --- a/src/cadet/gnunet-cadet.c +++ b/src/cadet/gnunet-cadet.c | |||
@@ -116,6 +116,11 @@ static struct GNUNET_CADET_Handle *mh; | |||
116 | static struct GNUNET_CADET_Channel *ch; | 116 | static struct GNUNET_CADET_Channel *ch; |
117 | 117 | ||
118 | /** | 118 | /** |
119 | * Transmit handle. | ||
120 | */ | ||
121 | static struct GNUNET_CADET_TransmitHandle *th; | ||
122 | |||
123 | /** | ||
119 | * Shutdown task handle. | 124 | * Shutdown task handle. |
120 | */ | 125 | */ |
121 | struct GNUNET_SCHEDULER_Task * sd; | 126 | struct GNUNET_SCHEDULER_Task * sd; |
@@ -223,6 +228,8 @@ data_ready (void *cls, size_t size, void *buf) | |||
223 | struct GNUNET_MessageHeader *msg; | 228 | struct GNUNET_MessageHeader *msg; |
224 | size_t total_size; | 229 | size_t total_size; |
225 | 230 | ||
231 | th = NULL; | ||
232 | |||
226 | if (NULL == buf || 0 == size) | 233 | if (NULL == buf || 0 == size) |
227 | { | 234 | { |
228 | GNUNET_SCHEDULER_shutdown(); | 235 | GNUNET_SCHEDULER_shutdown(); |
@@ -251,8 +258,7 @@ data_ready (void *cls, size_t size, void *buf) | |||
251 | 258 | ||
252 | 259 | ||
253 | /** | 260 | /** |
254 | * Task run in monitor mode when the user presses CTRL-C to abort. | 261 | * Task run in stdio mode, after some data is available at stdin. |
255 | * Stops monitoring activity. | ||
256 | * | 262 | * |
257 | * @param cls Closure (unused). | 263 | * @param cls Closure (unused). |
258 | * @param tc scheduler context | 264 | * @param tc scheduler context |
@@ -275,11 +281,12 @@ read_stdio (void *cls, | |||
275 | GNUNET_SCHEDULER_shutdown(); | 281 | GNUNET_SCHEDULER_shutdown(); |
276 | return; | 282 | return; |
277 | } | 283 | } |
278 | GNUNET_CADET_notify_transmit_ready (ch, GNUNET_NO, | 284 | GNUNET_assert (NULL == th); |
279 | GNUNET_TIME_UNIT_FOREVER_REL, | 285 | th = GNUNET_CADET_notify_transmit_ready (ch, GNUNET_NO, |
280 | data_size | 286 | GNUNET_TIME_UNIT_FOREVER_REL, |
281 | + sizeof (struct GNUNET_MessageHeader), | 287 | sizeof (struct GNUNET_MessageHeader) |
282 | &data_ready, buf); | 288 | + data_size, |
289 | &data_ready, buf); | ||
283 | } | 290 | } |
284 | 291 | ||
285 | 292 | ||
@@ -318,7 +325,17 @@ channel_ended (void *cls, | |||
318 | void *channel_ctx) | 325 | void *channel_ctx) |
319 | { | 326 | { |
320 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Channel ended!\n"); | 327 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Channel ended!\n"); |
321 | GNUNET_break (channel == ch); | 328 | if (channel != ch) |
329 | { | ||
330 | GNUNET_break (0); | ||
331 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "ended: %p, expected: %p\n", channel, ch); | ||
332 | } | ||
333 | if (NULL != th) | ||
334 | { | ||
335 | GNUNET_CADET_notify_transmit_ready_cancel (th); | ||
336 | th = NULL; | ||
337 | } | ||
338 | |||
322 | ch = NULL; | 339 | ch = NULL; |
323 | GNUNET_SCHEDULER_shutdown (); | 340 | GNUNET_SCHEDULER_shutdown (); |
324 | } | 341 | } |
@@ -353,7 +370,10 @@ channel_incoming (void *cls, | |||
353 | channel, port); | 370 | channel, port); |
354 | if (NULL != ch) | 371 | if (NULL != ch) |
355 | { | 372 | { |
356 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "A channel already exists\n"); | 373 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
374 | "A channel already exists (%p)\n", channel); | ||
375 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
376 | "Incoming channel %p on port %u\n", channel, port); | ||
357 | return NULL; | 377 | return NULL; |
358 | } | 378 | } |
359 | if (0 == listen_port) | 379 | if (0 == listen_port) |
@@ -383,10 +403,11 @@ send_echo (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
383 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) || NULL == ch) | 403 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) || NULL == ch) |
384 | return; | 404 | return; |
385 | 405 | ||
386 | GNUNET_CADET_notify_transmit_ready (ch, GNUNET_NO, | 406 | GNUNET_assert (NULL == th); |
387 | GNUNET_TIME_UNIT_FOREVER_REL, | 407 | th = GNUNET_CADET_notify_transmit_ready (ch, GNUNET_NO, |
388 | sizeof (struct GNUNET_MessageHeader), | 408 | GNUNET_TIME_UNIT_FOREVER_REL, |
389 | &data_ready, NULL); | 409 | sizeof (struct GNUNET_MessageHeader), |
410 | &data_ready, NULL); | ||
390 | } | 411 | } |
391 | 412 | ||
392 | 413 | ||
@@ -472,10 +493,16 @@ data_callback (void *cls, | |||
472 | if (0 != listen_port) | 493 | if (0 != listen_port) |
473 | { | 494 | { |
474 | /* Just listening to echo incoming messages*/ | 495 | /* Just listening to echo incoming messages*/ |
475 | GNUNET_CADET_notify_transmit_ready (channel, GNUNET_NO, | 496 | if (NULL != th) |
476 | GNUNET_TIME_UNIT_FOREVER_REL, | 497 | { |
477 | sizeof (struct GNUNET_MessageHeader), | 498 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
478 | &data_ready, NULL); | 499 | "Last echo reply not yet sent, dropping current reply.\n"); |
500 | return GNUNET_OK; | ||
501 | } | ||
502 | th = GNUNET_CADET_notify_transmit_ready (channel, GNUNET_NO, | ||
503 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
504 | sizeof (struct GNUNET_MessageHeader), | ||
505 | &data_ready, NULL); | ||
479 | return GNUNET_OK; | 506 | return GNUNET_OK; |
480 | } | 507 | } |
481 | else | 508 | else |