From 3ccfd30802db0ff457cecef92609aa21c4728a4c Mon Sep 17 00:00:00 2001 From: Sree Harsha Totakura Date: Mon, 10 Dec 2012 14:11:53 +0000 Subject: [PATCH] fix 2672 --- src/fs/gnunet-service-fs_stream.c | 1 - src/include/gnunet_stream_lib.h | 29 ++++++++++++++--------------- src/stream/stream_api.c | 23 ++++++++++++----------- 3 files changed, 26 insertions(+), 27 deletions(-) diff --git a/src/fs/gnunet-service-fs_stream.c b/src/fs/gnunet-service-fs_stream.c index 4daf21e44..50c9bfcf4 100644 --- a/src/fs/gnunet-service-fs_stream.c +++ b/src/fs/gnunet-service-fs_stream.c @@ -1049,7 +1049,6 @@ process_request (void *cls, case GNUNET_STREAM_TIMEOUT: case GNUNET_STREAM_SHUTDOWN: case GNUNET_STREAM_SYSERR: - case GNUNET_STREAM_BROKEN: terminate_stream_async (sc); return size; default: diff --git a/src/include/gnunet_stream_lib.h b/src/include/gnunet_stream_lib.h index d81218364..7097f8a5b 100644 --- a/src/include/gnunet_stream_lib.h +++ b/src/include/gnunet_stream_lib.h @@ -46,29 +46,23 @@ enum GNUNET_STREAM_Status /** * All previous read/write operations are successfully done */ - GNUNET_STREAM_OK = 0, + GNUNET_STREAM_OK, /** * A timeout occured while reading/writing the stream */ - GNUNET_STREAM_TIMEOUT = 1, + GNUNET_STREAM_TIMEOUT, /** * Other side has shutdown the socket for this type of operation * (reading/writing) */ - GNUNET_STREAM_SHUTDOWN = 2, + GNUNET_STREAM_SHUTDOWN, /** * A serious error occured while operating on this stream */ - GNUNET_STREAM_SYSERR = 3, - - /** - * An error resulted in an unusable stream - * FIXME: status code unused? - */ - GNUNET_STREAM_BROKEN + GNUNET_STREAM_SYSERR }; /** @@ -279,9 +273,13 @@ GNUNET_STREAM_listen_close (struct GNUNET_STREAM_ListenSocket *lsocket); * * @param cls the closure from GNUNET_STREAM_write * @param status the status of the stream at the time this function is called; - * GNUNET_OK if writing to stream was completed successfully, + * GNUNET_STREAM_OK if writing to stream was completed successfully; + * GNUNET_STREAM_TIMEOUT if the given data is not sent successfully + * (this doesn't mean that the data is never sent, the receiver may + * have read the data but its ACKs may have been lost); * GNUNET_STREAM_SHUTDOWN if the stream is shutdown for writing in the - * mean time. + * mean time; GNUNET_STREAM_SYSERR if the stream is broken and cannot + * be processed. * @param size the number of bytes written */ typedef void (*GNUNET_STREAM_CompletionContinuation) (void *cls, @@ -315,9 +313,10 @@ struct GNUNET_STREAM_IOReadHandle; * stream * @param write_cont_cls the closure * - * @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. + * @return handle to cancel the operation; if a previous write is pending NULL + * is returned. If the stream has been shutdown for this operation or + * is broken then write_cont is immediately called and NULL is + * returned. */ struct GNUNET_STREAM_IOWriteHandle * GNUNET_STREAM_write (struct GNUNET_STREAM_Socket *socket, diff --git a/src/stream/stream_api.c b/src/stream/stream_api.c index 60e7cfbd8..a0be54d43 100644 --- a/src/stream/stream_api.c +++ b/src/stream/stream_api.c @@ -2603,6 +2603,7 @@ handle_ack (struct GNUNET_STREAM_Socket *socket, ack_bitmap = GNUNET_ntohll (ack->bitmap); for (; packet < GNUNET_STREAM_ACK_BITMAP_BIT_LENGTH; packet++) { + if (NULL == socket->write_handle->messages[packet]) break; if (ackbitmap_is_bit_set (&ack_bitmap, ntohl (socket->write_handle->messages[packet]->sequence_number) - ntohl (ack->base_sequence_number))) @@ -2912,7 +2913,7 @@ tunnel_cleaner (void *cls, GNUNET_STATISTICS_update (socket->stat_handle, "inbound connections", -1, GNUNET_NO); } - socket->status = GNUNET_STREAM_SHUTDOWN; + socket->status = GNUNET_STREAM_SYSERR; /* Clear Transmit handles */ if (NULL != socket->transmit_handle) { @@ -2936,12 +2937,6 @@ tunnel_cleaner (void *cls, GNUNET_SCHEDULER_cancel (socket->control_retransmission_task_id); socket->control_retransmission_task_id = GNUNET_SCHEDULER_NO_TASK; } - /* Clear Transmit handles */ - if (NULL != socket->transmit_handle) - { - GNUNET_MESH_notify_transmit_ready_cancel (socket->transmit_handle); - socket->transmit_handle = NULL; - } /* Clear existing message queue */ while (NULL != (head = socket->queue_head)) { GNUNET_CONTAINER_DLL_remove (socket->queue_head, @@ -3437,9 +3432,10 @@ GNUNET_STREAM_listen_close (struct GNUNET_STREAM_ListenSocket *lsocket) * stream * @param write_cont_cls the closure * - * @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. + * @return handle to cancel the operation; if a previous write is pending NULL + * is returned. If the stream has been shutdown for this operation or + * is broken then write_cont is immediately called and NULL is + * returned. */ struct GNUNET_STREAM_IOWriteHandle * GNUNET_STREAM_write (struct GNUNET_STREAM_Socket *socket, @@ -3466,6 +3462,12 @@ GNUNET_STREAM_write (struct GNUNET_STREAM_Socket *socket, GNUNET_break (0); return NULL; } + if (NULL == socket->tunnel) + { + if (NULL != write_cont) + write_cont (write_cont_cls, GNUNET_STREAM_SYSERR, 0); + return NULL; + } switch (socket->state) { case STATE_TRANSMIT_CLOSED: @@ -3481,7 +3483,6 @@ GNUNET_STREAM_write (struct GNUNET_STREAM_Socket *socket, case STATE_LISTEN: case STATE_HELLO_WAIT: if (NULL != write_cont) - /* FIXME: GNUNET_STREAM_SYSERR?? */ write_cont (write_cont_cls, GNUNET_STREAM_SYSERR, 0); LOG (GNUNET_ERROR_TYPE_DEBUG, "%s() END\n", __func__); -- 2.25.1