From: Sree Harsha Totakura Date: Mon, 27 Feb 2012 12:51:42 +0000 (+0000) Subject: -added read io timeout X-Git-Tag: initial-import-from-subversion-38251~14611 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=074fd12910bf6896d254dfabd03b139551df83cf;p=oweals%2Fgnunet.git -added read io timeout --- 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 @@ -236,6 +236,11 @@ struct GNUNET_STREAM_Socket */ void *copy_buffer; + /** + * Task identifier for the read io timeout task + */ + GNUNET_SCHEDULER_TaskIdentifier read_io_timeout_task; + /** * The state of the protocol associated with this socket */ @@ -687,6 +692,9 @@ call_read_processor_task (void *cls, valid_read_size = socket->copy_buffer_size - socket->copy_buffer_read_offset; GNUNET_assert (0 != valid_read_size); + /* Cancel the read_io_timeout_task */ + GNUNET_SCHEDULER_cancel (socket->read_io_timeout_task); + /* Call the data processor */ read_size = socket->read_handle->proc (socket->read_handle->proc_cls, socket->status, socket->copy_buffer @@ -785,6 +793,26 @@ prepare_buffer_for_read (struct GNUNET_STREAM_Socket *socket) } + +/** + * Cancels the existing read io handle + * + * @param cls the closure from the SCHEDULER call + * @param tc the task context + */ +static void +cancel_read_io (void *cls, + const struct GNUNET_SCHEDULER_TaskContext *tc) +{ + struct GNUNET_STREAM_Socket *socket = cls; + + GNUNET_assert (NULL != socket->read_handle); + + GNUNET_free (socket->read_handle); + socket->read_handle = NULL; +} + + /** * Handler for DATA messages; Same for both client and server * @@ -2153,5 +2181,9 @@ GNUNET_STREAM_read (struct GNUNET_STREAM_Socket *socket, else prepare_buffer_for_read (socket); + socket->read_io_timeout_task = GNUNET_SCHEDULER_add_delayed (timeout, + &cancel_read_io, + socket); + return read_handle; }