-added error status GNUNET_STREAM_BROKEN
[oweals/gnunet.git] / src / include / gnunet_stream_lib.h
index 5a2f9b2e49cc0702ab92cd5483a3f1bbebbdbbd2..e09c264d6aa44ef4c248f6a4769a6cbe1ba286f4 100644 (file)
@@ -62,7 +62,12 @@ enum GNUNET_STREAM_Status
     /**
      * A serious error occured while operating on this stream
      */
-    GNUNET_STREAM_SYSERR = 3
+    GNUNET_STREAM_SYSERR = 3,
+    
+    /**
+     * An error resulted in an unusable stream
+     */
+    GNUNET_STREAM_BROKEN
   };
 
 /**
@@ -125,18 +130,51 @@ GNUNET_STREAM_open (const struct GNUNET_CONFIGURATION_Handle *cfg,
 
 
 /**
- * Shutdown the stream for reading or writing (man 2 shutdown).
+ * Handle for shutdown
+ */
+struct GNUNET_STREAM_ShutdownHandle;
+
+
+/**
+ * Completion callback for shutdown
+ *
+ * @param cls the closure from GNUNET_STREAM_shutdown call
+ * @param operation the operation that was shutdown (SHUT_RD, SHUT_WR,
+ *          SHUT_RDWR) 
+ */
+typedef void (*GNUNET_STREAM_ShutdownCompletion) (void *cls,
+                                                  int operation);
+
+
+/**
+ * Shutdown the stream for reading or writing (similar to man 2 shutdown).
  *
  * @param socket the stream socket
- * @param how SHUT_RD, SHUT_WR or SHUT_RDWR 
+ * @param operation SHUT_RD, SHUT_WR or SHUT_RDWR
+ * @param completion_cb the callback that will be called upon successful
+ *          shutdown of given operation
+ * @param completion_cls the closure for the completion callback
+ * @return the shutdown handle; NULL in case of any error
  */
-void
+struct GNUNET_STREAM_ShutdownHandle *
 GNUNET_STREAM_shutdown (struct GNUNET_STREAM_Socket *socket,
-                       int how);
+                       int operation,
+                        GNUNET_STREAM_ShutdownCompletion completion_cb,
+                        void *completion_cls);
+
+
+/**
+ * Cancels a pending shutdown
+ *
+ * @param handle the shutdown handle returned from GNUNET_STREAM_shutdown
+ */
+void
+GNUNET_STREAM_shutdown_cancel (struct GNUNET_STREAM_ShutdownHandle *handle);
 
 
 /**
- * Closes the stream
+ * Closes the stream and frees the associated state. The stream should be
+ * shutdown before closing.
  *
  * @param socket the stream socket
  */
@@ -229,7 +267,10 @@ struct GNUNET_STREAM_IOReadHandle;
  * @param write_cont the function to call upon writing some bytes into the
  *          stream 
  * @param write_cont_cls the closure
- * @return handle to cancel the operation; NULL if a previous write is pending
+ *
+ * @return handle to cancel the operation; if a previous write is pending or
+ *           the stream has been shutdown for this operation then write_cont is
+ *           immediately called and NULL is returned.
  */
 struct GNUNET_STREAM_IOWriteHandle *
 GNUNET_STREAM_write (struct GNUNET_STREAM_Socket *socket,
@@ -258,13 +299,16 @@ typedef size_t (*GNUNET_STREAM_DataProcessor) (void *cls,
 
 
 /**
- * Tries to read data from the stream
+ * Tries to read data from the stream.
  *
  * @param socket the socket representing a stream
  * @param timeout the timeout period
  * @param proc function to call with data (once only)
  * @param proc_cls the closure for proc
- * @return handle to cancel the operation
+ *
+ * @return handle to cancel the operation; if the stream has been shutdown for
+ *           this type of opeartion then the DataProcessor is immediately
+ *           called with GNUNET_STREAM_SHUTDOWN as status and NULL if returned
  */
 struct GNUNET_STREAM_IOReadHandle *
 GNUNET_STREAM_read (struct GNUNET_STREAM_Socket *socket,