diff options
author | Sree Harsha Totakura <totakura@in.tum.de> | 2014-03-07 15:57:34 +0000 |
---|---|---|
committer | Sree Harsha Totakura <totakura@in.tum.de> | 2014-03-07 15:57:34 +0000 |
commit | 393254f8297fb32bab8c0ec6af2b03b8e72756c6 (patch) | |
tree | bb6b1a5dcb2a8e305ff2c38b8461b0a5a24d15e7 /src/testbed | |
parent | 918024cf6824c59e91593b7ade6b8ff8a93a214b (diff) |
- Delay shutdown until all connections are closed.
Diffstat (limited to 'src/testbed')
-rw-r--r-- | src/testbed/gnunet-service-testbed-logger.c | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/src/testbed/gnunet-service-testbed-logger.c b/src/testbed/gnunet-service-testbed-logger.c index deaeca543f..6bf33e681b 100644 --- a/src/testbed/gnunet-service-testbed-logger.c +++ b/src/testbed/gnunet-service-testbed-logger.c @@ -86,6 +86,16 @@ struct GNUNET_BIO_WriteHandle *bio; static GNUNET_SCHEDULER_TaskIdentifier shutdown_task_id; /** + * The number of connections we have + */ +static unsigned int nconn; + +/** + * Are we shutting down? + */ +static int in_shutdown; + +/** * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_ADDHOST messages * * @param cls NULL @@ -117,6 +127,15 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) struct MessageQueue *mq_entry; shutdown_task_id = GNUNET_SCHEDULER_NO_TASK; + in_shutdown = GNUNET_YES; + if (0 != nconn) + { + /* Delay shutdown if there are active connections */ + shutdown_task_id = GNUNET_SCHEDULER_add_delayed + (GNUNET_TIME_UNIT_FOREVER_REL, + &shutdown_task, NULL); + return; + } while (NULL != (mq_entry = mq_head)) { GNUNET_free (mq_entry->msg); @@ -129,6 +148,51 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) /** + * Functions with this signature are called whenever a client + * is disconnected on the network level. + * + * @param cls closure + * @param client identification of the client; NULL + * for the last call when the server is destroyed + */ +static void +client_disconnected (void *cls, struct GNUNET_SERVER_Client *client) +{ + if (NULL == client) + { + GNUNET_break (0 == nconn); + return; + } + nconn--; + if (GNUNET_YES != in_shutdown) + return; + GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != shutdown_task_id); + GNUNET_SCHEDULER_cancel (shutdown_task_id); + shutdown_task_id = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); +} + + +/** + * Functions with this signature are called whenever a client + * is connected on the network level. + * + * @param cls closure + * @param client identification of the client + */ +static void +client_connected (void *cls, struct GNUNET_SERVER_Client *client) +{ + if (NULL == client) + { + GNUNET_break (0 == nconn); + return; + } + GNUNET_SERVER_client_persist_ (client); + nconn++; +} + + +/** * Testbed setup * * @param cls closure @@ -180,6 +244,8 @@ logger_run (void *cls, struct GNUNET_SERVER_Handle *server, } GNUNET_free (fn); GNUNET_SERVER_add_handlers (server, message_handlers); + GNUNET_SERVER_connect_notify (server, &client_connected, NULL); + GNUNET_SERVER_disconnect_notify (server, &client_disconnected, NULL); shutdown_task_id = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task, NULL); |