diff options
author | Christian Grothoff <christian@grothoff.org> | 2014-11-27 11:56:28 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2014-11-27 11:56:28 +0000 |
commit | ce9b32618b6ee488352ef0eb506c744868145f82 (patch) | |
tree | dde0f1de9dfec7d3814a29cfb5b252a79a64d726 /src/set/set_api.c | |
parent | 2b0e3f9ba871095d003fc078eee75b5eda6fc8b8 (diff) | |
download | gnunet-ce9b32618b6ee488352ef0eb506c744868145f82.tar.gz gnunet-ce9b32618b6ee488352ef0eb506c744868145f82.zip |
clean up internal set API, avoid copying context message needlessly
Diffstat (limited to 'src/set/set_api.c')
-rw-r--r-- | src/set/set_api.c | 43 |
1 files changed, 24 insertions, 19 deletions
diff --git a/src/set/set_api.c b/src/set/set_api.c index ff0c959e4..90cba446c 100644 --- a/src/set/set_api.c +++ b/src/set/set_api.c | |||
@@ -402,18 +402,16 @@ set_destroy (struct GNUNET_SET_Handle *set) | |||
402 | } | 402 | } |
403 | 403 | ||
404 | 404 | ||
405 | |||
406 | |||
407 | /** | 405 | /** |
408 | * Cancel the given set operation. We need to send an explicit cancel message, | 406 | * Cancel the given set operation. We need to send an explicit cancel message, |
409 | * as all operations one one set communicate using one handle. | 407 | * as all operations one one set communicate using one handle. |
410 | * | 408 | * |
411 | * In contrast to GNUNET_SET_operation_cancel, this function indicates whether | 409 | * In contrast to #GNUNET_SET_operation_cancel(), this function indicates whether |
412 | * the set of the operation has been destroyed because all operations are done and | 410 | * the set of the operation has been destroyed because all operations are done and |
413 | * the set's destruction was requested before. | 411 | * the set's destruction was requested before. |
414 | * | 412 | * |
415 | * @param oh set operation to cancel | 413 | * @param oh set operation to cancel |
416 | * @return GNUNET_YES if the set of the operation was destroyed | 414 | * @return #GNUNET_YES if the set of the operation was destroyed |
417 | */ | 415 | */ |
418 | static int | 416 | static int |
419 | set_operation_cancel (struct GNUNET_SET_OperationHandle *oh) | 417 | set_operation_cancel (struct GNUNET_SET_OperationHandle *oh) |
@@ -430,8 +428,11 @@ set_operation_cancel (struct GNUNET_SET_OperationHandle *oh) | |||
430 | struct GNUNET_SET_CancelMessage *m; | 428 | struct GNUNET_SET_CancelMessage *m; |
431 | struct GNUNET_MQ_Envelope *mqm; | 429 | struct GNUNET_MQ_Envelope *mqm; |
432 | 430 | ||
433 | GNUNET_CONTAINER_DLL_remove (oh->set->ops_head, oh->set->ops_tail, oh); | 431 | GNUNET_CONTAINER_DLL_remove (oh->set->ops_head, |
434 | h_assoc = GNUNET_MQ_assoc_remove (oh->set->mq, oh->request_id); | 432 | oh->set->ops_tail, |
433 | oh); | ||
434 | h_assoc = GNUNET_MQ_assoc_remove (oh->set->mq, | ||
435 | oh->request_id); | ||
435 | GNUNET_assert ((h_assoc == NULL) || (h_assoc == oh)); | 436 | GNUNET_assert ((h_assoc == NULL) || (h_assoc == oh)); |
436 | mqm = GNUNET_MQ_msg (m, GNUNET_MESSAGE_TYPE_SET_CANCEL); | 437 | mqm = GNUNET_MQ_msg (m, GNUNET_MESSAGE_TYPE_SET_CANCEL); |
437 | m->request_id = htonl (oh->request_id); | 438 | m->request_id = htonl (oh->request_id); |
@@ -439,20 +440,20 @@ set_operation_cancel (struct GNUNET_SET_OperationHandle *oh) | |||
439 | 440 | ||
440 | if (GNUNET_YES == oh->set->destroy_requested) | 441 | if (GNUNET_YES == oh->set->destroy_requested) |
441 | { | 442 | { |
442 | LOG (GNUNET_ERROR_TYPE_DEBUG, "destroying set after operation cancel\n"); | 443 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
444 | "Destroying set after operation cancel\n"); | ||
443 | ret = set_destroy (oh->set); | 445 | ret = set_destroy (oh->set); |
444 | } | 446 | } |
445 | } | 447 | } |
446 | |||
447 | GNUNET_free (oh); | 448 | GNUNET_free (oh); |
448 | |||
449 | return ret; | 449 | return ret; |
450 | } | 450 | } |
451 | 451 | ||
452 | 452 | ||
453 | /** | 453 | /** |
454 | * Cancel the given set operation. We need to send an explicit cancel message, | 454 | * Cancel the given set operation. We need to send an explicit cancel |
455 | * as all operations one one set communicate using one handle. | 455 | * message, as all operations one one set communicate using one |
456 | * handle. | ||
456 | * | 457 | * |
457 | * @param oh set operation to cancel | 458 | * @param oh set operation to cancel |
458 | */ | 459 | */ |
@@ -468,7 +469,8 @@ handle_client_set_error (void *cls, enum GNUNET_MQ_Error error) | |||
468 | { | 469 | { |
469 | struct GNUNET_SET_Handle *set = cls; | 470 | struct GNUNET_SET_Handle *set = cls; |
470 | 471 | ||
471 | LOG (GNUNET_ERROR_TYPE_DEBUG, "handling client set error\n"); | 472 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
473 | "handling client set error\n"); | ||
472 | 474 | ||
473 | while (NULL != set->ops_head) | 475 | while (NULL != set->ops_head) |
474 | { | 476 | { |
@@ -588,7 +590,9 @@ GNUNET_SET_remove_element (struct GNUNET_SET_Handle *set, | |||
588 | return GNUNET_SYSERR; | 590 | return GNUNET_SYSERR; |
589 | } | 591 | } |
590 | 592 | ||
591 | mqm = GNUNET_MQ_msg_extra (msg, element->size, GNUNET_MESSAGE_TYPE_SET_REMOVE); | 593 | mqm = GNUNET_MQ_msg_extra (msg, |
594 | element->size, | ||
595 | GNUNET_MESSAGE_TYPE_SET_REMOVE); | ||
592 | msg->element_type = element->element_type; | 596 | msg->element_type = element->element_type; |
593 | memcpy (&msg[1], element->data, element->size); | 597 | memcpy (&msg[1], element->data, element->size); |
594 | GNUNET_MQ_notify_sent (mqm, cont, cont_cls); | 598 | GNUNET_MQ_notify_sent (mqm, cont, cont_cls); |
@@ -842,13 +846,15 @@ GNUNET_SET_commit (struct GNUNET_SET_OperationHandle *oh, | |||
842 | * | 846 | * |
843 | * @param set the set to iterate over | 847 | * @param set the set to iterate over |
844 | * @param iter the iterator to call for each element | 848 | * @param iter the iterator to call for each element |
845 | * @param cls closure for @a iter | 849 | * @param iter_cls closure for @a iter |
846 | * @return #GNUNET_YES if the iteration started successfuly, | 850 | * @return #GNUNET_YES if the iteration started successfuly, |
847 | * #GNUNET_NO if another iteration is active | 851 | * #GNUNET_NO if another iteration is active |
848 | * #GNUNET_SYSERR if the set is invalid (e.g. the server crashed, disconnected) | 852 | * #GNUNET_SYSERR if the set is invalid (e.g. the server crashed, disconnected) |
849 | */ | 853 | */ |
850 | int | 854 | int |
851 | GNUNET_SET_iterate (struct GNUNET_SET_Handle *set, GNUNET_SET_ElementIterator iter, void *cls) | 855 | GNUNET_SET_iterate (struct GNUNET_SET_Handle *set, |
856 | GNUNET_SET_ElementIterator iter, | ||
857 | void *iter_cls) | ||
852 | { | 858 | { |
853 | struct GNUNET_MQ_Envelope *ev; | 859 | struct GNUNET_MQ_Envelope *ev; |
854 | 860 | ||
@@ -859,11 +865,10 @@ GNUNET_SET_iterate (struct GNUNET_SET_Handle *set, GNUNET_SET_ElementIterator it | |||
859 | return GNUNET_SYSERR; | 865 | return GNUNET_SYSERR; |
860 | if (NULL != set->iterator) | 866 | if (NULL != set->iterator) |
861 | return GNUNET_NO; | 867 | return GNUNET_NO; |
862 | 868 | LOG (GNUNET_ERROR_TYPE_DEBUG, | |
863 | LOG (GNUNET_ERROR_TYPE_DEBUG, "iterating set\n"); | 869 | "iterating set\n"); |
864 | |||
865 | set->iterator = iter; | 870 | set->iterator = iter; |
866 | set->iterator_cls = cls; | 871 | set->iterator_cls = iter_cls; |
867 | ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_SET_ITER_REQUEST); | 872 | ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_SET_ITER_REQUEST); |
868 | GNUNET_MQ_send (set->mq, ev); | 873 | GNUNET_MQ_send (set->mq, ev); |
869 | return GNUNET_YES; | 874 | return GNUNET_YES; |