diff options
author | Christian Grothoff <christian@grothoff.org> | 2010-03-12 12:36:50 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2010-03-12 12:36:50 +0000 |
commit | 61cfd3340e67672f351ab92dab7da72dca058c79 (patch) | |
tree | 7144d056b877397aff501ec7f36e42f659350be8 | |
parent | 6324d68ac07d6cc498c934727ba5970909741c85 (diff) | |
download | gnunet-61cfd3340e67672f351ab92dab7da72dca058c79.tar.gz gnunet-61cfd3340e67672f351ab92dab7da72dca058c79.zip |
enable stats get cancellation
-rw-r--r-- | src/datastore/gnunet-service-datastore.c | 30 | ||||
-rw-r--r-- | src/datastore/plugin_datastore_sqlite.c | 34 | ||||
-rw-r--r-- | src/include/gnunet_statistics_service.h | 19 | ||||
-rw-r--r-- | src/statistics/gnunet-statistics.c | 5 | ||||
-rw-r--r-- | src/statistics/statistics_api.c | 120 | ||||
-rw-r--r-- | src/statistics/test_statistics_api.c | 15 |
6 files changed, 154 insertions, 69 deletions
diff --git a/src/datastore/gnunet-service-datastore.c b/src/datastore/gnunet-service-datastore.c index cededcca8..fac1ff1d0 100644 --- a/src/datastore/gnunet-service-datastore.c +++ b/src/datastore/gnunet-service-datastore.c | |||
@@ -1230,6 +1230,24 @@ unload_plugin (struct DatastorePlugin *plug) | |||
1230 | 1230 | ||
1231 | 1231 | ||
1232 | /** | 1232 | /** |
1233 | * Final task run after shutdown. Unloads plugins and disconnects us from | ||
1234 | * statistics. | ||
1235 | */ | ||
1236 | static void | ||
1237 | unload_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
1238 | { | ||
1239 | unload_plugin (plugin); | ||
1240 | plugin = NULL; | ||
1241 | if (filter != NULL) | ||
1242 | { | ||
1243 | GNUNET_CONTAINER_bloomfilter_free (filter); | ||
1244 | filter = NULL; | ||
1245 | } | ||
1246 | GNUNET_ARM_stop_services (cfg, tc->sched, "statistics", NULL); | ||
1247 | } | ||
1248 | |||
1249 | |||
1250 | /** | ||
1233 | * Last task run during shutdown. Disconnects us from | 1251 | * Last task run during shutdown. Disconnects us from |
1234 | * the transport and core. | 1252 | * the transport and core. |
1235 | */ | 1253 | */ |
@@ -1256,14 +1274,10 @@ cleaning_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1256 | expired_kill_task); | 1274 | expired_kill_task); |
1257 | expired_kill_task = GNUNET_SCHEDULER_NO_TASK; | 1275 | expired_kill_task = GNUNET_SCHEDULER_NO_TASK; |
1258 | } | 1276 | } |
1259 | unload_plugin (plugin); | 1277 | GNUNET_SCHEDULER_add_continuation (sched, |
1260 | plugin = NULL; | 1278 | &unload_task, |
1261 | if (filter != NULL) | 1279 | NULL, |
1262 | { | 1280 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); |
1263 | GNUNET_CONTAINER_bloomfilter_free (filter); | ||
1264 | filter = NULL; | ||
1265 | } | ||
1266 | GNUNET_ARM_stop_services (cfg, tc->sched, "statistics", NULL); | ||
1267 | } | 1281 | } |
1268 | 1282 | ||
1269 | 1283 | ||
diff --git a/src/datastore/plugin_datastore_sqlite.c b/src/datastore/plugin_datastore_sqlite.c index 2fc28e13e..9356b79ed 100644 --- a/src/datastore/plugin_datastore_sqlite.c +++ b/src/datastore/plugin_datastore_sqlite.c | |||
@@ -91,6 +91,7 @@ | |||
91 | #define BUSY_TIMEOUT_MS 250 | 91 | #define BUSY_TIMEOUT_MS 250 |
92 | 92 | ||
93 | 93 | ||
94 | |||
94 | /** | 95 | /** |
95 | * Context for all functions in this plugin. | 96 | * Context for all functions in this plugin. |
96 | */ | 97 | */ |
@@ -125,6 +126,11 @@ struct Plugin | |||
125 | * Handle to the statistics service. | 126 | * Handle to the statistics service. |
126 | */ | 127 | */ |
127 | struct GNUNET_STATISTICS_Handle *statistics; | 128 | struct GNUNET_STATISTICS_Handle *statistics; |
129 | |||
130 | /** | ||
131 | * Handle for pending get request. | ||
132 | */ | ||
133 | struct GNUNET_STATISTICS_GetHandle *stat_get; | ||
128 | 134 | ||
129 | /** | 135 | /** |
130 | * How much data are we currently storing | 136 | * How much data are we currently storing |
@@ -1559,6 +1565,15 @@ process_stat_in (void *cls, | |||
1559 | #endif | 1565 | #endif |
1560 | return GNUNET_OK; | 1566 | return GNUNET_OK; |
1561 | } | 1567 | } |
1568 | |||
1569 | |||
1570 | static void | ||
1571 | process_stat_done (void *cls, | ||
1572 | int success) | ||
1573 | { | ||
1574 | struct Plugin *plugin = cls; | ||
1575 | plugin->stat_get = NULL; | ||
1576 | } | ||
1562 | 1577 | ||
1563 | 1578 | ||
1564 | /** | 1579 | /** |
@@ -1581,13 +1596,13 @@ libgnunet_plugin_datastore_sqlite_init (void *cls) | |||
1581 | plugin.statistics = GNUNET_STATISTICS_create (env->sched, | 1596 | plugin.statistics = GNUNET_STATISTICS_create (env->sched, |
1582 | "sqlite", | 1597 | "sqlite", |
1583 | env->cfg); | 1598 | env->cfg); |
1584 | GNUNET_STATISTICS_get (plugin.statistics, | 1599 | plugin.stat_get = GNUNET_STATISTICS_get (plugin.statistics, |
1585 | "sqlite", | 1600 | "sqlite", |
1586 | QUOTA_STAT_NAME, | 1601 | QUOTA_STAT_NAME, |
1587 | GNUNET_TIME_UNIT_MINUTES, | 1602 | GNUNET_TIME_UNIT_MINUTES, |
1588 | NULL, | 1603 | &process_stat_done, |
1589 | &process_stat_in, | 1604 | &process_stat_in, |
1590 | &plugin); | 1605 | &plugin); |
1591 | if (GNUNET_OK != | 1606 | if (GNUNET_OK != |
1592 | database_setup (env->cfg, &plugin)) | 1607 | database_setup (env->cfg, &plugin)) |
1593 | { | 1608 | { |
@@ -1626,6 +1641,11 @@ libgnunet_plugin_datastore_sqlite_done (void *cls) | |||
1626 | struct GNUNET_DATASTORE_PluginFunctions *api = cls; | 1641 | struct GNUNET_DATASTORE_PluginFunctions *api = cls; |
1627 | struct Plugin *plugin = api->cls; | 1642 | struct Plugin *plugin = api->cls; |
1628 | 1643 | ||
1644 | if (plugin->stat_get != NULL) | ||
1645 | { | ||
1646 | GNUNET_STATISTICS_get_cancel (plugin->stat_get); | ||
1647 | plugin->stat_get = NULL; | ||
1648 | } | ||
1629 | fn = NULL; | 1649 | fn = NULL; |
1630 | if (plugin->drop_on_shutdown) | 1650 | if (plugin->drop_on_shutdown) |
1631 | fn = GNUNET_strdup (plugin->fn); | 1651 | fn = GNUNET_strdup (plugin->fn); |
diff --git a/src/include/gnunet_statistics_service.h b/src/include/gnunet_statistics_service.h index 0fc84cfc3..5c166d43d 100644 --- a/src/include/gnunet_statistics_service.h +++ b/src/include/gnunet_statistics_service.h | |||
@@ -103,6 +103,11 @@ void GNUNET_STATISTICS_destroy (struct GNUNET_STATISTICS_Handle *h, | |||
103 | typedef void (*GNUNET_STATISTICS_Callback) (void *cls, int success); | 103 | typedef void (*GNUNET_STATISTICS_Callback) (void *cls, int success); |
104 | 104 | ||
105 | /** | 105 | /** |
106 | * Handle that can be used to cancel a statistics 'get' operation. | ||
107 | */ | ||
108 | struct GNUNET_STATISTICS_GetHandle; | ||
109 | |||
110 | /** | ||
106 | * Get statistic from the peer. | 111 | * Get statistic from the peer. |
107 | * | 112 | * |
108 | * @param handle identification of the statistics service | 113 | * @param handle identification of the statistics service |
@@ -113,8 +118,9 @@ typedef void (*GNUNET_STATISTICS_Callback) (void *cls, int success); | |||
113 | * @param cont continuation to call when done (can be NULL) | 118 | * @param cont continuation to call when done (can be NULL) |
114 | * @param proc function to call on each value | 119 | * @param proc function to call on each value |
115 | * @param cls closure for proc and cont | 120 | * @param cls closure for proc and cont |
121 | * @return NULL on error | ||
116 | */ | 122 | */ |
117 | void | 123 | struct GNUNET_STATISTICS_GetHandle * |
118 | GNUNET_STATISTICS_get (struct GNUNET_STATISTICS_Handle *handle, | 124 | GNUNET_STATISTICS_get (struct GNUNET_STATISTICS_Handle *handle, |
119 | const char *subsystem, | 125 | const char *subsystem, |
120 | const char *name, | 126 | const char *name, |
@@ -122,6 +128,17 @@ GNUNET_STATISTICS_get (struct GNUNET_STATISTICS_Handle *handle, | |||
122 | GNUNET_STATISTICS_Callback cont, | 128 | GNUNET_STATISTICS_Callback cont, |
123 | GNUNET_STATISTICS_Iterator proc, void *cls); | 129 | GNUNET_STATISTICS_Iterator proc, void *cls); |
124 | 130 | ||
131 | |||
132 | /** | ||
133 | * Cancel a 'get' request. Must be called before the 'cont' | ||
134 | * function is called. | ||
135 | * | ||
136 | * @param gh handle of the request to cancel | ||
137 | */ | ||
138 | void | ||
139 | GNUNET_STATISTICS_get_cancel (struct GNUNET_STATISTICS_GetHandle *gh); | ||
140 | |||
141 | |||
125 | /** | 142 | /** |
126 | * Set statistic value for the peer. Will always use our | 143 | * Set statistic value for the peer. Will always use our |
127 | * subsystem (the argument used when "handle" was created). | 144 | * subsystem (the argument used when "handle" was created). |
diff --git a/src/statistics/gnunet-statistics.c b/src/statistics/gnunet-statistics.c index f51452699..e996bb728 100644 --- a/src/statistics/gnunet-statistics.c +++ b/src/statistics/gnunet-statistics.c | |||
@@ -140,8 +140,9 @@ run (void *cls, | |||
140 | ret = 1; | 140 | ret = 1; |
141 | return; | 141 | return; |
142 | } | 142 | } |
143 | GNUNET_STATISTICS_get (h, | 143 | if (NULL == GNUNET_STATISTICS_get (h, |
144 | subsystem, name, GET_TIMEOUT, &cleanup, &printer, h); | 144 | subsystem, name, GET_TIMEOUT, &cleanup, &printer, h)) |
145 | cleanup (h, GNUNET_SYSERR); | ||
145 | } | 146 | } |
146 | 147 | ||
147 | /** | 148 | /** |
diff --git a/src/statistics/statistics_api.c b/src/statistics/statistics_api.c index 86950ad4c..e9ebe7fa6 100644 --- a/src/statistics/statistics_api.c +++ b/src/statistics/statistics_api.c | |||
@@ -25,6 +25,7 @@ | |||
25 | */ | 25 | */ |
26 | #include "platform.h" | 26 | #include "platform.h" |
27 | #include "gnunet_client_lib.h" | 27 | #include "gnunet_client_lib.h" |
28 | #include "gnunet_container_lib.h" | ||
28 | #include "gnunet_protocols.h" | 29 | #include "gnunet_protocols.h" |
29 | #include "gnunet_server_lib.h" | 30 | #include "gnunet_server_lib.h" |
30 | #include "gnunet_statistics_service.h" | 31 | #include "gnunet_statistics_service.h" |
@@ -48,14 +49,25 @@ enum ActionType | |||
48 | /** | 49 | /** |
49 | * Linked list of things we still need to do. | 50 | * Linked list of things we still need to do. |
50 | */ | 51 | */ |
51 | struct ActionItem | 52 | struct GNUNET_STATISTICS_GetHandle |
52 | { | 53 | { |
54 | |||
55 | /** | ||
56 | * This is a doubly linked list. | ||
57 | */ | ||
58 | struct GNUNET_STATISTICS_GetHandle *next; | ||
59 | |||
53 | /** | 60 | /** |
54 | * This is a linked list. | 61 | * This is a doubly linked list. |
55 | */ | 62 | */ |
56 | struct ActionItem *next; | 63 | struct GNUNET_STATISTICS_GetHandle *prev; |
57 | 64 | ||
58 | /** | 65 | /** |
66 | * Main statistics handle. | ||
67 | */ | ||
68 | struct GNUNET_STATISTICS_Handle *sh; | ||
69 | |||
70 | /** | ||
59 | * What subsystem is this action about? (can be NULL) | 71 | * What subsystem is this action about? (can be NULL) |
60 | */ | 72 | */ |
61 | char *subsystem; | 73 | char *subsystem; |
@@ -147,19 +159,19 @@ struct GNUNET_STATISTICS_Handle | |||
147 | * Head of the linked list of pending actions (first action | 159 | * Head of the linked list of pending actions (first action |
148 | * to be performed). | 160 | * to be performed). |
149 | */ | 161 | */ |
150 | struct ActionItem *action_head; | 162 | struct GNUNET_STATISTICS_GetHandle *action_head; |
151 | 163 | ||
152 | /** | 164 | /** |
153 | * Tail of the linked list of actions (for fast append). | 165 | * Tail of the linked list of actions (for fast append). |
154 | */ | 166 | */ |
155 | struct ActionItem *action_tail; | 167 | struct GNUNET_STATISTICS_GetHandle *action_tail; |
156 | 168 | ||
157 | /** | 169 | /** |
158 | * Action we are currently busy with (action request has been | 170 | * Action we are currently busy with (action request has been |
159 | * transmitted, we're now receiving the response from the | 171 | * transmitted, we're now receiving the response from the |
160 | * service). | 172 | * service). |
161 | */ | 173 | */ |
162 | struct ActionItem *current; | 174 | struct GNUNET_STATISTICS_GetHandle *current; |
163 | 175 | ||
164 | /** | 176 | /** |
165 | * Should this handle auto-destruct once all actions have | 177 | * Should this handle auto-destruct once all actions have |
@@ -195,7 +207,7 @@ try_connect (struct GNUNET_STATISTICS_Handle *ret) | |||
195 | * Free memory associated with the given action item. | 207 | * Free memory associated with the given action item. |
196 | */ | 208 | */ |
197 | static void | 209 | static void |
198 | free_action_item (struct ActionItem *ai) | 210 | free_action_item (struct GNUNET_STATISTICS_GetHandle *ai) |
199 | { | 211 | { |
200 | GNUNET_free_non_null (ai->subsystem); | 212 | GNUNET_free_non_null (ai->subsystem); |
201 | GNUNET_free_non_null (ai->name); | 213 | GNUNET_free_non_null (ai->name); |
@@ -203,9 +215,6 @@ free_action_item (struct ActionItem *ai) | |||
203 | } | 215 | } |
204 | 216 | ||
205 | 217 | ||
206 | |||
207 | |||
208 | |||
209 | /** | 218 | /** |
210 | * Schedule the next action to be performed. | 219 | * Schedule the next action to be performed. |
211 | */ | 220 | */ |
@@ -218,7 +227,7 @@ static void schedule_action (struct GNUNET_STATISTICS_Handle *h); | |||
218 | static void | 227 | static void |
219 | finish (struct GNUNET_STATISTICS_Handle *h, int code) | 228 | finish (struct GNUNET_STATISTICS_Handle *h, int code) |
220 | { | 229 | { |
221 | struct ActionItem *pos = h->current; | 230 | struct GNUNET_STATISTICS_GetHandle *pos = h->current; |
222 | h->current = NULL; | 231 | h->current = NULL; |
223 | schedule_action (h); | 232 | schedule_action (h); |
224 | if (pos->cont != NULL) | 233 | if (pos->cont != NULL) |
@@ -264,17 +273,17 @@ process_message (struct GNUNET_STATISTICS_Handle *h, | |||
264 | #endif | 273 | #endif |
265 | if (GNUNET_OK != | 274 | if (GNUNET_OK != |
266 | h->current->proc (h->current->cls, | 275 | h->current->proc (h->current->cls, |
267 | service, | 276 | service, |
268 | name, | 277 | name, |
269 | GNUNET_ntohll (smsg->value), | 278 | GNUNET_ntohll (smsg->value), |
270 | 0 != | 279 | 0 != |
271 | (ntohl (smsg->uid) & GNUNET_STATISTICS_PERSIST_BIT))) | 280 | (ntohl (smsg->uid) & GNUNET_STATISTICS_PERSIST_BIT))) |
272 | { | 281 | { |
273 | #if DEBUG_STATISTICS | 282 | #if DEBUG_STATISTICS |
274 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 283 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
275 | "Processing of remaining statistics aborted by client.\n"); | 284 | "Processing of remaining statistics aborted by client.\n"); |
276 | #endif | 285 | #endif |
277 | h->current->aborted = GNUNET_YES; | 286 | h->current->aborted = GNUNET_YES; |
278 | } | 287 | } |
279 | return GNUNET_OK; | 288 | return GNUNET_OK; |
280 | } | 289 | } |
@@ -495,9 +504,9 @@ void | |||
495 | GNUNET_STATISTICS_destroy (struct GNUNET_STATISTICS_Handle *h, | 504 | GNUNET_STATISTICS_destroy (struct GNUNET_STATISTICS_Handle *h, |
496 | int sync_first) | 505 | int sync_first) |
497 | { | 506 | { |
498 | struct ActionItem *pos; | 507 | struct GNUNET_STATISTICS_GetHandle *pos; |
499 | struct ActionItem *next; | 508 | struct GNUNET_STATISTICS_GetHandle *next; |
500 | struct ActionItem *prev; | 509 | struct GNUNET_STATISTICS_GetHandle *prev; |
501 | struct GNUNET_TIME_Relative timeout; | 510 | struct GNUNET_TIME_Relative timeout; |
502 | 511 | ||
503 | if (sync_first) | 512 | if (sync_first) |
@@ -606,10 +615,9 @@ schedule_action (struct GNUNET_STATISTICS_Handle *h) | |||
606 | } | 615 | } |
607 | return; | 616 | return; |
608 | } | 617 | } |
609 | h->action_head = h->action_head->next; | 618 | GNUNET_CONTAINER_DLL_remove (h->action_head, |
610 | if (NULL == h->action_head) | 619 | h->action_tail, |
611 | h->action_tail = NULL; | 620 | h->current); |
612 | h->current->next = NULL; | ||
613 | timeout = GNUNET_TIME_absolute_get_remaining (h->current->timeout); | 621 | timeout = GNUNET_TIME_absolute_get_remaining (h->current->timeout); |
614 | if (NULL == | 622 | if (NULL == |
615 | (h->th = GNUNET_CLIENT_notify_transmit_ready (h->client, | 623 | (h->th = GNUNET_CLIENT_notify_transmit_ready (h->client, |
@@ -628,19 +636,14 @@ schedule_action (struct GNUNET_STATISTICS_Handle *h) | |||
628 | 636 | ||
629 | 637 | ||
630 | static void | 638 | static void |
631 | insert_ai (struct GNUNET_STATISTICS_Handle *h, struct ActionItem *ai) | 639 | insert_ai (struct GNUNET_STATISTICS_Handle *h, struct GNUNET_STATISTICS_GetHandle *ai) |
632 | { | 640 | { |
633 | if (h->action_tail == NULL) | 641 | GNUNET_CONTAINER_DLL_insert_after (h->action_head, |
634 | { | 642 | h->action_tail, |
635 | h->action_head = ai; | 643 | h->action_tail, |
636 | h->action_tail = ai; | 644 | ai); |
637 | schedule_action (h); | 645 | if (h->action_head == ai) |
638 | } | 646 | schedule_action (h); |
639 | else | ||
640 | { | ||
641 | h->action_tail->next = ai; | ||
642 | h->action_tail = ai; | ||
643 | } | ||
644 | } | 647 | } |
645 | 648 | ||
646 | 649 | ||
@@ -655,8 +658,9 @@ insert_ai (struct GNUNET_STATISTICS_Handle *h, struct ActionItem *ai) | |||
655 | * @param cont continuation to call when done (can be NULL) | 658 | * @param cont continuation to call when done (can be NULL) |
656 | * @param proc function to call on each value | 659 | * @param proc function to call on each value |
657 | * @param cls closure for cont and proc | 660 | * @param cls closure for cont and proc |
661 | * @return NULL on error | ||
658 | */ | 662 | */ |
659 | void | 663 | struct GNUNET_STATISTICS_GetHandle * |
660 | GNUNET_STATISTICS_get (struct GNUNET_STATISTICS_Handle *handle, | 664 | GNUNET_STATISTICS_get (struct GNUNET_STATISTICS_Handle *handle, |
661 | const char *subsystem, | 665 | const char *subsystem, |
662 | const char *name, | 666 | const char *name, |
@@ -666,7 +670,7 @@ GNUNET_STATISTICS_get (struct GNUNET_STATISTICS_Handle *handle, | |||
666 | { | 670 | { |
667 | size_t slen1; | 671 | size_t slen1; |
668 | size_t slen2; | 672 | size_t slen2; |
669 | struct ActionItem *ai; | 673 | struct GNUNET_STATISTICS_GetHandle *ai; |
670 | 674 | ||
671 | GNUNET_assert (handle != NULL); | 675 | GNUNET_assert (handle != NULL); |
672 | GNUNET_assert (proc != NULL); | 676 | GNUNET_assert (proc != NULL); |
@@ -679,9 +683,7 @@ GNUNET_STATISTICS_get (struct GNUNET_STATISTICS_Handle *handle, | |||
679 | strlen (subsystem) ? subsystem : "*", | 683 | strlen (subsystem) ? subsystem : "*", |
680 | strlen (name) ? name : "*"); | 684 | strlen (name) ? name : "*"); |
681 | #endif | 685 | #endif |
682 | if (cont != NULL) | 686 | return NULL; |
683 | cont (cls, GNUNET_SYSERR); | ||
684 | return; | ||
685 | } | 687 | } |
686 | if (subsystem == NULL) | 688 | if (subsystem == NULL) |
687 | subsystem = ""; | 689 | subsystem = ""; |
@@ -691,7 +693,8 @@ GNUNET_STATISTICS_get (struct GNUNET_STATISTICS_Handle *handle, | |||
691 | slen2 = strlen (name); | 693 | slen2 = strlen (name); |
692 | GNUNET_assert (slen1 + slen2 + sizeof (struct GNUNET_MessageHeader) < | 694 | GNUNET_assert (slen1 + slen2 + sizeof (struct GNUNET_MessageHeader) < |
693 | GNUNET_SERVER_MAX_MESSAGE_SIZE); | 695 | GNUNET_SERVER_MAX_MESSAGE_SIZE); |
694 | ai = GNUNET_malloc (sizeof (struct ActionItem)); | 696 | ai = GNUNET_malloc (sizeof (struct GNUNET_STATISTICS_GetHandle)); |
697 | ai->sh = handle; | ||
695 | ai->subsystem = GNUNET_strdup (subsystem); | 698 | ai->subsystem = GNUNET_strdup (subsystem); |
696 | ai->name = GNUNET_strdup (name); | 699 | ai->name = GNUNET_strdup (name); |
697 | ai->cont = cont; | 700 | ai->cont = cont; |
@@ -701,6 +704,32 @@ GNUNET_STATISTICS_get (struct GNUNET_STATISTICS_Handle *handle, | |||
701 | ai->type = ACTION_GET; | 704 | ai->type = ACTION_GET; |
702 | ai->msize = slen1 + slen2 + sizeof (struct GNUNET_MessageHeader); | 705 | ai->msize = slen1 + slen2 + sizeof (struct GNUNET_MessageHeader); |
703 | insert_ai (handle, ai); | 706 | insert_ai (handle, ai); |
707 | return ai; | ||
708 | } | ||
709 | |||
710 | |||
711 | /** | ||
712 | * Cancel a 'get' request. Must be called before the 'cont' | ||
713 | * function is called. | ||
714 | * | ||
715 | * @param gh handle of the request to cancel | ||
716 | */ | ||
717 | void | ||
718 | GNUNET_STATISTICS_get_cancel (struct GNUNET_STATISTICS_GetHandle *gh) | ||
719 | { | ||
720 | if (gh->sh->current == gh) | ||
721 | { | ||
722 | gh->aborted = GNUNET_YES; | ||
723 | } | ||
724 | else | ||
725 | { | ||
726 | GNUNET_CONTAINER_DLL_remove (gh->sh->action_head, | ||
727 | gh->sh->action_tail, | ||
728 | gh); | ||
729 | GNUNET_free (gh->name); | ||
730 | GNUNET_free (gh->subsystem); | ||
731 | GNUNET_free (gh); | ||
732 | } | ||
704 | } | 733 | } |
705 | 734 | ||
706 | 735 | ||
@@ -710,7 +739,7 @@ add_setter_action (struct GNUNET_STATISTICS_Handle *h, | |||
710 | int make_persistent, | 739 | int make_persistent, |
711 | uint64_t value, enum ActionType type) | 740 | uint64_t value, enum ActionType type) |
712 | { | 741 | { |
713 | struct ActionItem *ai; | 742 | struct GNUNET_STATISTICS_GetHandle *ai; |
714 | size_t slen; | 743 | size_t slen; |
715 | size_t nlen; | 744 | size_t nlen; |
716 | size_t nsize; | 745 | size_t nsize; |
@@ -727,7 +756,8 @@ add_setter_action (struct GNUNET_STATISTICS_Handle *h, | |||
727 | GNUNET_break (0); | 756 | GNUNET_break (0); |
728 | return; | 757 | return; |
729 | } | 758 | } |
730 | ai = GNUNET_malloc (sizeof (struct ActionItem)); | 759 | ai = GNUNET_malloc (sizeof (struct GNUNET_STATISTICS_GetHandle)); |
760 | ai->sh = h; | ||
731 | ai->subsystem = GNUNET_strdup (h->subsystem); | 761 | ai->subsystem = GNUNET_strdup (h->subsystem); |
732 | ai->name = GNUNET_strdup (name); | 762 | ai->name = GNUNET_strdup (name); |
733 | ai->timeout = GNUNET_TIME_relative_to_absolute (SET_TRANSMIT_TIMEOUT); | 763 | ai->timeout = GNUNET_TIME_relative_to_absolute (SET_TRANSMIT_TIMEOUT); |
diff --git a/src/statistics/test_statistics_api.c b/src/statistics/test_statistics_api.c index 8a4a5e911..d7eb90b4d 100644 --- a/src/statistics/test_statistics_api.c +++ b/src/statistics/test_statistics_api.c | |||
@@ -83,8 +83,9 @@ static void | |||
83 | next (void *cls, int success) | 83 | next (void *cls, int success) |
84 | { | 84 | { |
85 | GNUNET_assert (success == GNUNET_OK); | 85 | GNUNET_assert (success == GNUNET_OK); |
86 | GNUNET_STATISTICS_get (h, NULL, "test-2", | 86 | GNUNET_break (NULL != |
87 | GNUNET_TIME_UNIT_SECONDS, &next_fin, &check_2, cls); | 87 | GNUNET_STATISTICS_get (h, NULL, "test-2", |
88 | GNUNET_TIME_UNIT_SECONDS, &next_fin, &check_2, cls)); | ||
88 | } | 89 | } |
89 | 90 | ||
90 | static void | 91 | static void |
@@ -100,8 +101,9 @@ run (void *cls, | |||
100 | GNUNET_STATISTICS_set (h, "test-2", 2, GNUNET_NO); | 101 | GNUNET_STATISTICS_set (h, "test-2", 2, GNUNET_NO); |
101 | GNUNET_STATISTICS_set (h, "test-3", 2, GNUNET_NO); | 102 | GNUNET_STATISTICS_set (h, "test-3", 2, GNUNET_NO); |
102 | GNUNET_STATISTICS_update (h, "test-3", 1, GNUNET_YES); | 103 | GNUNET_STATISTICS_update (h, "test-3", 1, GNUNET_YES); |
103 | GNUNET_STATISTICS_get (h, NULL, "test-1", | 104 | GNUNET_break (NULL != |
104 | GNUNET_TIME_UNIT_SECONDS, &next, &check_1, cls); | 105 | GNUNET_STATISTICS_get (h, NULL, "test-1", |
106 | GNUNET_TIME_UNIT_SECONDS, &next, &check_1, cls)); | ||
105 | } | 107 | } |
106 | 108 | ||
107 | static void | 109 | static void |
@@ -112,8 +114,9 @@ run_more (void *cls, | |||
112 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 114 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
113 | { | 115 | { |
114 | h = GNUNET_STATISTICS_create (sched, "test-statistics-api", cfg); | 116 | h = GNUNET_STATISTICS_create (sched, "test-statistics-api", cfg); |
115 | GNUNET_STATISTICS_get (h, NULL, "test-3", | 117 | GNUNET_break (NULL != |
116 | GNUNET_TIME_UNIT_SECONDS, &next_fin, &check_3, cls); | 118 | GNUNET_STATISTICS_get (h, NULL, "test-3", |
119 | GNUNET_TIME_UNIT_SECONDS, &next_fin, &check_3, cls)); | ||
117 | } | 120 | } |
118 | 121 | ||
119 | static int | 122 | static int |