diff options
author | Christian Grothoff <christian@grothoff.org> | 2010-02-18 14:28:58 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2010-02-18 14:28:58 +0000 |
commit | 819d8df0fe778124e51d765303549fe36fbf7bf2 (patch) | |
tree | 917f7dafb8dcad4df2b75a86fc45341c42ffbec3 /src | |
parent | b98a298aaae3976cd3c01d12bafc8880e8024944 (diff) | |
download | gnunet-819d8df0fe778124e51d765303549fe36fbf7bf2.tar.gz gnunet-819d8df0fe778124e51d765303549fe36fbf7bf2.zip |
fixes, cleaner code
Diffstat (limited to 'src')
-rw-r--r-- | src/transport/gnunet-service-transport.c | 87 |
1 files changed, 49 insertions, 38 deletions
diff --git a/src/transport/gnunet-service-transport.c b/src/transport/gnunet-service-transport.c index b89bc8bce..3fbbc8804 100644 --- a/src/transport/gnunet-service-transport.c +++ b/src/transport/gnunet-service-transport.c | |||
@@ -573,17 +573,22 @@ struct TransportPongMessage | |||
573 | 573 | ||
574 | }; | 574 | }; |
575 | 575 | ||
576 | |||
576 | /** | 577 | /** |
577 | * Linked list of messages to be transmitted to | 578 | * Linked list of messages to be transmitted to the client. Each |
578 | * the client. Each entry is followed by the | 579 | * entry is followed by the actual message. |
579 | * actual message. | ||
580 | */ | 580 | */ |
581 | struct ClientMessageQueueEntry | 581 | struct ClientMessageQueueEntry |
582 | { | 582 | { |
583 | /** | 583 | /** |
584 | * This is a linked list. | 584 | * This is a doubly-linked list. |
585 | */ | 585 | */ |
586 | struct ClientMessageQueueEntry *next; | 586 | struct ClientMessageQueueEntry *next; |
587 | |||
588 | /** | ||
589 | * This is a doubly-linked list. | ||
590 | */ | ||
591 | struct ClientMessageQueueEntry *prev; | ||
587 | }; | 592 | }; |
588 | 593 | ||
589 | 594 | ||
@@ -616,6 +621,11 @@ struct TransportClient | |||
616 | struct ClientMessageQueueEntry *message_queue_tail; | 621 | struct ClientMessageQueueEntry *message_queue_tail; |
617 | 622 | ||
618 | /** | 623 | /** |
624 | * Current transmit request handle. | ||
625 | */ | ||
626 | struct GNUNET_CONNECTION_TransmitHandle *th; | ||
627 | |||
628 | /** | ||
619 | * Is a call to "transmit_send_continuation" pending? If so, we | 629 | * Is a call to "transmit_send_continuation" pending? If so, we |
620 | * must not free this struct (even if the corresponding client | 630 | * must not free this struct (even if the corresponding client |
621 | * disconnects) and instead only remove it from the linked list and | 631 | * disconnects) and instead only remove it from the linked list and |
@@ -912,9 +922,9 @@ transmit_to_client_callback (void *cls, size_t size, void *buf) | |||
912 | uint16_t msize; | 922 | uint16_t msize; |
913 | size_t tsize; | 923 | size_t tsize; |
914 | const struct GNUNET_MessageHeader *msg; | 924 | const struct GNUNET_MessageHeader *msg; |
915 | struct GNUNET_CONNECTION_TransmitHandle *th; | ||
916 | char *cbuf; | 925 | char *cbuf; |
917 | 926 | ||
927 | client->th = NULL; | ||
918 | if (buf == NULL) | 928 | if (buf == NULL) |
919 | { | 929 | { |
920 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 930 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -922,10 +932,11 @@ transmit_to_client_callback (void *cls, size_t size, void *buf) | |||
922 | /* fatal error with client, free message queue! */ | 932 | /* fatal error with client, free message queue! */ |
923 | while (NULL != (q = client->message_queue_head)) | 933 | while (NULL != (q = client->message_queue_head)) |
924 | { | 934 | { |
925 | client->message_queue_head = q->next; | 935 | GNUNET_CONTAINER_DLL_remove (client->message_queue_head, |
936 | client->message_queue_tail, | ||
937 | q); | ||
926 | GNUNET_free (q); | 938 | GNUNET_free (q); |
927 | } | 939 | } |
928 | client->message_queue_tail = NULL; | ||
929 | client->message_count = 0; | 940 | client->message_count = 0; |
930 | return 0; | 941 | return 0; |
931 | } | 942 | } |
@@ -942,9 +953,9 @@ transmit_to_client_callback (void *cls, size_t size, void *buf) | |||
942 | "Transmitting message of type %u to client.\n", | 953 | "Transmitting message of type %u to client.\n", |
943 | ntohs (msg->type)); | 954 | ntohs (msg->type)); |
944 | #endif | 955 | #endif |
945 | client->message_queue_head = q->next; | 956 | GNUNET_CONTAINER_DLL_remove (client->message_queue_head, |
946 | if (q->next == NULL) | 957 | client->message_queue_tail, |
947 | client->message_queue_tail = NULL; | 958 | q); |
948 | memcpy (&cbuf[tsize], msg, msize); | 959 | memcpy (&cbuf[tsize], msg, msize); |
949 | tsize += msize; | 960 | tsize += msize; |
950 | GNUNET_free (q); | 961 | GNUNET_free (q); |
@@ -953,12 +964,12 @@ transmit_to_client_callback (void *cls, size_t size, void *buf) | |||
953 | if (NULL != q) | 964 | if (NULL != q) |
954 | { | 965 | { |
955 | GNUNET_assert (msize >= sizeof (struct GNUNET_MessageHeader)); | 966 | GNUNET_assert (msize >= sizeof (struct GNUNET_MessageHeader)); |
956 | th = GNUNET_SERVER_notify_transmit_ready (client->client, | 967 | client->th = GNUNET_SERVER_notify_transmit_ready (client->client, |
957 | msize, | 968 | msize, |
958 | GNUNET_TIME_UNIT_FOREVER_REL, | 969 | GNUNET_TIME_UNIT_FOREVER_REL, |
959 | &transmit_to_client_callback, | 970 | &transmit_to_client_callback, |
960 | client); | 971 | client); |
961 | GNUNET_assert (th != NULL); | 972 | GNUNET_assert (client->th != NULL); |
962 | } | 973 | } |
963 | return tsize; | 974 | return tsize; |
964 | } | 975 | } |
@@ -980,7 +991,6 @@ transmit_to_client (struct TransportClient *client, | |||
980 | { | 991 | { |
981 | struct ClientMessageQueueEntry *q; | 992 | struct ClientMessageQueueEntry *q; |
982 | uint16_t msize; | 993 | uint16_t msize; |
983 | struct GNUNET_CONNECTION_TransmitHandle *th; | ||
984 | 994 | ||
985 | if ((client->message_count >= MAX_PENDING) && (GNUNET_YES == may_drop)) | 995 | if ((client->message_count >= MAX_PENDING) && (GNUNET_YES == may_drop)) |
986 | { | 996 | { |
@@ -991,30 +1001,23 @@ transmit_to_client (struct TransportClient *client, | |||
991 | /* TODO: call to statistics... */ | 1001 | /* TODO: call to statistics... */ |
992 | return; | 1002 | return; |
993 | } | 1003 | } |
994 | client->message_count++; | ||
995 | msize = ntohs (msg->size); | 1004 | msize = ntohs (msg->size); |
996 | GNUNET_assert (msize >= sizeof (struct GNUNET_MessageHeader)); | 1005 | GNUNET_assert (msize >= sizeof (struct GNUNET_MessageHeader)); |
997 | q = GNUNET_malloc (sizeof (struct ClientMessageQueueEntry) + msize); | 1006 | q = GNUNET_malloc (sizeof (struct ClientMessageQueueEntry) + msize); |
998 | memcpy (&q[1], msg, msize); | 1007 | memcpy (&q[1], msg, msize); |
999 | /* append to message queue */ | 1008 | GNUNET_CONTAINER_DLL_insert_after (client->message_queue_head, |
1000 | if (client->message_queue_tail == NULL) | 1009 | client->message_queue_tail, |
1001 | { | 1010 | client->message_queue_tail, |
1002 | client->message_queue_tail = q; | 1011 | q); |
1003 | } | 1012 | client->message_count++; |
1004 | else | 1013 | if (client->th == NULL) |
1005 | { | ||
1006 | client->message_queue_tail->next = q; | ||
1007 | client->message_queue_tail = q; | ||
1008 | } | ||
1009 | if (client->message_queue_head == NULL) | ||
1010 | { | 1014 | { |
1011 | client->message_queue_head = q; | 1015 | client->th = GNUNET_SERVER_notify_transmit_ready (client->client, |
1012 | th = GNUNET_SERVER_notify_transmit_ready (client->client, | 1016 | msize, |
1013 | msize, | 1017 | GNUNET_TIME_UNIT_FOREVER_REL, |
1014 | GNUNET_TIME_UNIT_FOREVER_REL, | 1018 | &transmit_to_client_callback, |
1015 | &transmit_to_client_callback, | 1019 | client); |
1016 | client); | 1020 | GNUNET_assert (client->th != NULL); |
1017 | GNUNET_assert (th != NULL); | ||
1018 | } | 1021 | } |
1019 | } | 1022 | } |
1020 | 1023 | ||
@@ -3046,10 +3049,12 @@ client_disconnect_notification (void *cls, | |||
3046 | return; | 3049 | return; |
3047 | while (NULL != (mqe = pos->message_queue_head)) | 3050 | while (NULL != (mqe = pos->message_queue_head)) |
3048 | { | 3051 | { |
3049 | pos->message_queue_head = mqe->next; | 3052 | GNUNET_CONTAINER_DLL_remove (pos->message_queue_head, |
3053 | pos->message_queue_tail, | ||
3054 | mqe); | ||
3055 | pos->message_count--; | ||
3050 | GNUNET_free (mqe); | 3056 | GNUNET_free (mqe); |
3051 | } | 3057 | } |
3052 | pos->message_queue_head = NULL; | ||
3053 | if (prev == NULL) | 3058 | if (prev == NULL) |
3054 | clients = pos->next; | 3059 | clients = pos->next; |
3055 | else | 3060 | else |
@@ -3059,6 +3064,12 @@ client_disconnect_notification (void *cls, | |||
3059 | pos->client = NULL; | 3064 | pos->client = NULL; |
3060 | return; | 3065 | return; |
3061 | } | 3066 | } |
3067 | if (pos->th != NULL) | ||
3068 | { | ||
3069 | GNUNET_CONNECTION_notify_transmit_ready_cancel (pos->th); | ||
3070 | pos->th = NULL; | ||
3071 | } | ||
3072 | GNUNET_break (0 == pos->message_count); | ||
3062 | GNUNET_free (pos); | 3073 | GNUNET_free (pos); |
3063 | } | 3074 | } |
3064 | 3075 | ||