aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2009-11-08 21:04:18 +0000
committerChristian Grothoff <christian@grothoff.org>2009-11-08 21:04:18 +0000
commit74ae43d6c88f18a795ee9e5aee6a7e211e6ba964 (patch)
tree9b8bd0a701a78e0888d6095d289793810c648794 /src
parent423523a8c32a35988f83dda2c3c362178e7e0c2f (diff)
downloadgnunet-74ae43d6c88f18a795ee9e5aee6a7e211e6ba964.tar.gz
gnunet-74ae43d6c88f18a795ee9e5aee6a7e211e6ba964.zip
reducing leaks, fixing shutdown bug, increasing timeouts
Diffstat (limited to 'src')
-rw-r--r--src/core/test_core_api.c2
-rw-r--r--src/datastore/test_datastore_api_management.c2
-rw-r--r--src/fs/fs_file_information.c7
-rw-r--r--src/fs/fs_tree.c11
-rw-r--r--src/fs/test_fs_download.c2
-rw-r--r--src/fs/test_fs_list_indexed.c2
-rw-r--r--src/fs/test_fs_publish.c2
-rw-r--r--src/fs/test_fs_search.c2
-rw-r--r--src/fs/test_fs_unindex.c2
-rw-r--r--src/include/gnunet_client_lib.h3
-rw-r--r--src/transport/test_transport_api.c2
-rw-r--r--src/util/client.c205
12 files changed, 134 insertions, 108 deletions
diff --git a/src/core/test_core_api.c b/src/core/test_core_api.c
index ebd4e8e99..6ad396415 100644
--- a/src/core/test_core_api.c
+++ b/src/core/test_core_api.c
@@ -42,7 +42,7 @@
42/** 42/**
43 * How long until we give up on transmitting the message? 43 * How long until we give up on transmitting the message?
44 */ 44 */
45#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15) 45#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60)
46 46
47#define MTYPE 12345 47#define MTYPE 12345
48 48
diff --git a/src/datastore/test_datastore_api_management.c b/src/datastore/test_datastore_api_management.c
index cad789a6f..a889f7c1c 100644
--- a/src/datastore/test_datastore_api_management.c
+++ b/src/datastore/test_datastore_api_management.c
@@ -33,7 +33,7 @@
33/** 33/**
34 * How long until we give up on transmitting the message? 34 * How long until we give up on transmitting the message?
35 */ 35 */
36#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15) 36#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60)
37 37
38/** 38/**
39 * Number of iterations to run; must be large enough 39 * Number of iterations to run; must be large enough
diff --git a/src/fs/fs_file_information.c b/src/fs/fs_file_information.c
index 2f8bbbdc9..c28635198 100644
--- a/src/fs/fs_file_information.c
+++ b/src/fs/fs_file_information.c
@@ -32,6 +32,7 @@
32#include <extractor.h> 32#include <extractor.h>
33#include "gnunet_fs_service.h" 33#include "gnunet_fs_service.h"
34#include "fs.h" 34#include "fs.h"
35#include "fs_tree.h"
35 36
36 37
37/** 38/**
@@ -849,6 +850,12 @@ GNUNET_FS_file_information_destroy (struct GNUNET_FS_FileInformation *fi,
849 GNUNET_FS_uri_destroy (fi->keywords); 850 GNUNET_FS_uri_destroy (fi->keywords);
850 GNUNET_CONTAINER_meta_data_destroy (fi->meta); 851 GNUNET_CONTAINER_meta_data_destroy (fi->meta);
851 GNUNET_free_non_null (fi->serialization); 852 GNUNET_free_non_null (fi->serialization);
853 if (fi->te != NULL)
854 {
855 GNUNET_FS_tree_encoder_finish (fi->te,
856 NULL, NULL);
857 fi->te = NULL;
858 }
852 GNUNET_free (fi); 859 GNUNET_free (fi);
853} 860}
854 861
diff --git a/src/fs/fs_tree.c b/src/fs/fs_tree.c
index 4d15d78f3..07f78eea7 100644
--- a/src/fs/fs_tree.c
+++ b/src/fs/fs_tree.c
@@ -385,8 +385,15 @@ void GNUNET_FS_tree_encoder_finish (struct GNUNET_FS_TreeEncoder * te,
385 struct GNUNET_FS_Uri **uri, 385 struct GNUNET_FS_Uri **uri,
386 char **emsg) 386 char **emsg)
387{ 387{
388 *uri = te->uri; 388 if (uri != NULL)
389 *emsg = te->emsg; 389 *uri = te->uri;
390 else
391 if (NULL != te->uri)
392 GNUNET_FS_uri_destroy (te->uri);
393 if (emsg != NULL)
394 *emsg = te->emsg;
395 else
396 GNUNET_free_non_null (te->emsg);
390 GNUNET_free (te->chk_tree); 397 GNUNET_free (te->chk_tree);
391 GNUNET_free (te); 398 GNUNET_free (te);
392} 399}
diff --git a/src/fs/test_fs_download.c b/src/fs/test_fs_download.c
index f3ecfaba0..4b940e8dc 100644
--- a/src/fs/test_fs_download.c
+++ b/src/fs/test_fs_download.c
@@ -41,7 +41,7 @@
41/** 41/**
42 * How long until we give up on transmitting the message? 42 * How long until we give up on transmitting the message?
43 */ 43 */
44#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15) 44#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60)
45 45
46/** 46/**
47 * How long should our test-content live? 47 * How long should our test-content live?
diff --git a/src/fs/test_fs_list_indexed.c b/src/fs/test_fs_list_indexed.c
index f9225e3ce..ba0906c81 100644
--- a/src/fs/test_fs_list_indexed.c
+++ b/src/fs/test_fs_list_indexed.c
@@ -45,7 +45,7 @@
45/** 45/**
46 * How long until we give up on transmitting the message? 46 * How long until we give up on transmitting the message?
47 */ 47 */
48#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15) 48#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60)
49 49
50/** 50/**
51 * How long should our test-content live? 51 * How long should our test-content live?
diff --git a/src/fs/test_fs_publish.c b/src/fs/test_fs_publish.c
index a7bcd48d9..46a2dc3da 100644
--- a/src/fs/test_fs_publish.c
+++ b/src/fs/test_fs_publish.c
@@ -42,7 +42,7 @@
42/** 42/**
43 * How long until we give up on transmitting the message? 43 * How long until we give up on transmitting the message?
44 */ 44 */
45#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15) 45#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60)
46 46
47/** 47/**
48 * How long should our test-content live? 48 * How long should our test-content live?
diff --git a/src/fs/test_fs_search.c b/src/fs/test_fs_search.c
index e0961c4a7..2ef323317 100644
--- a/src/fs/test_fs_search.c
+++ b/src/fs/test_fs_search.c
@@ -41,7 +41,7 @@
41/** 41/**
42 * How long until we give up on transmitting the message? 42 * How long until we give up on transmitting the message?
43 */ 43 */
44#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15) 44#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60)
45 45
46/** 46/**
47 * How long should our test-content live? 47 * How long should our test-content live?
diff --git a/src/fs/test_fs_unindex.c b/src/fs/test_fs_unindex.c
index af9db7400..4c751c9a6 100644
--- a/src/fs/test_fs_unindex.c
+++ b/src/fs/test_fs_unindex.c
@@ -41,7 +41,7 @@
41/** 41/**
42 * How long until we give up on transmitting the message? 42 * How long until we give up on transmitting the message?
43 */ 43 */
44#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15) 44#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60)
45 45
46/** 46/**
47 * How long should our test-content live? 47 * How long should our test-content live?
diff --git a/src/include/gnunet_client_lib.h b/src/include/gnunet_client_lib.h
index 3773a55d1..b2311e870 100644
--- a/src/include/gnunet_client_lib.h
+++ b/src/include/gnunet_client_lib.h
@@ -70,7 +70,8 @@ struct GNUNET_CLIENT_Connection *GNUNET_CLIENT_connect (struct
70 * transmission request will also be cancelled UNLESS the callback for 70 * transmission request will also be cancelled UNLESS the callback for
71 * the transmission request has already been called, in which case the 71 * the transmission request has already been called, in which case the
72 * transmission is guaranteed to complete before the socket is fully 72 * transmission is guaranteed to complete before the socket is fully
73 * destroyed. 73 * destroyed (unless, of course, there is an error with the server
74 * in which case the message may still be lost).
74 * 75 *
75 * @param sock handle to the service connection 76 * @param sock handle to the service connection
76 */ 77 */
diff --git a/src/transport/test_transport_api.c b/src/transport/test_transport_api.c
index 57ab52e4b..36264051d 100644
--- a/src/transport/test_transport_api.c
+++ b/src/transport/test_transport_api.c
@@ -40,7 +40,7 @@
40/** 40/**
41 * How long until we give up on transmitting the message? 41 * How long until we give up on transmitting the message?
42 */ 42 */
43#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) 43#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60)
44 44
45#define MTYPE 12345 45#define MTYPE 12345
46 46
diff --git a/src/util/client.c b/src/util/client.c
index 664b06271..a1ef36496 100644
--- a/src/util/client.c
+++ b/src/util/client.c
@@ -72,15 +72,15 @@ struct GNUNET_CLIENT_TransmitHandle
72 struct GNUNET_CONNECTION_TransmitHandle *th; 72 struct GNUNET_CONNECTION_TransmitHandle *th;
73 73
74 /** 74 /**
75 * Timeout. 75 * If we are re-trying and are delaying to do so,
76 * handle to the scheduled task managing the delay.
76 */ 77 */
77 struct GNUNET_TIME_Absolute timeout; 78 GNUNET_SCHEDULER_TaskIdentifier reconnect_task;
78 79
79 /** 80 /**
80 * If we are re-trying and are delaying to do so, 81 * Timeout.
81 * handle to the scheduled task managing the delay.
82 */ 82 */
83 GNUNET_SCHEDULER_TaskIdentifier task; 83 struct GNUNET_TIME_Absolute timeout;
84 84
85 /** 85 /**
86 * Number of bytes requested. 86 * Number of bytes requested.
@@ -104,6 +104,39 @@ struct GNUNET_CLIENT_TransmitHandle
104}; 104};
105 105
106 106
107/**
108 * Context for processing
109 * "GNUNET_CLIENT_transmit_and_get_response" requests.
110 */
111struct TransmitGetResponseContext
112{
113 /**
114 * Client handle.
115 */
116 struct GNUNET_CLIENT_Connection *sock;
117
118 /**
119 * Message to transmit; do not free, allocated
120 * right after this struct.
121 */
122 const struct GNUNET_MessageHeader *hdr;
123
124 /**
125 * Timeout to use.
126 */
127 struct GNUNET_TIME_Absolute timeout;
128
129 /**
130 * Function to call when done.
131 */
132 GNUNET_CLIENT_MessageHandler rn;
133
134 /**
135 * Closure for "rn".
136 */
137 void *rn_cls;
138};
139
107 140
108/** 141/**
109 * Struct to refer to a GNUnet TCP connection. 142 * Struct to refer to a GNUnet TCP connection.
@@ -135,6 +168,12 @@ struct GNUNET_CLIENT_Connection
135 char *service_name; 168 char *service_name;
136 169
137 /** 170 /**
171 * Context of a transmit_and_get_response operation, NULL
172 * if no such operation is pending.
173 */
174 struct TransmitGetResponseContext *tag;
175
176 /**
138 * Handler for current receiver task. 177 * Handler for current receiver task.
139 */ 178 */
140 GNUNET_CLIENT_MessageHandler receiver_handler; 179 GNUNET_CLIENT_MessageHandler receiver_handler;
@@ -156,6 +195,12 @@ struct GNUNET_CLIENT_Connection
156 GNUNET_SCHEDULER_Task test_cb; 195 GNUNET_SCHEDULER_Task test_cb;
157 196
158 /** 197 /**
198 * If we are re-trying and are delaying to do so,
199 * handle to the scheduled task managing the delay.
200 */
201 GNUNET_SCHEDULER_TaskIdentifier receive_task;
202
203 /**
159 * Closure for test_cb (NULL unless in service_test) 204 * Closure for test_cb (NULL unless in service_test)
160 */ 205 */
161 void *test_cb_cls; 206 void *test_cb_cls;
@@ -187,9 +232,7 @@ struct GNUNET_CLIENT_Connection
187 232
188 /** 233 /**
189 * Are we currently busy doing receive-processing? 234 * Are we currently busy doing receive-processing?
190 * GNUNET_YES if so, GNUNET_NO if not, GNUNET_SYSERR 235 * GNUNET_YES if so, GNUNET_NO if not.
191 * if the handle should be destroyed as soon as the
192 * receive processing is done.
193 */ 236 */
194 int in_receive; 237 int in_receive;
195 238
@@ -269,31 +312,14 @@ GNUNET_CLIENT_connect (struct GNUNET_SCHEDULER_Handle *sched,
269 312
270 313
271/** 314/**
272 * Receiver task has completed, free rest of client
273 * data structures.
274 */
275static void
276finish_cleanup (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
277{
278 struct GNUNET_CLIENT_Connection *sock = cls;
279
280 if (sock->th != NULL)
281 GNUNET_CLIENT_notify_transmit_ready_cancel (sock->th);
282 GNUNET_array_grow (sock->received_buf, sock->received_size, 0);
283 GNUNET_free (sock->service_name);
284 GNUNET_CONFIGURATION_destroy (sock->cfg);
285 GNUNET_free (sock);
286}
287
288
289/**
290 * Destroy connection with the service. This will automatically 315 * Destroy connection with the service. This will automatically
291 * cancel any pending "receive" request (however, the handler will 316 * cancel any pending "receive" request (however, the handler will
292 * *NOT* be called, not even with a NULL message). Any pending 317 * *NOT* be called, not even with a NULL message). Any pending
293 * transmission request will also be cancelled UNLESS the callback for 318 * transmission request will also be cancelled UNLESS the callback for
294 * the transmission request has already been called, in which case the 319 * the transmission request has already been called, in which case the
295 * transmission is guaranteed to complete before the socket is fully 320 * transmission is guaranteed to complete before the socket is fully
296 * destroyed. 321 * destroyed (unless, of course, there is an error with the server
322 * in which case the message may still be lost).
297 * 323 *
298 * @param sock handle to the service connection 324 * @param sock handle to the service connection
299 */ 325 */
@@ -301,15 +327,31 @@ void
301GNUNET_CLIENT_disconnect (struct GNUNET_CLIENT_Connection *sock) 327GNUNET_CLIENT_disconnect (struct GNUNET_CLIENT_Connection *sock)
302{ 328{
303 GNUNET_assert (sock->sock != NULL); 329 GNUNET_assert (sock->sock != NULL);
330 if (sock->in_receive == GNUNET_YES)
331 {
332 GNUNET_CONNECTION_receive_cancel (sock->sock);
333 sock->in_receive = GNUNET_NO;
334 }
304 GNUNET_CONNECTION_destroy (sock->sock); 335 GNUNET_CONNECTION_destroy (sock->sock);
305 sock->sock = NULL; 336 sock->sock = NULL;
337 if (sock->tag != NULL)
338 {
339 GNUNET_free (sock->tag);
340 sock->tag = NULL;
341 }
306 sock->receiver_handler = NULL; 342 sock->receiver_handler = NULL;
307 if (sock->in_receive == GNUNET_YES) 343 if (sock->th != NULL)
308 sock->in_receive = GNUNET_SYSERR; 344 GNUNET_CLIENT_notify_transmit_ready_cancel (sock->th);
309 else 345 if (sock->receive_task != GNUNET_SCHEDULER_NO_TASK)
310 GNUNET_SCHEDULER_add_after (sock->sched, 346 {
311 GNUNET_SCHEDULER_NO_TASK, 347 GNUNET_SCHEDULER_cancel (sock->sched,
312 &finish_cleanup, sock); 348 sock->receive_task);
349 sock->receive_task = GNUNET_SCHEDULER_NO_TASK;
350 }
351 GNUNET_array_grow (sock->received_buf, sock->received_size, 0);
352 GNUNET_free (sock->service_name);
353 GNUNET_CONFIGURATION_destroy (sock->cfg);
354 GNUNET_free (sock);
313} 355}
314 356
315 357
@@ -349,10 +391,6 @@ receive_helper (void *cls,
349 struct GNUNET_TIME_Relative remaining; 391 struct GNUNET_TIME_Relative remaining;
350 392
351 GNUNET_assert (conn->msg_complete == GNUNET_NO); 393 GNUNET_assert (conn->msg_complete == GNUNET_NO);
352 if (GNUNET_SYSERR == conn->in_receive)
353 GNUNET_SCHEDULER_add_after (conn->sched,
354 GNUNET_SCHEDULER_NO_TASK,
355 &finish_cleanup, conn);
356 conn->in_receive = GNUNET_NO; 394 conn->in_receive = GNUNET_NO;
357 if ((available == 0) || (conn->sock == NULL) || (errCode != 0)) 395 if ((available == 0) || (conn->sock == NULL) || (errCode != 0))
358 { 396 {
@@ -393,24 +431,23 @@ receive_helper (void *cls,
393 431
394/** 432/**
395 * Continuation to call the receive callback. 433 * Continuation to call the receive callback.
434 *
435 * @param cls our handle to the client connection
436 * @param tc scheduler context
396 */ 437 */
397static void 438static void
398receive_task (void *scls, const struct GNUNET_SCHEDULER_TaskContext *tc) 439receive_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
399{ 440{
400 struct GNUNET_CLIENT_Connection *sock = scls; 441 struct GNUNET_CLIENT_Connection *sock = cls;
401 GNUNET_CLIENT_MessageHandler handler = sock->receiver_handler; 442 GNUNET_CLIENT_MessageHandler handler = sock->receiver_handler;
402 const struct GNUNET_MessageHeader *cmsg = 443 const struct GNUNET_MessageHeader *cmsg =
403 (const struct GNUNET_MessageHeader *) sock->received_buf; 444 (const struct GNUNET_MessageHeader *) sock->received_buf;
404 void *cls = sock->receiver_handler_cls; 445 void *handler_cls = sock->receiver_handler_cls;
405 uint16_t msize = ntohs (cmsg->size); 446 uint16_t msize = ntohs (cmsg->size);
406 char mbuf[msize]; 447 char mbuf[msize];
407 struct GNUNET_MessageHeader *msg = (struct GNUNET_MessageHeader *) mbuf; 448 struct GNUNET_MessageHeader *msg = (struct GNUNET_MessageHeader *) mbuf;
408 449
409 if (GNUNET_SYSERR == sock->in_receive) 450 sock->receive_task = GNUNET_SCHEDULER_NO_TASK;
410 GNUNET_SCHEDULER_add_after (sock->sched,
411 GNUNET_SCHEDULER_NO_TASK,
412 &finish_cleanup, sock);
413 sock->in_receive = GNUNET_NO;
414 GNUNET_assert (GNUNET_YES == sock->msg_complete); 451 GNUNET_assert (GNUNET_YES == sock->msg_complete);
415 GNUNET_assert (sock->received_pos >= msize); 452 GNUNET_assert (sock->received_pos >= msize);
416 memcpy (msg, cmsg, msize); 453 memcpy (msg, cmsg, msize);
@@ -421,7 +458,7 @@ receive_task (void *scls, const struct GNUNET_SCHEDULER_TaskContext *tc)
421 sock->receiver_handler = NULL; 458 sock->receiver_handler = NULL;
422 check_complete (sock); 459 check_complete (sock);
423 if (handler != NULL) 460 if (handler != NULL)
424 handler (cls, msg); 461 handler (handler_cls, msg);
425} 462}
426 463
427 464
@@ -448,15 +485,19 @@ GNUNET_CLIENT_receive (struct GNUNET_CLIENT_Connection *sock,
448 sock->receiver_handler = handler; 485 sock->receiver_handler = handler;
449 sock->receiver_handler_cls = handler_cls; 486 sock->receiver_handler_cls = handler_cls;
450 sock->receive_timeout = GNUNET_TIME_relative_to_absolute (timeout); 487 sock->receive_timeout = GNUNET_TIME_relative_to_absolute (timeout);
451 sock->in_receive = GNUNET_YES;
452 if (GNUNET_YES == sock->msg_complete) 488 if (GNUNET_YES == sock->msg_complete)
453 GNUNET_SCHEDULER_add_after (sock->sched, 489 {
454 GNUNET_SCHEDULER_NO_TASK, 490 sock->receive_task = GNUNET_SCHEDULER_add_after (sock->sched,
455 &receive_task, sock); 491 GNUNET_SCHEDULER_NO_TASK,
492 &receive_task, sock);
493 }
456 else 494 else
457 GNUNET_CONNECTION_receive (sock->sock, 495 {
458 GNUNET_SERVER_MAX_MESSAGE_SIZE, 496 sock->in_receive = GNUNET_YES;
459 timeout, &receive_helper, sock); 497 GNUNET_CONNECTION_receive (sock->sock,
498 GNUNET_SERVER_MAX_MESSAGE_SIZE,
499 timeout, &receive_helper, sock);
500 }
460} 501}
461 502
462 503
@@ -657,7 +698,7 @@ client_delayed_retry (void *cls,
657{ 698{
658 struct GNUNET_CLIENT_TransmitHandle *th = cls; 699 struct GNUNET_CLIENT_TransmitHandle *th = cls;
659 700
660 th->task = GNUNET_SCHEDULER_NO_TASK; 701 th->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
661 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) 702 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
662 { 703 {
663#if DEBUG_CLIENT 704#if DEBUG_CLIENT
@@ -733,9 +774,9 @@ client_notify (void *cls, size_t size, void *buf)
733 MAX_ATTEMPTS - th->attempts_left, 774 MAX_ATTEMPTS - th->attempts_left,
734 (unsigned long long) delay.value); 775 (unsigned long long) delay.value);
735#endif 776#endif
736 th->task = GNUNET_SCHEDULER_add_delayed (th->sock->sched, 777 th->reconnect_task = GNUNET_SCHEDULER_add_delayed (th->sock->sched,
737 delay, 778 delay,
738 &client_delayed_retry, th); 779 &client_delayed_retry, th);
739 th->sock->th = th; 780 th->sock->th = th;
740 return 0; 781 return 0;
741 } 782 }
@@ -809,10 +850,11 @@ void
809GNUNET_CLIENT_notify_transmit_ready_cancel (struct 850GNUNET_CLIENT_notify_transmit_ready_cancel (struct
810 GNUNET_CLIENT_TransmitHandle *th) 851 GNUNET_CLIENT_TransmitHandle *th)
811{ 852{
812 if (th->task != GNUNET_SCHEDULER_NO_TASK) 853 if (th->reconnect_task != GNUNET_SCHEDULER_NO_TASK)
813 { 854 {
814 GNUNET_break (NULL == th->th); 855 GNUNET_break (NULL == th->th);
815 GNUNET_SCHEDULER_cancel (th->sock->sched, th->task); 856 GNUNET_SCHEDULER_cancel (th->sock->sched, th->reconnect_task);
857 th->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
816 } 858 }
817 else 859 else
818 { 860 {
@@ -825,46 +867,12 @@ GNUNET_CLIENT_notify_transmit_ready_cancel (struct
825 867
826 868
827/** 869/**
828 * Context for processing
829 * "GNUNET_CLIENT_transmit_and_get_response" requests.
830 */
831struct TARCtx
832{
833 /**
834 * Client handle.
835 */
836 struct GNUNET_CLIENT_Connection *sock;
837
838 /**
839 * Message to transmit; do not free, allocated
840 * right after this struct.
841 */
842 const struct GNUNET_MessageHeader *hdr;
843
844 /**
845 * Timeout to use.
846 */
847 struct GNUNET_TIME_Absolute timeout;
848
849 /**
850 * Function to call when done.
851 */
852 GNUNET_CLIENT_MessageHandler rn;
853
854 /**
855 * Closure for "rn".
856 */
857 void *rn_cls;
858};
859
860
861/**
862 * Function called to notify a client about the socket 870 * Function called to notify a client about the socket
863 * begin ready to queue the message. "buf" will be 871 * begin ready to queue the message. "buf" will be
864 * NULL and "size" zero if the socket was closed for 872 * NULL and "size" zero if the socket was closed for
865 * writing in the meantime. 873 * writing in the meantime.
866 * 874 *
867 * @param cls closure of type "struct TARCtx*" 875 * @param cls closure of type "struct TransmitGetResponseContext*"
868 * @param size number of bytes available in buf 876 * @param size number of bytes available in buf
869 * @param buf where the callee should write the message 877 * @param buf where the callee should write the message
870 * @return number of bytes written to buf 878 * @return number of bytes written to buf
@@ -872,9 +880,10 @@ struct TARCtx
872static size_t 880static size_t
873transmit_for_response (void *cls, size_t size, void *buf) 881transmit_for_response (void *cls, size_t size, void *buf)
874{ 882{
875 struct TARCtx *tc = cls; 883 struct TransmitGetResponseContext *tc = cls;
876 uint16_t msize; 884 uint16_t msize;
877 885
886 tc->sock->tag = NULL;
878 msize = ntohs (tc->hdr->size); 887 msize = ntohs (tc->hdr->size);
879 if (NULL == buf) 888 if (NULL == buf)
880 { 889 {
@@ -924,13 +933,14 @@ GNUNET_CLIENT_transmit_and_get_response (struct GNUNET_CLIENT_Connection
924 GNUNET_CLIENT_MessageHandler rn, 933 GNUNET_CLIENT_MessageHandler rn,
925 void *rn_cls) 934 void *rn_cls)
926{ 935{
927 struct TARCtx *tc; 936 struct TransmitGetResponseContext *tc;
928 uint16_t msize; 937 uint16_t msize;
929 938
930 if (NULL != sock->th) 939 if (NULL != sock->th)
931 return GNUNET_SYSERR; 940 return GNUNET_SYSERR;
941 GNUNET_assert (sock->tag == NULL);
932 msize = ntohs (hdr->size); 942 msize = ntohs (hdr->size);
933 tc = GNUNET_malloc (sizeof (struct TARCtx) + msize); 943 tc = GNUNET_malloc (sizeof (struct TransmitGetResponseContext) + msize);
934 tc->sock = sock; 944 tc->sock = sock;
935 tc->hdr = (const struct GNUNET_MessageHeader *) &tc[1]; 945 tc->hdr = (const struct GNUNET_MessageHeader *) &tc[1];
936 memcpy (&tc[1], hdr, msize); 946 memcpy (&tc[1], hdr, msize);
@@ -948,6 +958,7 @@ GNUNET_CLIENT_transmit_and_get_response (struct GNUNET_CLIENT_Connection
948 GNUNET_free (tc); 958 GNUNET_free (tc);
949 return GNUNET_SYSERR; 959 return GNUNET_SYSERR;
950 } 960 }
961 sock->tag = tc;
951 return GNUNET_OK; 962 return GNUNET_OK;
952} 963}
953 964