diff options
author | Sree Harsha Totakura <totakura@in.tum.de> | 2012-02-27 12:51:42 +0000 |
---|---|---|
committer | Sree Harsha Totakura <totakura@in.tum.de> | 2012-02-27 12:51:42 +0000 |
commit | 074fd12910bf6896d254dfabd03b139551df83cf (patch) | |
tree | 39cb38f6056f7e20fe3e0e2283fd5a0484b57afd /src/stream/stream_api.c | |
parent | 4ea2ac4058b988958137a7eac0b0e695c38ab527 (diff) | |
download | gnunet-074fd12910bf6896d254dfabd03b139551df83cf.tar.gz gnunet-074fd12910bf6896d254dfabd03b139551df83cf.zip |
-added read io timeout
Diffstat (limited to 'src/stream/stream_api.c')
-rw-r--r-- | src/stream/stream_api.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/stream/stream_api.c b/src/stream/stream_api.c index 2ccf4e892..7d6202979 100644 --- a/src/stream/stream_api.c +++ b/src/stream/stream_api.c | |||
@@ -237,6 +237,11 @@ struct GNUNET_STREAM_Socket | |||
237 | void *copy_buffer; | 237 | void *copy_buffer; |
238 | 238 | ||
239 | /** | 239 | /** |
240 | * Task identifier for the read io timeout task | ||
241 | */ | ||
242 | GNUNET_SCHEDULER_TaskIdentifier read_io_timeout_task; | ||
243 | |||
244 | /** | ||
240 | * The state of the protocol associated with this socket | 245 | * The state of the protocol associated with this socket |
241 | */ | 246 | */ |
242 | enum State state; | 247 | enum State state; |
@@ -687,6 +692,9 @@ call_read_processor_task (void *cls, | |||
687 | valid_read_size = socket->copy_buffer_size - socket->copy_buffer_read_offset; | 692 | valid_read_size = socket->copy_buffer_size - socket->copy_buffer_read_offset; |
688 | GNUNET_assert (0 != valid_read_size); | 693 | GNUNET_assert (0 != valid_read_size); |
689 | 694 | ||
695 | /* Cancel the read_io_timeout_task */ | ||
696 | GNUNET_SCHEDULER_cancel (socket->read_io_timeout_task); | ||
697 | /* Call the data processor */ | ||
690 | read_size = socket->read_handle->proc (socket->read_handle->proc_cls, | 698 | read_size = socket->read_handle->proc (socket->read_handle->proc_cls, |
691 | socket->status, | 699 | socket->status, |
692 | socket->copy_buffer | 700 | socket->copy_buffer |
@@ -785,6 +793,26 @@ prepare_buffer_for_read (struct GNUNET_STREAM_Socket *socket) | |||
785 | } | 793 | } |
786 | 794 | ||
787 | 795 | ||
796 | |||
797 | /** | ||
798 | * Cancels the existing read io handle | ||
799 | * | ||
800 | * @param cls the closure from the SCHEDULER call | ||
801 | * @param tc the task context | ||
802 | */ | ||
803 | static void | ||
804 | cancel_read_io (void *cls, | ||
805 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
806 | { | ||
807 | struct GNUNET_STREAM_Socket *socket = cls; | ||
808 | |||
809 | GNUNET_assert (NULL != socket->read_handle); | ||
810 | |||
811 | GNUNET_free (socket->read_handle); | ||
812 | socket->read_handle = NULL; | ||
813 | } | ||
814 | |||
815 | |||
788 | /** | 816 | /** |
789 | * Handler for DATA messages; Same for both client and server | 817 | * Handler for DATA messages; Same for both client and server |
790 | * | 818 | * |
@@ -2153,5 +2181,9 @@ GNUNET_STREAM_read (struct GNUNET_STREAM_Socket *socket, | |||
2153 | else | 2181 | else |
2154 | prepare_buffer_for_read (socket); | 2182 | prepare_buffer_for_read (socket); |
2155 | 2183 | ||
2184 | socket->read_io_timeout_task = GNUNET_SCHEDULER_add_delayed (timeout, | ||
2185 | &cancel_read_io, | ||
2186 | socket); | ||
2187 | |||
2156 | return read_handle; | 2188 | return read_handle; |
2157 | } | 2189 | } |