diff options
author | Martin Schanzenbach <mschanzenbach@posteo.de> | 2020-08-06 23:06:16 +0200 |
---|---|---|
committer | Martin Schanzenbach <mschanzenbach@posteo.de> | 2020-08-06 23:06:16 +0200 |
commit | 7648cde6cfb181f03df9e145a576430220234f5f (patch) | |
tree | 987badd6024e09608b47e72f56052cf79f67b405 /src/gns | |
parent | 19fe8e8ff74a9639fc075f5d974a01a977e1196a (diff) | |
download | gnunet-7648cde6cfb181f03df9e145a576430220234f5f.tar.gz gnunet-7648cde6cfb181f03df9e145a576430220234f5f.zip |
-improve request cleanup handling
Diffstat (limited to 'src/gns')
-rw-r--r-- | src/gns/plugin_rest_gns.c | 36 |
1 files changed, 32 insertions, 4 deletions
diff --git a/src/gns/plugin_rest_gns.c b/src/gns/plugin_rest_gns.c index 1d560515c..6ec921f70 100644 --- a/src/gns/plugin_rest_gns.c +++ b/src/gns/plugin_rest_gns.c | |||
@@ -81,6 +81,16 @@ struct Plugin | |||
81 | struct RequestHandle | 81 | struct RequestHandle |
82 | { | 82 | { |
83 | /** | 83 | /** |
84 | * DLL | ||
85 | */ | ||
86 | struct RequestHandle *next; | ||
87 | |||
88 | /** | ||
89 | * DLL | ||
90 | */ | ||
91 | struct RequestHandle *prev; | ||
92 | |||
93 | /** | ||
84 | * Active GNS lookup | 94 | * Active GNS lookup |
85 | */ | 95 | */ |
86 | struct GNUNET_GNS_LookupWithTldRequest *gns_lookup; | 96 | struct GNUNET_GNS_LookupWithTldRequest *gns_lookup; |
@@ -136,6 +146,15 @@ struct RequestHandle | |||
136 | int response_code; | 146 | int response_code; |
137 | }; | 147 | }; |
138 | 148 | ||
149 | /** | ||
150 | * DLL | ||
151 | */ | ||
152 | static struct RequestHandle *requests_head; | ||
153 | |||
154 | /** | ||
155 | * DLL | ||
156 | */ | ||
157 | static struct RequestHandle *requests_tail; | ||
139 | 158 | ||
140 | /** | 159 | /** |
141 | * Cleanup lookup handle | 160 | * Cleanup lookup handle |
@@ -165,6 +184,9 @@ cleanup_handle (void *cls) | |||
165 | if (NULL != handle->emsg) | 184 | if (NULL != handle->emsg) |
166 | GNUNET_free (handle->emsg); | 185 | GNUNET_free (handle->emsg); |
167 | 186 | ||
187 | GNUNET_CONTAINER_DLL_remove (requests_head, | ||
188 | requests_tail, | ||
189 | handle); | ||
168 | GNUNET_free (handle); | 190 | GNUNET_free (handle); |
169 | } | 191 | } |
170 | 192 | ||
@@ -198,7 +220,7 @@ do_error (void *cls) | |||
198 | handle->proc (handle->proc_cls, resp, handle->response_code); | 220 | handle->proc (handle->proc_cls, resp, handle->response_code); |
199 | json_decref (json_error); | 221 | json_decref (json_error); |
200 | GNUNET_free (response); | 222 | GNUNET_free (response); |
201 | GNUNET_SCHEDULER_add_now (&cleanup_handle, handle); | 223 | cleanup_handle(handle); |
202 | } | 224 | } |
203 | 225 | ||
204 | 226 | ||
@@ -374,8 +396,12 @@ rest_process_request (struct GNUNET_REST_RequestHandle *rest_handle, | |||
374 | handle->proc_cls = proc_cls; | 396 | handle->proc_cls = proc_cls; |
375 | handle->proc = proc; | 397 | handle->proc = proc; |
376 | handle->rest_handle = rest_handle; | 398 | handle->rest_handle = rest_handle; |
377 | |||
378 | handle->url = GNUNET_strdup (rest_handle->url); | 399 | handle->url = GNUNET_strdup (rest_handle->url); |
400 | handle->timeout_task = | ||
401 | GNUNET_SCHEDULER_add_delayed (handle->timeout, &do_timeout, handle); | ||
402 | GNUNET_CONTAINER_DLL_insert (requests_head, | ||
403 | requests_tail, | ||
404 | handle); | ||
379 | if (handle->url[strlen (handle->url) - 1] == '/') | 405 | if (handle->url[strlen (handle->url) - 1] == '/') |
380 | handle->url[strlen (handle->url) - 1] = '\0'; | 406 | handle->url[strlen (handle->url) - 1] = '\0'; |
381 | if (GNUNET_NO == | 407 | if (GNUNET_NO == |
@@ -386,8 +412,6 @@ rest_process_request (struct GNUNET_REST_RequestHandle *rest_handle, | |||
386 | } | 412 | } |
387 | 413 | ||
388 | 414 | ||
389 | handle->timeout_task = | ||
390 | GNUNET_SCHEDULER_add_delayed (handle->timeout, &do_timeout, handle); | ||
391 | return GNUNET_YES; | 415 | return GNUNET_YES; |
392 | } | 416 | } |
393 | 417 | ||
@@ -435,8 +459,12 @@ void * | |||
435 | libgnunet_plugin_rest_gns_done (void *cls) | 459 | libgnunet_plugin_rest_gns_done (void *cls) |
436 | { | 460 | { |
437 | struct GNUNET_REST_Plugin *api = cls; | 461 | struct GNUNET_REST_Plugin *api = cls; |
462 | struct RequestHandle *request; | ||
438 | struct Plugin *plugin; | 463 | struct Plugin *plugin; |
439 | 464 | ||
465 | while (NULL != (request = requests_head)) | ||
466 | do_error (request); | ||
467 | |||
440 | if (NULL != gns) | 468 | if (NULL != gns) |
441 | GNUNET_GNS_disconnect (gns); | 469 | GNUNET_GNS_disconnect (gns); |
442 | 470 | ||