diff options
author | Nathan S. Evans <evans@in.tum.de> | 2011-02-15 12:06:37 +0000 |
---|---|---|
committer | Nathan S. Evans <evans@in.tum.de> | 2011-02-15 12:06:37 +0000 |
commit | 3294e6c66210cdcca65524593ce09bbf4db14c7f (patch) | |
tree | d4c1dcb38f1646515b4821b04c58290f1dcc4b82 /src/transport/plugin_transport_unix.c | |
parent | 66dd280cc10564606ebba1eb17b9e4c171ca83fb (diff) | |
download | gnunet-3294e6c66210cdcca65524593ce09bbf4db14c7f.tar.gz gnunet-3294e6c66210cdcca65524593ce09bbf4db14c7f.zip |
Testing api change and related test case fixes, remember retry task and clean up on exit for unix domain socket transport.
Diffstat (limited to 'src/transport/plugin_transport_unix.c')
-rw-r--r-- | src/transport/plugin_transport_unix.c | 64 |
1 files changed, 63 insertions, 1 deletions
diff --git a/src/transport/plugin_transport_unix.c b/src/transport/plugin_transport_unix.c index 790e4451f..0163a8e5b 100644 --- a/src/transport/plugin_transport_unix.c +++ b/src/transport/plugin_transport_unix.c | |||
@@ -80,6 +80,24 @@ struct UNIXMessage | |||
80 | 80 | ||
81 | }; | 81 | }; |
82 | 82 | ||
83 | struct RetryList | ||
84 | { | ||
85 | /** | ||
86 | * Pointer to next element. | ||
87 | */ | ||
88 | struct RetryList *next; | ||
89 | |||
90 | /** | ||
91 | * Pointer to previous element. | ||
92 | */ | ||
93 | struct RetryList *prev; | ||
94 | |||
95 | /** | ||
96 | * The actual retry context. | ||
97 | */ | ||
98 | struct RetrySendContext *retry_ctx; | ||
99 | }; | ||
100 | |||
83 | /** | 101 | /** |
84 | * Network format for IPv4 addresses. | 102 | * Network format for IPv4 addresses. |
85 | */ | 103 | */ |
@@ -191,6 +209,11 @@ struct RetrySendContext | |||
191 | * The priority of the message. | 209 | * The priority of the message. |
192 | */ | 210 | */ |
193 | unsigned int priority; | 211 | unsigned int priority; |
212 | |||
213 | /** | ||
214 | * Entry in the DLL of retry items. | ||
215 | */ | ||
216 | struct RetryList *retry_list_entry; | ||
194 | }; | 217 | }; |
195 | 218 | ||
196 | /** | 219 | /** |
@@ -342,6 +365,16 @@ struct Plugin | |||
342 | 365 | ||
343 | }; | 366 | }; |
344 | 367 | ||
368 | /** | ||
369 | * Head of retry DLL. | ||
370 | */ | ||
371 | static struct RetryList *retry_list_head; | ||
372 | |||
373 | /** | ||
374 | * Tail of retry DLL. | ||
375 | */ | ||
376 | static struct RetryList *retry_list_tail; | ||
377 | |||
345 | 378 | ||
346 | /** | 379 | /** |
347 | * Disconnect from a remote node. Clean up session if we have one for this peer | 380 | * Disconnect from a remote node. Clean up session if we have one for this peer |
@@ -370,6 +403,22 @@ static int | |||
370 | unix_transport_server_stop (void *cls) | 403 | unix_transport_server_stop (void *cls) |
371 | { | 404 | { |
372 | struct Plugin *plugin = cls; | 405 | struct Plugin *plugin = cls; |
406 | struct RetryList *pos; | ||
407 | |||
408 | pos = retry_list_head; | ||
409 | |||
410 | while(NULL != (pos = retry_list_head)) | ||
411 | { | ||
412 | GNUNET_CONTAINER_DLL_remove(retry_list_head, retry_list_tail, pos); | ||
413 | if (GNUNET_SCHEDULER_NO_TASK != pos->retry_ctx->retry_task) | ||
414 | { | ||
415 | GNUNET_SCHEDULER_cancel(pos->retry_ctx->retry_task); | ||
416 | } | ||
417 | GNUNET_free(pos->retry_ctx->msg); | ||
418 | GNUNET_free(pos->retry_ctx->addr); | ||
419 | GNUNET_free(pos->retry_ctx); | ||
420 | GNUNET_free(pos); | ||
421 | } | ||
373 | 422 | ||
374 | if (plugin->select_task != GNUNET_SCHEDULER_NO_TASK) | 423 | if (plugin->select_task != GNUNET_SCHEDULER_NO_TASK) |
375 | { | 424 | { |
@@ -428,7 +477,13 @@ void retry_send_message (void *cls, | |||
428 | struct RetrySendContext *retry_ctx = cls; | 477 | struct RetrySendContext *retry_ctx = cls; |
429 | 478 | ||
430 | if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN) | 479 | if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN) |
431 | return; | 480 | { |
481 | GNUNET_free(retry_ctx->msg); | ||
482 | GNUNET_free(retry_ctx->addr); | ||
483 | GNUNET_free(retry_ctx); | ||
484 | return; | ||
485 | } | ||
486 | |||
432 | unix_real_send (retry_ctx->plugin, | 487 | unix_real_send (retry_ctx->plugin, |
433 | retry_ctx, | 488 | retry_ctx, |
434 | retry_ctx->send_handle, | 489 | retry_ctx->send_handle, |
@@ -489,6 +544,7 @@ unix_real_send (void *cls, | |||
489 | size_t sbs; | 544 | size_t sbs; |
490 | struct sockaddr_un un; | 545 | struct sockaddr_un un; |
491 | size_t slen; | 546 | size_t slen; |
547 | struct RetryList *retry_list_entry; | ||
492 | 548 | ||
493 | if (send_handle == NULL) | 549 | if (send_handle == NULL) |
494 | { | 550 | { |
@@ -542,6 +598,7 @@ unix_real_send (void *cls, | |||
542 | { | 598 | { |
543 | if (incoming_retry_context == NULL) | 599 | if (incoming_retry_context == NULL) |
544 | { | 600 | { |
601 | retry_list_entry = GNUNET_malloc(sizeof(struct RetryList)); | ||
545 | retry_ctx = GNUNET_malloc(sizeof(struct RetrySendContext)); | 602 | retry_ctx = GNUNET_malloc(sizeof(struct RetrySendContext)); |
546 | retry_ctx->addr = GNUNET_malloc(addrlen); | 603 | retry_ctx->addr = GNUNET_malloc(addrlen); |
547 | retry_ctx->msg = GNUNET_malloc(msgbuf_size); | 604 | retry_ctx->msg = GNUNET_malloc(msgbuf_size); |
@@ -557,6 +614,9 @@ unix_real_send (void *cls, | |||
557 | retry_ctx->timeout = GNUNET_TIME_relative_to_absolute(timeout); | 614 | retry_ctx->timeout = GNUNET_TIME_relative_to_absolute(timeout); |
558 | memcpy(&retry_ctx->target, target, sizeof(struct GNUNET_PeerIdentity)); | 615 | memcpy(&retry_ctx->target, target, sizeof(struct GNUNET_PeerIdentity)); |
559 | retry_ctx->delay = GNUNET_TIME_UNIT_MILLISECONDS; | 616 | retry_ctx->delay = GNUNET_TIME_UNIT_MILLISECONDS; |
617 | retry_ctx->retry_list_entry = retry_list_entry; | ||
618 | retry_list_entry->retry_ctx = retry_ctx; | ||
619 | GNUNET_CONTAINER_DLL_insert(retry_list_head, retry_list_tail, retry_list_entry); | ||
560 | } | 620 | } |
561 | else | 621 | else |
562 | { | 622 | { |
@@ -597,6 +657,8 @@ unix_real_send (void *cls, | |||
597 | 657 | ||
598 | if (incoming_retry_context != NULL) | 658 | if (incoming_retry_context != NULL) |
599 | { | 659 | { |
660 | GNUNET_CONTAINER_DLL_remove(retry_list_head, retry_list_tail, incoming_retry_context->retry_list_entry); | ||
661 | GNUNET_free(incoming_retry_context->retry_list_entry); | ||
600 | GNUNET_free(incoming_retry_context->msg); | 662 | GNUNET_free(incoming_retry_context->msg); |
601 | GNUNET_free(incoming_retry_context->addr); | 663 | GNUNET_free(incoming_retry_context->addr); |
602 | GNUNET_free(incoming_retry_context); | 664 | GNUNET_free(incoming_retry_context); |