From 184240c9c28f784bbdea72742e0a3ce3e3ee4652 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sat, 13 Jun 2009 06:19:33 +0000 Subject: [PATCH] use external select --- src/hostlist/gnunet-daemon-hostlist.c | 12 +++-- src/hostlist/hostlist-server.c | 73 +++++++++++++++++++++++++-- 2 files changed, 77 insertions(+), 8 deletions(-) diff --git a/src/hostlist/gnunet-daemon-hostlist.c b/src/hostlist/gnunet-daemon-hostlist.c index da2553238..e2e64a717 100644 --- a/src/hostlist/gnunet-daemon-hostlist.c +++ b/src/hostlist/gnunet-daemon-hostlist.c @@ -69,13 +69,17 @@ static struct GNUNET_STATISTICS_Handle *stats; * gnunet-daemon-hostlist command line options. */ static struct GNUNET_GETOPT_CommandLineOption options[] = { - { 'a', "advertise", NULL, gettext_noop ("advertise our hostlist to other peers"), + { 'a', "advertise", NULL, + gettext_noop ("advertise our hostlist to other peers"), GNUNET_NO, &GNUNET_GETOPT_set_one, &advertising }, - { 'b', "bootstrap", NULL, gettext_noop ("bootstrap using hostlists (it is highly recommended that you always use this option)"), + { 'b', "bootstrap", NULL, + gettext_noop ("bootstrap using hostlists (it is highly recommended that you always use this option)"), GNUNET_NO, &GNUNET_GETOPT_set_one, &bootstrapping }, - { 'e', "enable-learning", NULL, gettext_noop ("enable learning about hostlist servers from other peers"), + { 'e', "enable-learning", NULL, + gettext_noop ("enable learning about hostlist servers from other peers"), GNUNET_NO, &GNUNET_GETOPT_set_one, &learning}, - { 'p', "provide-hostlist", NULL, gettext_noop ("provide a hostlist server"), + { 'p', "provide-hostlist", NULL, + gettext_noop ("provide a hostlist server"), GNUNET_NO, &GNUNET_GETOPT_set_one, &provide_hostlist}, GNUNET_GETOPT_OPTION_END }; diff --git a/src/hostlist/hostlist-server.c b/src/hostlist/hostlist-server.c index a2bbe2dec..a481aa7a7 100644 --- a/src/hostlist/hostlist-server.c +++ b/src/hostlist/hostlist-server.c @@ -142,7 +142,9 @@ update_response (void *cls, } - +/** + * Hostlist access policy (very permissive, allows everything). + */ static int accept_policy_callback (void *cls, const struct sockaddr *addr, socklen_t addrlen) @@ -151,6 +153,9 @@ accept_policy_callback (void *cls, } +/** + * Main request handler. + */ static int access_handler_callback (void *cls, struct MHD_Connection *connection, @@ -177,6 +182,67 @@ access_handler_callback (void *cls, } +/** + * Function that queries MHD's select sets and + * starts the task waiting for them. + */ +static void +prepare_daemon (void); + + +static void +run_daemon (void *cls, + const struct GNUNET_SCHEDULER_TaskContext *tc) +{ + GNUNET_assert (MHD_YES == MHD_run (daemon_handle)); + prepare_daemon (); +} + + +/** + * Function that queries MHD's select sets and + * starts the task waiting for them. + */ +static void +prepare_daemon () +{ + fd_set rs; + fd_set ws; + fd_set es; + int max; + unsigned long long timeout; + int haveto; + struct GNUNET_TIME_Relative tv; + + FD_ZERO(&rs); + FD_ZERO(&ws); + FD_ZERO(&es); + max = -1; + GNUNET_assert (MHD_YES == + MHD_get_fdset (daemon_handle, + &rs, + &ws, + &es, + &max)); + haveto = MHD_get_timeout (daemon_handle, &timeout); + if (haveto == MHD_YES) + tv.value = (uint64_t) timeout; + else + tv = GNUNET_TIME_UNIT_FOREVER_REL; + GNUNET_SCHEDULER_add_select (sched, + GNUNET_NO, + GNUNET_SCHEDULER_PRIORITY_HIGH, + GNUNET_SCHEDULER_NO_PREREQUISITE_TASK, + tv, + max, + &rs, + &ws, + &run_daemon, + NULL); +} + + + /** * Start server offering our hostlist. * @@ -196,9 +262,7 @@ GNUNET_HOSTLIST_server_start (struct GNUNET_CONFIGURATION_Handle *c, "PORT", &port)) return GNUNET_SYSERR; - /* FIXME: must use *external* SELECT mode since our - code is NOT thread safe! Integrate with scheduler! */ - daemon_handle = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY | MHD_USE_IPv6, + daemon_handle = MHD_start_daemon (MHD_USE_IPv6, (unsigned short) port, &accept_policy_callback, NULL, @@ -216,6 +280,7 @@ GNUNET_HOSTLIST_server_start (struct GNUNET_CONFIGURATION_Handle *c, (unsigned short) port); return GNUNET_SYSERR; } + prepare_daemon (); return GNUNET_OK; } -- 2.25.1