diff options
author | Sree Harsha Totakura <totakura@in.tum.de> | 2012-06-23 15:59:18 +0000 |
---|---|---|
committer | Sree Harsha Totakura <totakura@in.tum.de> | 2012-06-23 15:59:18 +0000 |
commit | 4876301fb85d072bc54a67e077268616173f0fc5 (patch) | |
tree | 076c3d27e0db8b06507def298af671db8798417e /src/stream | |
parent | 560ea6e63a12bf63041745082546e96ef9359886 (diff) | |
download | gnunet-4876301fb85d072bc54a67e077268616173f0fc5.tar.gz gnunet-4876301fb85d072bc54a67e077268616173f0fc5.zip |
-added stream read io cancel
Diffstat (limited to 'src/stream')
-rw-r--r-- | src/stream/stream_api.c | 40 |
1 files changed, 28 insertions, 12 deletions
diff --git a/src/stream/stream_api.c b/src/stream/stream_api.c index f042ccc93..18435d0a7 100644 --- a/src/stream/stream_api.c +++ b/src/stream/stream_api.c | |||
@@ -479,6 +479,11 @@ struct GNUNET_STREAM_IOWriteHandle | |||
479 | struct GNUNET_STREAM_IOReadHandle | 479 | struct GNUNET_STREAM_IOReadHandle |
480 | { | 480 | { |
481 | /** | 481 | /** |
482 | * The socket to which this read handle is associated | ||
483 | */ | ||
484 | struct GNUNET_STREAM_Socket *socket; | ||
485 | |||
486 | /** | ||
482 | * Callback for the read processor | 487 | * Callback for the read processor |
483 | */ | 488 | */ |
484 | GNUNET_STREAM_DataProcessor proc; | 489 | GNUNET_STREAM_DataProcessor proc; |
@@ -1055,7 +1060,7 @@ call_read_processor (void *cls, | |||
1055 | * @param tc the task context | 1060 | * @param tc the task context |
1056 | */ | 1061 | */ |
1057 | static void | 1062 | static void |
1058 | read_io_timeout (void *cls, | 1063 | read_io_timeout (void *cls, |
1059 | const struct GNUNET_SCHEDULER_TaskContext *tc) | 1064 | const struct GNUNET_SCHEDULER_TaskContext *tc) |
1060 | { | 1065 | { |
1061 | struct GNUNET_STREAM_Socket *socket = cls; | 1066 | struct GNUNET_STREAM_Socket *socket = cls; |
@@ -1074,7 +1079,6 @@ read_io_timeout (void *cls, | |||
1074 | GNUNET_assert (NULL != socket->read_handle); | 1079 | GNUNET_assert (NULL != socket->read_handle); |
1075 | proc = socket->read_handle->proc; | 1080 | proc = socket->read_handle->proc; |
1076 | proc_cls = socket->read_handle->proc_cls; | 1081 | proc_cls = socket->read_handle->proc_cls; |
1077 | |||
1078 | GNUNET_free (socket->read_handle); | 1082 | GNUNET_free (socket->read_handle); |
1079 | socket->read_handle = NULL; | 1083 | socket->read_handle = NULL; |
1080 | /* Call the read processor to signal timeout */ | 1084 | /* Call the read processor to signal timeout */ |
@@ -3428,13 +3432,11 @@ GNUNET_STREAM_read (struct GNUNET_STREAM_Socket *socket, | |||
3428 | "%s: %s()\n", | 3432 | "%s: %s()\n", |
3429 | GNUNET_i2s (&socket->other_peer), | 3433 | GNUNET_i2s (&socket->other_peer), |
3430 | __func__); | 3434 | __func__); |
3431 | |||
3432 | /* Return NULL if there is already a read handle; the user has to cancel that | 3435 | /* Return NULL if there is already a read handle; the user has to cancel that |
3433 | first before continuing or has to wait until it is completed */ | 3436 | first before continuing or has to wait until it is completed */ |
3434 | if (NULL != socket->read_handle) return NULL; | 3437 | if (NULL != socket->read_handle) |
3435 | 3438 | return NULL; | |
3436 | GNUNET_assert (NULL != proc); | 3439 | GNUNET_assert (NULL != proc); |
3437 | |||
3438 | switch (socket->state) | 3440 | switch (socket->state) |
3439 | { | 3441 | { |
3440 | case STATE_RECEIVE_CLOSED: | 3442 | case STATE_RECEIVE_CLOSED: |
@@ -3450,21 +3452,18 @@ GNUNET_STREAM_read (struct GNUNET_STREAM_Socket *socket, | |||
3450 | default: | 3452 | default: |
3451 | break; | 3453 | break; |
3452 | } | 3454 | } |
3453 | |||
3454 | read_handle = GNUNET_malloc (sizeof (struct GNUNET_STREAM_IOReadHandle)); | 3455 | read_handle = GNUNET_malloc (sizeof (struct GNUNET_STREAM_IOReadHandle)); |
3455 | read_handle->proc = proc; | 3456 | read_handle->proc = proc; |
3456 | read_handle->proc_cls = proc_cls; | 3457 | read_handle->proc_cls = proc_cls; |
3458 | read_handle->socket = socket; | ||
3457 | socket->read_handle = read_handle; | 3459 | socket->read_handle = read_handle; |
3458 | |||
3459 | /* Check if we have a packet at bitmap 0 */ | 3460 | /* Check if we have a packet at bitmap 0 */ |
3460 | if (GNUNET_YES == ackbitmap_is_bit_set (&socket->ack_bitmap, | 3461 | if (GNUNET_YES == ackbitmap_is_bit_set (&socket->ack_bitmap, |
3461 | 0)) | 3462 | 0)) |
3462 | { | 3463 | { |
3463 | socket->read_task_id = GNUNET_SCHEDULER_add_now (&call_read_processor, | 3464 | socket->read_task_id = GNUNET_SCHEDULER_add_now (&call_read_processor, |
3464 | socket); | 3465 | socket); |
3465 | |||
3466 | } | 3466 | } |
3467 | |||
3468 | /* Setup the read timeout task */ | 3467 | /* Setup the read timeout task */ |
3469 | socket->read_io_timeout_task_id = | 3468 | socket->read_io_timeout_task_id = |
3470 | GNUNET_SCHEDULER_add_delayed (timeout, | 3469 | GNUNET_SCHEDULER_add_delayed (timeout, |
@@ -3517,7 +3516,24 @@ GNUNET_STREAM_io_write_cancel (struct GNUNET_STREAM_IOWriteHandle *ioh) | |||
3517 | void | 3516 | void |
3518 | GNUNET_STREAM_io_read_cancel (struct GNUNET_STREAM_IOReadHandle *ioh) | 3517 | GNUNET_STREAM_io_read_cancel (struct GNUNET_STREAM_IOReadHandle *ioh) |
3519 | { | 3518 | { |
3520 | // FIXME: do stuff | 3519 | struct GNUNET_STREAM_Socket *socket; |
3520 | |||
3521 | socket = ioh->socket; | ||
3522 | GNUNET_assert (NULL != socket->read_handle); | ||
3523 | GNUNET_assert (ioh == socket->read_handle); | ||
3524 | /* Read io time task should be there; if it is already executed then this | ||
3525 | read handle is not valid */ | ||
3526 | GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != socket->read_io_timeout_task_id); | ||
3527 | GNUNET_SCHEDULER_cancel (socket->read_io_timeout_task_id); | ||
3528 | socket->read_io_timeout_task_id = GNUNET_SCHEDULER_NO_TASK; | ||
3529 | /* reading task may be present; if so we have to stop it */ | ||
3530 | if (GNUNET_SCHEDULER_NO_TASK != socket->read_task_id) | ||
3531 | { | ||
3532 | GNUNET_SCHEDULER_cancel (socket->read_task_id); | ||
3533 | socket->read_task_id = GNUNET_SCHEDULER_NO_TASK; | ||
3534 | } | ||
3535 | GNUNET_free (ioh); | ||
3536 | socket->read_handle = NULL; | ||
3521 | } | 3537 | } |
3522 | 3538 | ||
3523 | /* end of stream_api.c */ | 3539 | /* end of stream_api.c */ |