diff options
author | Christian Grothoff <christian@grothoff.org> | 2016-04-09 23:14:03 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2016-04-09 23:14:03 +0000 |
commit | 29e6158507a0758192075ac6ece7ba8e75ddc49a (patch) | |
tree | b91ded48da322f8ba4c9bb0f5504228aa036c2d1 /src/rest | |
parent | 5dfcb058ab5db9ae0c4b147d8a99c64ca0980028 (diff) | |
download | gnunet-29e6158507a0758192075ac6ece7ba8e75ddc49a.tar.gz gnunet-29e6158507a0758192075ac6ece7ba8e75ddc49a.zip |
small API change: do no longer pass rarely needed GNUNET_SCHEDULER_TaskContext to all scheduler tasks; instead, allow the relatively few tasks that need it to obtain the context via GNUNET_SCHEDULER_get_task_context()
Diffstat (limited to 'src/rest')
-rw-r--r-- | src/rest/gnunet-rest-server.c | 41 |
1 files changed, 17 insertions, 24 deletions
diff --git a/src/rest/gnunet-rest-server.c b/src/rest/gnunet-rest-server.c index fdba7fcc4..705fcbeb3 100644 --- a/src/rest/gnunet-rest-server.c +++ b/src/rest/gnunet-rest-server.c | |||
@@ -119,7 +119,7 @@ static char* allow_origin; | |||
119 | static char* allow_headers; | 119 | static char* allow_headers; |
120 | 120 | ||
121 | /** | 121 | /** |
122 | * MHD Connection handle | 122 | * MHD Connection handle |
123 | */ | 123 | */ |
124 | struct MhdConnectionHandle | 124 | struct MhdConnectionHandle |
125 | { | 125 | { |
@@ -143,11 +143,9 @@ struct MhdConnectionHandle | |||
143 | * Task run whenever HTTP server operations are pending. | 143 | * Task run whenever HTTP server operations are pending. |
144 | * | 144 | * |
145 | * @param cls NULL | 145 | * @param cls NULL |
146 | * @param tc sched context | ||
147 | */ | 146 | */ |
148 | static void | 147 | static void |
149 | do_httpd (void *cls, | 148 | do_httpd (void *cls); |
150 | const struct GNUNET_SCHEDULER_TaskContext *tc); | ||
151 | 149 | ||
152 | 150 | ||
153 | /** | 151 | /** |
@@ -179,7 +177,7 @@ plugin_callback (void *cls, | |||
179 | struct MhdConnectionHandle *handle = cls; | 177 | struct MhdConnectionHandle *handle = cls; |
180 | handle->status = status; | 178 | handle->status = status; |
181 | handle->response = resp; | 179 | handle->response = resp; |
182 | run_mhd_now(); | 180 | run_mhd_now(); |
183 | } | 181 | } |
184 | 182 | ||
185 | 183 | ||
@@ -222,7 +220,7 @@ url_iterator (void *cls, | |||
222 | struct RestConnectionDataHandle *handle = cls; | 220 | struct RestConnectionDataHandle *handle = cls; |
223 | struct GNUNET_HashCode hkey; | 221 | struct GNUNET_HashCode hkey; |
224 | char *val; | 222 | char *val; |
225 | 223 | ||
226 | GNUNET_CRYPTO_hash (key, strlen (key), &hkey); | 224 | GNUNET_CRYPTO_hash (key, strlen (key), &hkey); |
227 | GNUNET_asprintf (&val, "%s", value); | 225 | GNUNET_asprintf (&val, "%s", value); |
228 | if (GNUNET_OK != | 226 | if (GNUNET_OK != |
@@ -394,7 +392,7 @@ kill_httpd () | |||
394 | httpd = NULL; | 392 | httpd = NULL; |
395 | } | 393 | } |
396 | if (NULL != httpd_task) | 394 | if (NULL != httpd_task) |
397 | { | 395 | { |
398 | GNUNET_SCHEDULER_cancel (httpd_task); | 396 | GNUNET_SCHEDULER_cancel (httpd_task); |
399 | httpd_task = NULL; | 397 | httpd_task = NULL; |
400 | } | 398 | } |
@@ -405,11 +403,9 @@ kill_httpd () | |||
405 | * Task run whenever HTTP server is idle for too long. Kill it. | 403 | * Task run whenever HTTP server is idle for too long. Kill it. |
406 | * | 404 | * |
407 | * @param cls NULL | 405 | * @param cls NULL |
408 | * @param tc sched context | ||
409 | */ | 406 | */ |
410 | static void | 407 | static void |
411 | kill_httpd_task (void *cls, | 408 | kill_httpd_task (void *cls) |
412 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
413 | { | 409 | { |
414 | httpd_task = NULL; | 410 | httpd_task = NULL; |
415 | kill_httpd (); | 411 | kill_httpd (); |
@@ -482,11 +478,9 @@ schedule_httpd () | |||
482 | * Task run whenever HTTP server operations are pending. | 478 | * Task run whenever HTTP server operations are pending. |
483 | * | 479 | * |
484 | * @param cls NULL | 480 | * @param cls NULL |
485 | * @param tc scheduler context | ||
486 | */ | 481 | */ |
487 | static void | 482 | static void |
488 | do_httpd (void *cls, | 483 | do_httpd (void *cls) |
489 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
490 | { | 484 | { |
491 | httpd_task = NULL; | 485 | httpd_task = NULL; |
492 | MHD_run (httpd); | 486 | MHD_run (httpd); |
@@ -501,10 +495,10 @@ do_httpd (void *cls, | |||
501 | * @param tc the scheduler context | 495 | * @param tc the scheduler context |
502 | */ | 496 | */ |
503 | static void | 497 | static void |
504 | do_accept (void *cls, | 498 | do_accept (void *cls) |
505 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
506 | { | 499 | { |
507 | struct GNUNET_NETWORK_Handle *lsock = cls; | 500 | struct GNUNET_NETWORK_Handle *lsock = cls; |
501 | const struct GNUNET_SCHEDULER_TaskContext *tc; | ||
508 | struct GNUNET_NETWORK_Handle *s; | 502 | struct GNUNET_NETWORK_Handle *s; |
509 | int fd; | 503 | int fd; |
510 | const struct sockaddr *addr; | 504 | const struct sockaddr *addr; |
@@ -514,8 +508,9 @@ do_accept (void *cls, | |||
514 | ltask4 = NULL; | 508 | ltask4 = NULL; |
515 | else | 509 | else |
516 | ltask6 = NULL; | 510 | ltask6 = NULL; |
511 | tc = GNUNET_SCHEDULER_get_task_context (); | ||
517 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | 512 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) |
518 | return; | 513 | return; |
519 | if (lsock == lsock4) | 514 | if (lsock == lsock4) |
520 | ltask4 = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, | 515 | ltask4 = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, |
521 | lsock, | 516 | lsock, |
@@ -550,11 +545,9 @@ do_accept (void *cls, | |||
550 | * Task run on shutdown | 545 | * Task run on shutdown |
551 | * | 546 | * |
552 | * @param cls closure | 547 | * @param cls closure |
553 | * @param tc task context | ||
554 | */ | 548 | */ |
555 | static void | 549 | static void |
556 | do_shutdown (void *cls, | 550 | do_shutdown (void *cls) |
557 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
558 | { | 551 | { |
559 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 552 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
560 | "Shutting down...\n"); | 553 | "Shutting down...\n"); |
@@ -581,7 +574,7 @@ bind_v4 () | |||
581 | sa4.sin_port = htons (port); | 574 | sa4.sin_port = htons (port); |
582 | #if HAVE_SOCKADDR_IN_SIN_LEN | 575 | #if HAVE_SOCKADDR_IN_SIN_LEN |
583 | sa4.sin_len = sizeof (sa4); | 576 | sa4.sin_len = sizeof (sa4); |
584 | #endif | 577 | #endif |
585 | ls = GNUNET_NETWORK_socket_create (AF_INET, | 578 | ls = GNUNET_NETWORK_socket_create (AF_INET, |
586 | SOCK_STREAM, | 579 | SOCK_STREAM, |
587 | 0); | 580 | 0); |
@@ -617,7 +610,7 @@ bind_v6 () | |||
617 | sa6.sin6_port = htons (port); | 610 | sa6.sin6_port = htons (port); |
618 | #if HAVE_SOCKADDR_IN_SIN_LEN | 611 | #if HAVE_SOCKADDR_IN_SIN_LEN |
619 | sa6.sin6_len = sizeof (sa6); | 612 | sa6.sin6_len = sizeof (sa6); |
620 | #endif | 613 | #endif |
621 | ls = GNUNET_NETWORK_socket_create (AF_INET6, | 614 | ls = GNUNET_NETWORK_socket_create (AF_INET6, |
622 | SOCK_STREAM, | 615 | SOCK_STREAM, |
623 | 0); | 616 | 0); |
@@ -685,8 +678,8 @@ load_plugin (void *cls, | |||
685 | * @param c configuration | 678 | * @param c configuration |
686 | */ | 679 | */ |
687 | static void | 680 | static void |
688 | run (void *cls, | 681 | run (void *cls, |
689 | char *const *args, | 682 | char *const *args, |
690 | const char *cfgfile, | 683 | const char *cfgfile, |
691 | const struct GNUNET_CONFIGURATION_Handle *c) | 684 | const struct GNUNET_CONFIGURATION_Handle *c) |
692 | { | 685 | { |
@@ -756,7 +749,7 @@ run (void *cls, | |||
756 | { | 749 | { |
757 | GNUNET_SCHEDULER_shutdown (); | 750 | GNUNET_SCHEDULER_shutdown (); |
758 | return; | 751 | return; |
759 | } | 752 | } |
760 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 753 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
761 | "Service listens on port %u\n", | 754 | "Service listens on port %u\n", |
762 | port); | 755 | port); |