diff options
Diffstat (limited to 'src/statistics/gnunet-statistics.c')
-rw-r--r-- | src/statistics/gnunet-statistics.c | 88 |
1 files changed, 63 insertions, 25 deletions
diff --git a/src/statistics/gnunet-statistics.c b/src/statistics/gnunet-statistics.c index f21da6059..192a450ac 100644 --- a/src/statistics/gnunet-statistics.c +++ b/src/statistics/gnunet-statistics.c | |||
@@ -29,7 +29,6 @@ | |||
29 | #include "gnunet_statistics_service.h" | 29 | #include "gnunet_statistics_service.h" |
30 | #include "statistics.h" | 30 | #include "statistics.h" |
31 | 31 | ||
32 | #define GET_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1) | ||
33 | 32 | ||
34 | /** | 33 | /** |
35 | * Final status code. | 34 | * Final status code. |
@@ -69,7 +68,7 @@ static char *remote_host; | |||
69 | /** | 68 | /** |
70 | * Remote host's port | 69 | * Remote host's port |
71 | */ | 70 | */ |
72 | static unsigned long long remote_port; | 71 | static unsigned long long remote_port; |
73 | 72 | ||
74 | /** | 73 | /** |
75 | * Value to set | 74 | * Value to set |
@@ -81,6 +80,11 @@ static unsigned long long set_val; | |||
81 | */ | 80 | */ |
82 | static int set_value; | 81 | static int set_value; |
83 | 82 | ||
83 | /** | ||
84 | * Handle for pending GET operation. | ||
85 | */ | ||
86 | static struct GNUNET_STATISTICS_GetHandle *gh; | ||
87 | |||
84 | 88 | ||
85 | /** | 89 | /** |
86 | * Callback function to process statistic values. | 90 | * Callback function to process statistic values. |
@@ -134,10 +138,11 @@ printer (void *cls, | |||
134 | * successfully obtained, #GNUNET_SYSERR if not. | 138 | * successfully obtained, #GNUNET_SYSERR if not. |
135 | */ | 139 | */ |
136 | static void | 140 | static void |
137 | cleanup (void *cls, int success) | 141 | cleanup (void *cls, |
142 | int success) | ||
138 | { | 143 | { |
139 | 144 | gh = NULL; | |
140 | if (success != GNUNET_OK) | 145 | if (GNUNET_OK != success) |
141 | { | 146 | { |
142 | if (NULL == remote_host) | 147 | if (NULL == remote_host) |
143 | FPRINTF (stderr, | 148 | FPRINTF (stderr, |
@@ -166,12 +171,21 @@ shutdown_task (void *cls) | |||
166 | 171 | ||
167 | if (NULL == h) | 172 | if (NULL == h) |
168 | return; | 173 | return; |
174 | if (NULL != gh) | ||
175 | { | ||
176 | GNUNET_STATISTICS_get_cancel (gh); | ||
177 | gh = NULL; | ||
178 | } | ||
169 | if ( (GNUNET_YES == watch) && | 179 | if ( (GNUNET_YES == watch) && |
170 | (NULL != subsystem) && | 180 | (NULL != subsystem) && |
171 | (NULL != name) ) | 181 | (NULL != name) ) |
172 | GNUNET_assert (GNUNET_OK == | 182 | GNUNET_assert (GNUNET_OK == |
173 | GNUNET_STATISTICS_watch_cancel (h, subsystem, name, &printer, h)); | 183 | GNUNET_STATISTICS_watch_cancel (h, |
174 | GNUNET_STATISTICS_destroy (h, GNUNET_NO); | 184 | subsystem, |
185 | name, | ||
186 | &printer, h)); | ||
187 | GNUNET_STATISTICS_destroy (h, | ||
188 | GNUNET_NO); | ||
175 | h = NULL; | 189 | h = NULL; |
176 | } | 190 | } |
177 | 191 | ||
@@ -207,12 +221,17 @@ main_task (void *cls) | |||
207 | ret = 1; | 221 | ret = 1; |
208 | return; | 222 | return; |
209 | } | 223 | } |
210 | GNUNET_STATISTICS_set (h, name, (uint64_t) set_val, persistent); | 224 | GNUNET_STATISTICS_set (h, |
211 | GNUNET_STATISTICS_destroy (h, GNUNET_YES); | 225 | name, |
226 | (uint64_t) set_val, | ||
227 | persistent); | ||
228 | GNUNET_STATISTICS_destroy (h, | ||
229 | GNUNET_YES); | ||
212 | h = NULL; | 230 | h = NULL; |
213 | return; | 231 | return; |
214 | } | 232 | } |
215 | if (NULL == (h = GNUNET_STATISTICS_create ("gnunet-statistics", cfg))) | 233 | if (NULL == (h = GNUNET_STATISTICS_create ("gnunet-statistics", |
234 | cfg))) | ||
216 | { | 235 | { |
217 | ret = 1; | 236 | ret = 1; |
218 | return; | 237 | return; |
@@ -220,10 +239,12 @@ main_task (void *cls) | |||
220 | if (GNUNET_NO == watch) | 239 | if (GNUNET_NO == watch) |
221 | { | 240 | { |
222 | if (NULL == | 241 | if (NULL == |
223 | GNUNET_STATISTICS_get (h, subsystem, name, GET_TIMEOUT, | 242 | (gh = GNUNET_STATISTICS_get (h, |
224 | &cleanup, | 243 | subsystem, |
225 | &printer, h)) | 244 | name, |
226 | cleanup (h, GNUNET_SYSERR); | 245 | &cleanup, |
246 | &printer, h)) ) | ||
247 | cleanup (h, GNUNET_SYSERR); | ||
227 | } | 248 | } |
228 | else | 249 | else |
229 | { | 250 | { |
@@ -235,15 +256,21 @@ main_task (void *cls) | |||
235 | ret = 1; | 256 | ret = 1; |
236 | return; | 257 | return; |
237 | } | 258 | } |
238 | if (GNUNET_OK != GNUNET_STATISTICS_watch (h, subsystem, name, | 259 | if (GNUNET_OK != |
239 | &printer, h)) | 260 | GNUNET_STATISTICS_watch (h, |
261 | subsystem, | ||
262 | name, | ||
263 | &printer, h)) | ||
240 | { | 264 | { |
241 | fprintf (stderr, _("Failed to initialize watch routine\n")); | 265 | fprintf (stderr, |
242 | GNUNET_SCHEDULER_add_now (&shutdown_task, h); | 266 | _("Failed to initialize watch routine\n")); |
267 | GNUNET_SCHEDULER_add_now (&shutdown_task, | ||
268 | h); | ||
243 | return; | 269 | return; |
244 | } | 270 | } |
245 | } | 271 | } |
246 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, h); | 272 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, |
273 | h); | ||
247 | } | 274 | } |
248 | 275 | ||
249 | 276 | ||
@@ -291,11 +318,17 @@ resolver_test_task (void *cls, | |||
291 | 318 | ||
292 | /* Manipulate configuration */ | 319 | /* Manipulate configuration */ |
293 | GNUNET_CONFIGURATION_set_value_string (cfg, | 320 | GNUNET_CONFIGURATION_set_value_string (cfg, |
294 | "statistics", "UNIXPATH", ""); | 321 | "statistics", |
322 | "UNIXPATH", | ||
323 | ""); | ||
295 | GNUNET_CONFIGURATION_set_value_string (cfg, | 324 | GNUNET_CONFIGURATION_set_value_string (cfg, |
296 | "statistics", "HOSTNAME", remote_host); | 325 | "statistics", |
326 | "HOSTNAME", | ||
327 | remote_host); | ||
297 | GNUNET_CONFIGURATION_set_value_number (cfg, | 328 | GNUNET_CONFIGURATION_set_value_number (cfg, |
298 | "statistics", "PORT", remote_port); | 329 | "statistics", |
330 | "PORT", | ||
331 | remote_port); | ||
299 | GNUNET_SCHEDULER_add_now (&main_task, cfg); | 332 | GNUNET_SCHEDULER_add_now (&main_task, cfg); |
300 | } | 333 | } |
301 | 334 | ||
@@ -309,7 +342,9 @@ resolver_test_task (void *cls, | |||
309 | * @param cfg configuration | 342 | * @param cfg configuration |
310 | */ | 343 | */ |
311 | static void | 344 | static void |
312 | run (void *cls, char *const *args, const char *cfgfile, | 345 | run (void *cls, |
346 | char *const *args, | ||
347 | const char *cfgfile, | ||
313 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 348 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
314 | { | 349 | { |
315 | set_value = GNUNET_NO; | 350 | set_value = GNUNET_NO; |
@@ -324,7 +359,9 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
324 | set_value = GNUNET_YES; | 359 | set_value = GNUNET_YES; |
325 | } | 360 | } |
326 | if (NULL != remote_host) | 361 | if (NULL != remote_host) |
327 | GNUNET_CLIENT_service_test ("resolver", cfg, GNUNET_TIME_UNIT_SECONDS, | 362 | GNUNET_CLIENT_service_test ("resolver", |
363 | cfg, | ||
364 | GNUNET_TIME_UNIT_SECONDS, | ||
328 | &resolver_test_task, (void *) cfg); | 365 | &resolver_test_task, (void *) cfg); |
329 | else | 366 | else |
330 | GNUNET_SCHEDULER_add_now (&main_task, (void *) cfg); | 367 | GNUNET_SCHEDULER_add_now (&main_task, (void *) cfg); |
@@ -367,7 +404,8 @@ main (int argc, char *const *argv) | |||
367 | }; | 404 | }; |
368 | remote_port = 0; | 405 | remote_port = 0; |
369 | remote_host = NULL; | 406 | remote_host = NULL; |
370 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) | 407 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, |
408 | &argc, &argv)) | ||
371 | return 2; | 409 | return 2; |
372 | 410 | ||
373 | ret = (GNUNET_OK == | 411 | ret = (GNUNET_OK == |