From e70d7f62e59d59846cfb744a4c15cd772ec357be Mon Sep 17 00:00:00 2001 From: Sree Harsha Totakura Date: Mon, 19 Nov 2012 15:02:23 +0000 Subject: [PATCH] - fixes --- src/stream/perf_stream_api.c | 36 ++++++++++++++- src/stream/test_stream_big.c | 44 ++++++++++++++++--- src/stream/test_stream_sequence_wraparound.c | 46 ++++++++++++++++---- 3 files changed, 109 insertions(+), 17 deletions(-) diff --git a/src/stream/perf_stream_api.c b/src/stream/perf_stream_api.c index 3c1d56f84..cd68310bc 100644 --- a/src/stream/perf_stream_api.c +++ b/src/stream/perf_stream_api.c @@ -125,6 +125,11 @@ struct PeerData */ struct GNUNET_PeerIdentity id; + /** + * Peer's shutdown handle + */ + struct GNUNET_STREAM_ShutdownHandle *shutdown_handle; + /** * Bytes the peer has written */ @@ -372,7 +377,7 @@ free_meter (struct ProgressMeter *meter) * Shutdown nicely */ static void -do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) +do_close (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { switch (test_step) { @@ -419,7 +424,34 @@ do_abort (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) if (GNUNET_SCHEDULER_NO_TASK != read_task) GNUNET_SCHEDULER_cancel (read_task); result = GNUNET_SYSERR; - do_shutdown (cls, tc); + 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) +{ + peer_data[0].shutdown_handle = GNUNET_STREAM_shutdown (peer_data[0].socket, SHUT_RDWR, + &shutdown_completion, cls); } diff --git a/src/stream/test_stream_big.c b/src/stream/test_stream_big.c index 05da82691..d5875dd55 100644 --- a/src/stream/test_stream_big.c +++ b/src/stream/test_stream_big.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 */ @@ -88,19 +93,16 @@ static int result; * 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); /* Close listen socket */ - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: shutdown\n"); - if (GNUNET_SCHEDULER_NO_TASK != abort_task) - GNUNET_SCHEDULER_cancel (abort_task); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Wait\n"); - GNUNET_SCHEDULER_shutdown (); } @@ -115,7 +117,35 @@ do_abort (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) GNUNET_SCHEDULER_cancel (read_task); result = GNUNET_SYSERR; abort_task = GNUNET_SCHEDULER_NO_TASK; - do_shutdown (cls, tc); + 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); } diff --git a/src/stream/test_stream_sequence_wraparound.c b/src/stream/test_stream_sequence_wraparound.c index f23171661..61e28cf72 100644 --- a/src/stream/test_stream_sequence_wraparound.c +++ b/src/stream/test_stream_sequence_wraparound.c @@ -63,6 +63,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 */ @@ -93,19 +98,16 @@ static int result; * 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); /* Close listen socket */ - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: shutdown\n"); - if (0 != abort_task) - { - GNUNET_SCHEDULER_cancel (abort_task); - } } @@ -121,8 +123,36 @@ do_abort (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) GNUNET_SCHEDULER_cancel (read_task); } 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); } -- 2.25.1