diff options
author | harsha <harsha@140774ce-b5e7-0310-ab8b-a85725594a96> | 2012-11-19 14:17:51 +0000 |
---|---|---|
committer | harsha <harsha@140774ce-b5e7-0310-ab8b-a85725594a96> | 2012-11-19 14:17:51 +0000 |
commit | 30caae6abd20a1f537fcb5d0fc0a6d57db0a23e1 (patch) | |
tree | 66e6b959dd53526a9b41aed1d35723e38a7249e1 | |
parent | cce10effb13a8fc1175118f5c16258dd0c4a7ffe (diff) |
- warn upon unclean socket close
git-svn-id: https://gnunet.org/svn/gnunet@25052 140774ce-b5e7-0310-ab8b-a85725594a96
-rw-r--r-- | src/stream/stream_api.c | 2 | ||||
-rw-r--r-- | src/stream/test_stream_2peers.c | 1 | ||||
-rw-r--r-- | src/stream/test_stream_local.c | 46 |
3 files changed, 40 insertions, 9 deletions
diff --git a/src/stream/stream_api.c b/src/stream/stream_api.c index b55ae46f03..fd2f86e51b 100644 --- a/src/stream/stream_api.c +++ b/src/stream/stream_api.c @@ -3214,6 +3214,8 @@ GNUNET_STREAM_close (struct GNUNET_STREAM_Socket *socket) GNUNET_STREAM_io_write_cancel (socket->write_handle); //socket->write_handle = NULL; } + GNUNET_break (GNUNET_YES == socket->receive_closed); + GNUNET_break (GNUNET_YES == socket->transmit_closed); /* Terminate the ack'ing task if they are still present */ if (socket->ack_task_id != GNUNET_SCHEDULER_NO_TASK) { diff --git a/src/stream/test_stream_2peers.c b/src/stream/test_stream_2peers.c index c517cc2b1d..d059d0521f 100644 --- a/src/stream/test_stream_2peers.c +++ b/src/stream/test_stream_2peers.c @@ -264,7 +264,6 @@ shutdown_completion (void *cls, } - /** * Shutdown sockets gracefully */ diff --git a/src/stream/test_stream_local.c b/src/stream/test_stream_local.c index 3286ade5fd..cb59de9997 100644 --- a/src/stream/test_stream_local.c +++ b/src/stream/test_stream_local.c @@ -60,6 +60,11 @@ struct PeerData struct GNUNET_STREAM_IOReadHandle *io_read_handle; /** + * Peer's shutdown handle + */ + struct GNUNET_STREAM_ShutdownHandle *shutdown_handle; + + /** * Bytes the peer has written */ unsigned int bytes_wrote; @@ -166,19 +171,16 @@ stream_write_task (void *cls, * Shutdown nicely */ static void -do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) +do_close (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { + if (GNUNET_SCHEDULER_NO_TASK != abort_task) + GNUNET_SCHEDULER_cancel (abort_task); if (NULL != peer1.socket) GNUNET_STREAM_close (peer1.socket); if (NULL != peer2.socket) GNUNET_STREAM_close (peer2.socket); if (NULL != peer2_listen_socket) GNUNET_STREAM_listen_close (peer2_listen_socket); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: shutdown\n"); - if (0 != abort_task) - { - GNUNET_SCHEDULER_cancel (abort_task); - } } @@ -190,8 +192,36 @@ do_abort (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: ABORT\n"); result = GNUNET_SYSERR; - abort_task = 0; - do_shutdown (cls, tc); + abort_task = GNUNET_SCHEDULER_NO_TASK; + do_close (cls, tc); +} + + +/** + * 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) + */ +static void +shutdown_completion (void *cls, + int operation) +{ + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "STREAM shutdown successful\n"); + GNUNET_SCHEDULER_add_now (&do_close, cls); +} + + +/** + * Shutdown sockets gracefully + */ +static void +do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) +{ + result = GNUNET_OK; + peer1.shutdown_handle = GNUNET_STREAM_shutdown (peer1.socket, SHUT_RDWR, + &shutdown_completion, cls); } |