From: Sree Harsha Totakura Date: Fri, 31 Aug 2012 12:05:47 +0000 (+0000) Subject: check if peer has already been stopped before attempting to stop it again X-Git-Tag: initial-import-from-subversion-38251~12002 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=ba0cbafc1f7fbd95bbe742f4eaa1bff620929115;p=oweals%2Fgnunet.git check if peer has already been stopped before attempting to stop it again --- diff --git a/src/testbed/test_testbed_api_testbed_run.c b/src/testbed/test_testbed_api_testbed_run.c index a9a2a8192..2a7c77af0 100644 --- a/src/testbed/test_testbed_api_testbed_run.c +++ b/src/testbed/test_testbed_api_testbed_run.c @@ -38,6 +38,11 @@ */ static struct GNUNET_TESTBED_Peer *peers[NUM_PEERS]; +/** + * Operation handle + */ +static struct GNUNET_TESTBED_Operation *op; + /** * Abort task identifier */ @@ -95,8 +100,9 @@ static void master_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { result = GNUNET_OK; - /* Artificial delay */ - GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &do_shutdown, NULL); + GNUNET_assert (NULL != peers[0]); + op = GNUNET_TESTBED_peer_stop (peers[0]); + GNUNET_assert (NULL != op); } @@ -118,6 +124,12 @@ controller_event_cb (void *cls, GNUNET_assert (NULL != event->details.peer_start.peer); peers[peer_id++] = event->details.peer_start.peer; break; + case GNUNET_TESTBED_ET_PEER_STOP: + GNUNET_assert (NULL != op); + GNUNET_TESTBED_operation_done (op); + GNUNET_assert (peers[0] == event->details.peer_stop.peer); + GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); + break; default: GNUNET_assert (0); } diff --git a/src/testbed/testbed_api_testbed.c b/src/testbed/testbed_api_testbed.c index fb9ed31b6..f9b67676e 100644 --- a/src/testbed/testbed_api_testbed.c +++ b/src/testbed/testbed_api_testbed.c @@ -27,6 +27,7 @@ #include "platform.h" #include "gnunet_testbed_service.h" +#include "testbed_api_peers.h" /** * Generic loggins shorthand @@ -500,13 +501,19 @@ shutdown_run_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) rc->peer_count = 0; for (peer = 0; peer < rc->num_peers; peer++) { + if (PS_STARTED != rc->peers[peer]->state) + { + rc->peer_count++; + continue; + } dll_op = GNUNET_malloc (sizeof (struct DLLOperation)); dll_op->op = GNUNET_TESTBED_peer_stop (rc->peers[peer]); dll_op->cls = rc->peers[peer]; GNUNET_CONTAINER_DLL_insert_tail (rc->dll_op_head, rc->dll_op_tail, dll_op); } - return; + if (rc->peer_count != rc->num_peers) + return; } } rc->state = RC_PEERS_DESTROYED; /* No peers are present so we consider the