aboutsummaryrefslogtreecommitdiff
path: root/src/statistics/statistics_api.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2014-03-07 08:51:48 +0000
committerChristian Grothoff <christian@grothoff.org>2014-03-07 08:51:48 +0000
commit727fb60a1f38a1ffb797942c2f169fa6e1e6f05e (patch)
tree35db3b1fa4d9ac53828c8de01a8c429af6421800 /src/statistics/statistics_api.c
parent68c7464f2559dbebaac0e524b85811172f86f6e3 (diff)
downloadgnunet-727fb60a1f38a1ffb797942c2f169fa6e1e6f05e.tar.gz
gnunet-727fb60a1f38a1ffb797942c2f169fa6e1e6f05e.zip
-ensure timeout forces call to continuation even if statistics service cannot be reached
Diffstat (limited to 'src/statistics/statistics_api.c')
-rw-r--r--src/statistics/statistics_api.c45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/statistics/statistics_api.c b/src/statistics/statistics_api.c
index f1adcae4c..52d49308a 100644
--- a/src/statistics/statistics_api.c
+++ b/src/statistics/statistics_api.c
@@ -147,6 +147,11 @@ struct GNUNET_STATISTICS_GetHandle
147 struct GNUNET_TIME_Absolute timeout; 147 struct GNUNET_TIME_Absolute timeout;
148 148
149 /** 149 /**
150 * Task run on timeout.
151 */
152 GNUNET_SCHEDULER_TaskIdentifier timeout_task;
153
154 /**
150 * Associated value. 155 * Associated value.
151 */ 156 */
152 uint64_t value; 157 uint64_t value;
@@ -362,6 +367,11 @@ schedule_watch_request (struct GNUNET_STATISTICS_Handle *h,
362static void 367static void
363free_action_item (struct GNUNET_STATISTICS_GetHandle *gh) 368free_action_item (struct GNUNET_STATISTICS_GetHandle *gh)
364{ 369{
370 if (GNUNET_SCHEDULER_NO_TASK != gh->timeout_task)
371 {
372 GNUNET_SCHEDULER_cancel (gh->timeout_task);
373 gh->timeout_task = GNUNET_SCHEDULER_NO_TASK;
374 }
365 GNUNET_free_non_null (gh->subsystem); 375 GNUNET_free_non_null (gh->subsystem);
366 GNUNET_free_non_null (gh->name); 376 GNUNET_free_non_null (gh->name);
367 GNUNET_free (gh); 377 GNUNET_free (gh);
@@ -389,7 +399,10 @@ do_disconnect (struct GNUNET_STATISTICS_Handle *h)
389 h->current = NULL; 399 h->current = NULL;
390 if ( (NULL != c->cont) && 400 if ( (NULL != c->cont) &&
391 (GNUNET_YES != c->aborted) ) 401 (GNUNET_YES != c->aborted) )
402 {
392 c->cont (c->cls, GNUNET_SYSERR); 403 c->cont (c->cls, GNUNET_SYSERR);
404 c->cont = NULL;
405 }
393 free_action_item (c); 406 free_action_item (c);
394 } 407 }
395 if (NULL != h->client) 408 if (NULL != h->client)
@@ -687,7 +700,10 @@ receive_stats (void *cls,
687 h->current = NULL; 700 h->current = NULL;
688 schedule_action (h); 701 schedule_action (h);
689 if (NULL != c->cont) 702 if (NULL != c->cont)
703 {
690 c->cont (c->cls, GNUNET_OK); 704 c->cont (c->cls, GNUNET_OK);
705 c->cont = NULL;
706 }
691 free_action_item (c); 707 free_action_item (c);
692 return; 708 return;
693 case GNUNET_MESSAGE_TYPE_STATISTICS_VALUE: 709 case GNUNET_MESSAGE_TYPE_STATISTICS_VALUE:
@@ -1142,6 +1158,27 @@ schedule_action (struct GNUNET_STATISTICS_Handle *h)
1142 1158
1143 1159
1144/** 1160/**
1161 * We have run into a timeout on a #GNUNET_STATISTICS_get() operation,
1162 * call the continuation.
1163 *
1164 * @param cls the `struct GNUNET_STATISTICS_GetHandle`
1165 * @param tc scheduler context
1166 */
1167static void
1168run_get_timeout (void *cls,
1169 const struct GNUNET_SCHEDULER_TaskContext *tc)
1170{
1171 struct GNUNET_STATISTICS_GetHandle *gh = cls;
1172 GNUNET_STATISTICS_Callback cont = gh->cont;
1173 void *cont_cls = gh->cls;
1174
1175 gh->timeout_task = GNUNET_SCHEDULER_NO_TASK;
1176 GNUNET_STATISTICS_get_cancel (gh);
1177 cont (cont_cls, GNUNET_SYSERR);
1178}
1179
1180
1181/**
1145 * Get statistic from the peer. 1182 * Get statistic from the peer.
1146 * 1183 *
1147 * @param handle identification of the statistics service 1184 * @param handle identification of the statistics service
@@ -1188,6 +1225,9 @@ GNUNET_STATISTICS_get (struct GNUNET_STATISTICS_Handle *handle,
1188 ai->timeout = GNUNET_TIME_relative_to_absolute (timeout); 1225 ai->timeout = GNUNET_TIME_relative_to_absolute (timeout);
1189 ai->type = ACTION_GET; 1226 ai->type = ACTION_GET;
1190 ai->msize = slen1 + slen2 + sizeof (struct GNUNET_MessageHeader); 1227 ai->msize = slen1 + slen2 + sizeof (struct GNUNET_MessageHeader);
1228 ai->timeout_task = GNUNET_SCHEDULER_add_delayed (timeout,
1229 &run_get_timeout,
1230 ai);
1191 GNUNET_CONTAINER_DLL_insert_tail (handle->action_head, handle->action_tail, 1231 GNUNET_CONTAINER_DLL_insert_tail (handle->action_head, handle->action_tail,
1192 ai); 1232 ai);
1193 schedule_action (handle); 1233 schedule_action (handle);
@@ -1206,6 +1246,11 @@ GNUNET_STATISTICS_get_cancel (struct GNUNET_STATISTICS_GetHandle *gh)
1206{ 1246{
1207 if (NULL == gh) 1247 if (NULL == gh)
1208 return; 1248 return;
1249 if (GNUNET_SCHEDULER_NO_TASK != gh->timeout_task)
1250 {
1251 GNUNET_SCHEDULER_cancel (gh->timeout_task);
1252 gh->timeout_task = GNUNET_SCHEDULER_NO_TASK;
1253 }
1209 gh->cont = NULL; 1254 gh->cont = NULL;
1210 if (gh->sh->current == gh) 1255 if (gh->sh->current == gh)
1211 { 1256 {