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 | |
parent | 918024cf6824c59e91593b7ade6b8ff8a93a214b (diff) | |
download | gnunet-393254f8297fb32bab8c0ec6af2b03b8e72756c6.tar.gz gnunet-393254f8297fb32bab8c0ec6af2b03b8e72756c6.zip |
- Delay shutdown until all connections are closed.
-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 deaeca543..6bf33e681 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; | |||
86 | static GNUNET_SCHEDULER_TaskIdentifier shutdown_task_id; | 86 | static GNUNET_SCHEDULER_TaskIdentifier shutdown_task_id; |
87 | 87 | ||
88 | /** | 88 | /** |
89 | * The number of connections we have | ||
90 | */ | ||
91 | static unsigned int nconn; | ||
92 | |||
93 | /** | ||
94 | * Are we shutting down? | ||
95 | */ | ||
96 | static int in_shutdown; | ||
97 | |||
98 | /** | ||
89 | * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_ADDHOST messages | 99 | * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_ADDHOST messages |
90 | * | 100 | * |
91 | * @param cls NULL | 101 | * @param cls NULL |
@@ -117,6 +127,15 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
117 | struct MessageQueue *mq_entry; | 127 | struct MessageQueue *mq_entry; |
118 | 128 | ||
119 | shutdown_task_id = GNUNET_SCHEDULER_NO_TASK; | 129 | shutdown_task_id = GNUNET_SCHEDULER_NO_TASK; |
130 | in_shutdown = GNUNET_YES; | ||
131 | if (0 != nconn) | ||
132 | { | ||
133 | /* Delay shutdown if there are active connections */ | ||
134 | shutdown_task_id = GNUNET_SCHEDULER_add_delayed | ||
135 | (GNUNET_TIME_UNIT_FOREVER_REL, | ||
136 | &shutdown_task, NULL); | ||
137 | return; | ||
138 | } | ||
120 | while (NULL != (mq_entry = mq_head)) | 139 | while (NULL != (mq_entry = mq_head)) |
121 | { | 140 | { |
122 | GNUNET_free (mq_entry->msg); | 141 | GNUNET_free (mq_entry->msg); |
@@ -129,6 +148,51 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
129 | 148 | ||
130 | 149 | ||
131 | /** | 150 | /** |
151 | * Functions with this signature are called whenever a client | ||
152 | * is disconnected on the network level. | ||
153 | * | ||
154 | * @param cls closure | ||
155 | * @param client identification of the client; NULL | ||
156 | * for the last call when the server is destroyed | ||
157 | */ | ||
158 | static void | ||
159 | client_disconnected (void *cls, struct GNUNET_SERVER_Client *client) | ||
160 | { | ||
161 | if (NULL == client) | ||
162 | { | ||
163 | GNUNET_break (0 == nconn); | ||
164 | return; | ||
165 | } | ||
166 | nconn--; | ||
167 | if (GNUNET_YES != in_shutdown) | ||
168 | return; | ||
169 | GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != shutdown_task_id); | ||
170 | GNUNET_SCHEDULER_cancel (shutdown_task_id); | ||
171 | shutdown_task_id = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); | ||
172 | } | ||
173 | |||
174 | |||
175 | /** | ||
176 | * Functions with this signature are called whenever a client | ||
177 | * is connected on the network level. | ||
178 | * | ||
179 | * @param cls closure | ||
180 | * @param client identification of the client | ||
181 | */ | ||
182 | static void | ||
183 | client_connected (void *cls, struct GNUNET_SERVER_Client *client) | ||
184 | { | ||
185 | if (NULL == client) | ||
186 | { | ||
187 | GNUNET_break (0 == nconn); | ||
188 | return; | ||
189 | } | ||
190 | GNUNET_SERVER_client_persist_ (client); | ||
191 | nconn++; | ||
192 | } | ||
193 | |||
194 | |||
195 | /** | ||
132 | * Testbed setup | 196 | * Testbed setup |
133 | * | 197 | * |
134 | * @param cls closure | 198 | * @param cls closure |
@@ -180,6 +244,8 @@ logger_run (void *cls, struct GNUNET_SERVER_Handle *server, | |||
180 | } | 244 | } |
181 | GNUNET_free (fn); | 245 | GNUNET_free (fn); |
182 | GNUNET_SERVER_add_handlers (server, message_handlers); | 246 | GNUNET_SERVER_add_handlers (server, message_handlers); |
247 | GNUNET_SERVER_connect_notify (server, &client_connected, NULL); | ||
248 | GNUNET_SERVER_disconnect_notify (server, &client_disconnected, NULL); | ||
183 | shutdown_task_id = | 249 | shutdown_task_id = |
184 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, | 250 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, |
185 | &shutdown_task, NULL); | 251 | &shutdown_task, NULL); |