-added read io timeout
authorSree Harsha Totakura <totakura@in.tum.de>
Mon, 27 Feb 2012 12:51:42 +0000 (12:51 +0000)
committerSree Harsha Totakura <totakura@in.tum.de>
Mon, 27 Feb 2012 12:51:42 +0000 (12:51 +0000)
src/stream/stream_api.c

index 2ccf4e892a160aed1f1cb765f1d47d5d7bd16b59..7d6202979ce91742382bdca36f0c89c430ce0394 100644 (file)
@@ -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;
 }