diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-04-20 08:31:54 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-04-20 08:31:54 +0000 |
commit | 468368210871d8d86c179bfce43d0b68e9eb331d (patch) | |
tree | 394170bec368e26ea09cff6bddc44fab27469e0e /src/transport | |
parent | 167c1552f3db95705317f32e21f6cd73ef75c9c6 (diff) | |
download | gnunet-468368210871d8d86c179bfce43d0b68e9eb331d.tar.gz gnunet-468368210871d8d86c179bfce43d0b68e9eb331d.zip |
fixing shutdown
Diffstat (limited to 'src/transport')
-rw-r--r-- | src/transport/plugin_transport_wlan.c | 130 |
1 files changed, 59 insertions, 71 deletions
diff --git a/src/transport/plugin_transport_wlan.c b/src/transport/plugin_transport_wlan.c index 441989165..fbaf7aa23 100644 --- a/src/transport/plugin_transport_wlan.c +++ b/src/transport/plugin_transport_wlan.c | |||
@@ -780,7 +780,7 @@ delay_fragment_task(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
780 | struct Plugin * plugin = cls; | 780 | struct Plugin * plugin = cls; |
781 | plugin->server_write_delay_task = GNUNET_SCHEDULER_NO_TASK; | 781 | plugin->server_write_delay_task = GNUNET_SCHEDULER_NO_TASK; |
782 | 782 | ||
783 | if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) | 783 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) |
784 | return; | 784 | return; |
785 | 785 | ||
786 | // GNUNET_TIME_UNIT_FOREVER_REL is needed to clean up old msg | 786 | // GNUNET_TIME_UNIT_FOREVER_REL is needed to clean up old msg |
@@ -893,8 +893,9 @@ set_next_send(struct Plugin * const plugin) | |||
893 | } | 893 | } |
894 | else | 894 | else |
895 | { | 895 | { |
896 | plugin->server_write_delay_task = GNUNET_SCHEDULER_add_delayed(next_send, | 896 | plugin->server_write_delay_task |
897 | &delay_fragment_task, plugin); | 897 | = GNUNET_SCHEDULER_add_delayed(next_send, |
898 | &delay_fragment_task, plugin); | ||
898 | } | 899 | } |
899 | } | 900 | } |
900 | 901 | ||
@@ -1353,39 +1354,42 @@ send_ack(struct Plugin * plugin, struct AckSendQueue * ack) | |||
1353 | 1354 | ||
1354 | //TODO DOXIGEN | 1355 | //TODO DOXIGEN |
1355 | static void | 1356 | static void |
1356 | finish_sending(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 1357 | finish_sending(void *cls, |
1358 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
1357 | { | 1359 | { |
1358 | struct Finish_send * finish; | 1360 | struct Finish_send * finish = cls; |
1359 | struct Plugin * plugin; | 1361 | struct Plugin * plugin; |
1360 | ssize_t bytes; | 1362 | ssize_t bytes; |
1361 | 1363 | ||
1362 | finish = cls; | ||
1363 | plugin = finish->plugin; | 1364 | plugin = finish->plugin; |
1364 | |||
1365 | plugin->server_write_task = GNUNET_SCHEDULER_NO_TASK; | 1365 | plugin->server_write_task = GNUNET_SCHEDULER_NO_TASK; |
1366 | 1366 | ||
1367 | bytes = GNUNET_DISK_file_write(plugin->server_stdin_handle, | 1367 | if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason)) |
1368 | finish->msgheader, finish->size); | 1368 | { |
1369 | GNUNET_assert(bytes != GNUNET_SYSERR); | 1369 | GNUNET_free (finish->msgstart); |
1370 | GNUNET_free (finish); | ||
1371 | return; | ||
1372 | } | ||
1373 | bytes = GNUNET_DISK_file_write (plugin->server_stdin_handle, | ||
1374 | finish->msgheader, | ||
1375 | finish->size); | ||
1376 | GNUNET_assert (bytes != GNUNET_SYSERR); | ||
1370 | 1377 | ||
1371 | if (bytes != finish->size) | 1378 | if (bytes != finish->size) |
1372 | { | 1379 | { |
1373 | |||
1374 | finish->msgheader = finish->msgheader + bytes; | 1380 | finish->msgheader = finish->msgheader + bytes; |
1375 | finish->size = finish->size - bytes; | 1381 | finish->size = finish->size - bytes; |
1376 | plugin->server_write_task = GNUNET_SCHEDULER_add_write_file( | 1382 | plugin->server_write_task |
1377 | GNUNET_TIME_UNIT_FOREVER_REL, plugin->server_stdin_handle, | 1383 | = GNUNET_SCHEDULER_add_write_file(GNUNET_TIME_UNIT_FOREVER_REL, |
1378 | &finish_sending, finish); | 1384 | plugin->server_stdin_handle, |
1385 | &finish_sending, finish); | ||
1379 | } | 1386 | } |
1380 | else | 1387 | else |
1381 | { | 1388 | { |
1382 | GNUNET_free(finish->msgstart); | 1389 | GNUNET_free(finish->msgstart); |
1383 | GNUNET_free(finish); | 1390 | GNUNET_free(finish); |
1384 | |||
1385 | set_next_send(plugin); | 1391 | set_next_send(plugin); |
1386 | |||
1387 | } | 1392 | } |
1388 | |||
1389 | } | 1393 | } |
1390 | 1394 | ||
1391 | /** | 1395 | /** |
@@ -1397,11 +1401,10 @@ finish_sending(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1397 | static void | 1401 | static void |
1398 | do_transmit(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 1402 | do_transmit(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
1399 | { | 1403 | { |
1400 | |||
1401 | struct Plugin * plugin = cls; | 1404 | struct Plugin * plugin = cls; |
1402 | plugin->server_write_task = GNUNET_SCHEDULER_NO_TASK; | ||
1403 | 1405 | ||
1404 | if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN) | 1406 | plugin->server_write_task = GNUNET_SCHEDULER_NO_TASK; |
1407 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | ||
1405 | return; | 1408 | return; |
1406 | 1409 | ||
1407 | struct Session * session; | 1410 | struct Session * session; |
@@ -1409,7 +1412,6 @@ do_transmit(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1409 | struct ieee80211_frame * ieeewlanheader; | 1412 | struct ieee80211_frame * ieeewlanheader; |
1410 | struct Radiotap_Send * radioHeader; | 1413 | struct Radiotap_Send * radioHeader; |
1411 | struct GNUNET_MessageHeader * msgheader; | 1414 | struct GNUNET_MessageHeader * msgheader; |
1412 | |||
1413 | struct FragmentationHeader fragheader; | 1415 | struct FragmentationHeader fragheader; |
1414 | struct FragmentationHeader * fragheaderptr; | 1416 | struct FragmentationHeader * fragheaderptr; |
1415 | struct Finish_send * finish; | 1417 | struct Finish_send * finish; |
@@ -1435,9 +1437,7 @@ do_transmit(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1435 | if (GNUNET_TIME_absolute_get_remaining(plugin->beacon_time).rel_value == 0) | 1437 | if (GNUNET_TIME_absolute_get_remaining(plugin->beacon_time).rel_value == 0) |
1436 | { | 1438 | { |
1437 | send_hello_beacon(plugin); | 1439 | send_hello_beacon(plugin); |
1438 | |||
1439 | return; | 1440 | return; |
1440 | |||
1441 | } | 1441 | } |
1442 | 1442 | ||
1443 | fm = GNUNET_CONTAINER_heap_peek(plugin->pending_Fragment_Messages); | 1443 | fm = GNUNET_CONTAINER_heap_peek(plugin->pending_Fragment_Messages); |
@@ -1920,20 +1920,14 @@ free_session(struct Plugin * plugin, struct Sessionqueue * queue) | |||
1920 | { | 1920 | { |
1921 | plugin->pendingsessions--; | 1921 | plugin->pendingsessions--; |
1922 | GNUNET_CONTAINER_DLL_remove (plugin->pending_Sessions_head, | 1922 | GNUNET_CONTAINER_DLL_remove (plugin->pending_Sessions_head, |
1923 | plugin->pending_Sessions_tail, pendingsession); | 1923 | plugin->pending_Sessions_tail, |
1924 | pendingsession); | ||
1924 | GNUNET_free(pendingsession); | 1925 | GNUNET_free(pendingsession); |
1925 | 1926 | ||
1926 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1927 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1927 | "Remove session %p from pending session queue\n", queue->content | 1928 | "Remove session %p from pending session queue\n", |
1928 | ); | 1929 | queue->content); |
1929 | 1930 | GNUNET_assert (check == 0); | |
1930 | |||
1931 | if (check == 1) | ||
1932 | { | ||
1933 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | ||
1934 | "Session is more then once in pending session\n"); | ||
1935 | } | ||
1936 | |||
1937 | check = 1; | 1931 | check = 1; |
1938 | } | 1932 | } |
1939 | pendingsession = pendingsession_tmp; | 1933 | pendingsession = pendingsession_tmp; |
@@ -1969,13 +1963,13 @@ free_session(struct Plugin * plugin, struct Sessionqueue * queue) | |||
1969 | GNUNET_free(pm); | 1963 | GNUNET_free(pm); |
1970 | } | 1964 | } |
1971 | 1965 | ||
1972 | GNUNET_CONTAINER_DLL_remove(plugin->sessions, plugin->sessions_tail, queue); | 1966 | GNUNET_CONTAINER_DLL_remove(plugin->sessions, |
1967 | plugin->sessions_tail, | ||
1968 | queue); | ||
1973 | GNUNET_free(queue->content); | 1969 | GNUNET_free(queue->content); |
1974 | GNUNET_free(queue); | 1970 | GNUNET_free(queue); |
1975 | plugin->session_count--; | 1971 | plugin->session_count--; |
1976 | |||
1977 | check_fragment_queue(plugin); | 1972 | check_fragment_queue(plugin); |
1978 | |||
1979 | } | 1973 | } |
1980 | 1974 | ||
1981 | /** | 1975 | /** |
@@ -2046,25 +2040,6 @@ wlan_plugin_address_pretty_printer(void *cls, const char *type, | |||
2046 | asc(asc_cls, ret); | 2040 | asc(asc_cls, ret); |
2047 | } | 2041 | } |
2048 | 2042 | ||
2049 | /** | ||
2050 | * function to check if bitfield is representation of fragments of the message | ||
2051 | * @param rec_message message to check | ||
2052 | */ | ||
2053 | |||
2054 | void | ||
2055 | check_message_fragment_bitfield(struct Receive_Message_Queue * rx_msg) | ||
2056 | { | ||
2057 | uint64_t checkfragments = 0; | ||
2058 | struct Receive_Fragment_Queue * rx_frag = rx_msg->frag_head; | ||
2059 | |||
2060 | while (rx_frag != NULL) | ||
2061 | { | ||
2062 | setBit((char*) &checkfragments, rx_frag->num); | ||
2063 | rx_frag = rx_frag->next; | ||
2064 | |||
2065 | } | ||
2066 | GNUNET_assert(checkfragments == rx_msg->received_fragments); | ||
2067 | } | ||
2068 | 2043 | ||
2069 | /** | 2044 | /** |
2070 | * Function to test if fragment number already exists in the fragments received | 2045 | * Function to test if fragment number already exists in the fragments received |
@@ -2073,8 +2048,7 @@ check_message_fragment_bitfield(struct Receive_Message_Queue * rx_msg) | |||
2073 | * @param fh Fragmentheader of the fragment | 2048 | * @param fh Fragmentheader of the fragment |
2074 | * @return GNUNET_YES if fragment exists already, GNUNET_NO if it does not exists in the queue of the session | 2049 | * @return GNUNET_YES if fragment exists already, GNUNET_NO if it does not exists in the queue of the session |
2075 | */ | 2050 | */ |
2076 | 2051 | static int | |
2077 | static const int | ||
2078 | is_double_msg(struct Receive_Message_Queue * rx_msg, | 2052 | is_double_msg(struct Receive_Message_Queue * rx_msg, |
2079 | struct FragmentationHeader * fh) | 2053 | struct FragmentationHeader * fh) |
2080 | { | 2054 | { |
@@ -2093,7 +2067,6 @@ is_double_msg(struct Receive_Message_Queue * rx_msg, | |||
2093 | * @param session session the fragment belongs to | 2067 | * @param session session the fragment belongs to |
2094 | * @param rec_queue fragment to add | 2068 | * @param rec_queue fragment to add |
2095 | */ | 2069 | */ |
2096 | |||
2097 | static void | 2070 | static void |
2098 | insert_fragment_in_queue(struct Receive_Message_Queue * rx_message, | 2071 | insert_fragment_in_queue(struct Receive_Message_Queue * rx_message, |
2099 | struct Receive_Fragment_Queue * rx_frag) | 2072 | struct Receive_Fragment_Queue * rx_frag) |
@@ -2884,7 +2857,7 @@ wlan_plugin_helper_read(void *cls, | |||
2884 | struct Plugin *plugin = cls; | 2857 | struct Plugin *plugin = cls; |
2885 | plugin->server_read_task = GNUNET_SCHEDULER_NO_TASK; | 2858 | plugin->server_read_task = GNUNET_SCHEDULER_NO_TASK; |
2886 | 2859 | ||
2887 | if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) | 2860 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) |
2888 | return; | 2861 | return; |
2889 | 2862 | ||
2890 | char mybuf[WLAN_MTU + sizeof(struct GNUNET_MessageHeader)]; | 2863 | char mybuf[WLAN_MTU + sizeof(struct GNUNET_MessageHeader)]; |
@@ -2993,7 +2966,31 @@ libgnunet_plugin_transport_wlan_done(void *cls) | |||
2993 | "libgnunet_plugin_transport_wlan_done started\n"); | 2966 | "libgnunet_plugin_transport_wlan_done started\n"); |
2994 | #endif | 2967 | #endif |
2995 | 2968 | ||
2996 | GNUNET_assert(cls !=NULL); | 2969 | GNUNET_assert (cls !=NULL); |
2970 | //free sessions | ||
2971 | while (queue != NULL) | ||
2972 | { | ||
2973 | queue_next = queue->next; | ||
2974 | free_session(plugin, queue); | ||
2975 | queue = queue_next; | ||
2976 | |||
2977 | } | ||
2978 | if (plugin->server_write_delay_task != GNUNET_SCHEDULER_NO_TASK) | ||
2979 | { | ||
2980 | GNUNET_SCHEDULER_cancel(plugin->server_write_delay_task); | ||
2981 | plugin->server_write_delay_task = GNUNET_SCHEDULER_NO_TASK; | ||
2982 | } | ||
2983 | if (plugin->server_write_task != GNUNET_SCHEDULER_NO_TASK) | ||
2984 | { | ||
2985 | GNUNET_SCHEDULER_cancel(plugin->server_write_task); | ||
2986 | plugin->server_write_task = GNUNET_SCHEDULER_NO_TASK; | ||
2987 | } | ||
2988 | if (plugin->server_read_task != GNUNET_SCHEDULER_NO_TASK) | ||
2989 | { | ||
2990 | GNUNET_SCHEDULER_cancel(plugin->server_read_task); | ||
2991 | plugin->server_read_task = GNUNET_SCHEDULER_NO_TASK; | ||
2992 | } | ||
2993 | |||
2997 | 2994 | ||
2998 | if (plugin->suid_tokenizer != NULL) | 2995 | if (plugin->suid_tokenizer != NULL) |
2999 | GNUNET_SERVER_mst_destroy(plugin->suid_tokenizer); | 2996 | GNUNET_SERVER_mst_destroy(plugin->suid_tokenizer); |
@@ -3014,15 +3011,6 @@ libgnunet_plugin_transport_wlan_done(void *cls) | |||
3014 | plugin->pending_Fragment_Messages); | 3011 | plugin->pending_Fragment_Messages); |
3015 | } | 3012 | } |
3016 | 3013 | ||
3017 | //free sessions | ||
3018 | while (queue != NULL) | ||
3019 | { | ||
3020 | queue_next = queue->next; | ||
3021 | free_session(plugin, queue); | ||
3022 | queue = queue_next; | ||
3023 | |||
3024 | } | ||
3025 | |||
3026 | GNUNET_free_non_null(plugin->interface); | 3014 | GNUNET_free_non_null(plugin->interface); |
3027 | GNUNET_CONTAINER_heap_destroy(plugin->pending_Fragment_Messages); | 3015 | GNUNET_CONTAINER_heap_destroy(plugin->pending_Fragment_Messages); |
3028 | GNUNET_free (plugin); | 3016 | GNUNET_free (plugin); |