diff options
author | Christian Grothoff <christian@grothoff.org> | 2010-02-22 10:05:24 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2010-02-22 10:05:24 +0000 |
commit | ac67c32972aeeb32bff943b9a95448688a3c7543 (patch) | |
tree | 3371814fd536b4ad14e1dc56fb0b13687d00ec97 /src | |
parent | d769849a484883fe973014fea696dc81f7687c3c (diff) | |
download | gnunet-ac67c32972aeeb32bff943b9a95448688a3c7543.tar.gz gnunet-ac67c32972aeeb32bff943b9a95448688a3c7543.zip |
better cleanup
Diffstat (limited to 'src')
-rw-r--r-- | src/datastore/gnunet-service-datastore.c | 79 |
1 files changed, 73 insertions, 6 deletions
diff --git a/src/datastore/gnunet-service-datastore.c b/src/datastore/gnunet-service-datastore.c index b9d82fdc2..8a3510946 100644 --- a/src/datastore/gnunet-service-datastore.c +++ b/src/datastore/gnunet-service-datastore.c | |||
@@ -174,12 +174,31 @@ typedef void (*TransmitContinuation)(void *cls, | |||
174 | int status); | 174 | int status); |
175 | 175 | ||
176 | 176 | ||
177 | /** | ||
178 | * Context for transmitting replies to clients. | ||
179 | */ | ||
177 | struct TransmitCallbackContext | 180 | struct TransmitCallbackContext |
178 | { | 181 | { |
182 | |||
183 | /** | ||
184 | * We keep these in a doubly-linked list (for cleanup). | ||
185 | */ | ||
186 | struct TransmitCallbackContext *next; | ||
187 | |||
188 | /** | ||
189 | * We keep these in a doubly-linked list (for cleanup). | ||
190 | */ | ||
191 | struct TransmitCallbackContext *prev; | ||
192 | |||
179 | /** | 193 | /** |
180 | * The message that we're asked to transmit. | 194 | * The message that we're asked to transmit. |
181 | */ | 195 | */ |
182 | struct GNUNET_MessageHeader *msg; | 196 | struct GNUNET_MessageHeader *msg; |
197 | |||
198 | /** | ||
199 | * Handle for the transmission request. | ||
200 | */ | ||
201 | struct GNUNET_CONNECTION_TransmitHandle *th; | ||
183 | 202 | ||
184 | /** | 203 | /** |
185 | * Client that we are transmitting to. | 204 | * Client that we are transmitting to. |
@@ -204,6 +223,17 @@ struct TransmitCallbackContext | |||
204 | int end; | 223 | int end; |
205 | }; | 224 | }; |
206 | 225 | ||
226 | |||
227 | /** | ||
228 | * Head of the doubly-linked list (for cleanup). | ||
229 | */ | ||
230 | static struct TransmitCallbackContext *tcc_head; | ||
231 | |||
232 | /** | ||
233 | * Tail of the doubly-linked list (for cleanup). | ||
234 | */ | ||
235 | static struct TransmitCallbackContext *tcc_tail; | ||
236 | |||
207 | 237 | ||
208 | /** | 238 | /** |
209 | * Task that is used to remove expired entries from | 239 | * Task that is used to remove expired entries from |
@@ -410,6 +440,10 @@ transmit_callback (void *cls, | |||
410 | struct TransmitCallbackContext *tcc = cls; | 440 | struct TransmitCallbackContext *tcc = cls; |
411 | size_t msize; | 441 | size_t msize; |
412 | 442 | ||
443 | tcc->th = NULL; | ||
444 | GNUNET_CONTAINER_DLL_remove (tcc_head, | ||
445 | tcc_tail, | ||
446 | tcc); | ||
413 | msize = ntohs(tcc->msg->size); | 447 | msize = ntohs(tcc->msg->size); |
414 | if (size == 0) | 448 | if (size == 0) |
415 | { | 449 | { |
@@ -474,13 +508,12 @@ transmit (struct GNUNET_SERVER_Client *client, | |||
474 | tcc->tc = tc; | 508 | tcc->tc = tc; |
475 | tcc->tc_cls = tc_cls; | 509 | tcc->tc_cls = tc_cls; |
476 | tcc->end = end; | 510 | tcc->end = end; |
477 | |||
478 | if (NULL == | 511 | if (NULL == |
479 | GNUNET_SERVER_notify_transmit_ready (client, | 512 | (tcc->th = GNUNET_SERVER_notify_transmit_ready (client, |
480 | ntohs(msg->size), | 513 | ntohs(msg->size), |
481 | GNUNET_TIME_UNIT_FOREVER_REL, | 514 | GNUNET_TIME_UNIT_FOREVER_REL, |
482 | &transmit_callback, | 515 | &transmit_callback, |
483 | tcc)) | 516 | tcc))) |
484 | { | 517 | { |
485 | GNUNET_break (0); | 518 | GNUNET_break (0); |
486 | if (GNUNET_YES == end) | 519 | if (GNUNET_YES == end) |
@@ -496,6 +529,9 @@ transmit (struct GNUNET_SERVER_Client *client, | |||
496 | GNUNET_free (msg); | 529 | GNUNET_free (msg); |
497 | GNUNET_free (tcc); | 530 | GNUNET_free (tcc); |
498 | } | 531 | } |
532 | GNUNET_CONTAINER_DLL_insert (tcc_head, | ||
533 | tcc_tail, | ||
534 | tcc); | ||
499 | } | 535 | } |
500 | 536 | ||
501 | 537 | ||
@@ -1260,6 +1296,36 @@ cleanup_reservations (void *cls, | |||
1260 | 1296 | ||
1261 | 1297 | ||
1262 | /** | 1298 | /** |
1299 | * Function that removes all active reservations made | ||
1300 | * by the given client and releases the space for other | ||
1301 | * requests. | ||
1302 | * | ||
1303 | * @param cls closure | ||
1304 | * @param client identification of the client | ||
1305 | */ | ||
1306 | static void | ||
1307 | cleanup_transmits (void *cls, | ||
1308 | struct GNUNET_SERVER_Client | ||
1309 | * client) | ||
1310 | { | ||
1311 | struct TransmitCallbackContext *tcc; | ||
1312 | |||
1313 | while (NULL != (tcc = tcc_head)) | ||
1314 | { | ||
1315 | GNUNET_CONTAINER_DLL_remove (tcc_head, | ||
1316 | tcc_tail, | ||
1317 | tcc); | ||
1318 | if (tcc->th != NULL) | ||
1319 | GNUNET_CONNECTION_notify_transmit_ready_cancel (tcc->th); | ||
1320 | GNUNET_free (tcc->msg); | ||
1321 | GNUNET_free (tcc); | ||
1322 | } | ||
1323 | |||
1324 | } | ||
1325 | |||
1326 | |||
1327 | |||
1328 | /** | ||
1263 | * Process datastore requests. | 1329 | * Process datastore requests. |
1264 | * | 1330 | * |
1265 | * @param cls closure | 1331 | * @param cls closure |
@@ -1323,6 +1389,7 @@ run (void *cls, | |||
1323 | return; | 1389 | return; |
1324 | } | 1390 | } |
1325 | GNUNET_SERVER_disconnect_notify (server, &cleanup_reservations, NULL); | 1391 | GNUNET_SERVER_disconnect_notify (server, &cleanup_reservations, NULL); |
1392 | GNUNET_SERVER_disconnect_notify (server, &cleanup_transmits, NULL); | ||
1326 | GNUNET_SERVER_add_handlers (server, handlers); | 1393 | GNUNET_SERVER_add_handlers (server, handlers); |
1327 | expired_kill_task | 1394 | expired_kill_task |
1328 | = GNUNET_SCHEDULER_add_with_priority (sched, | 1395 | = GNUNET_SCHEDULER_add_with_priority (sched, |