diff options
author | Christian Grothoff <christian@grothoff.org> | 2009-06-13 06:19:33 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2009-06-13 06:19:33 +0000 |
commit | 184240c9c28f784bbdea72742e0a3ce3e3ee4652 (patch) | |
tree | 06a3e2dabf45fe1f91c8d9dad591632e1b6d888b /src | |
parent | 256e783449308d848bb687f5e9e79fde1c5fe03d (diff) | |
download | gnunet-184240c9c28f784bbdea72742e0a3ce3e3ee4652.tar.gz gnunet-184240c9c28f784bbdea72742e0a3ce3e3ee4652.zip |
use external select
Diffstat (limited to 'src')
-rw-r--r-- | src/hostlist/gnunet-daemon-hostlist.c | 12 | ||||
-rw-r--r-- | 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; | |||
69 | * gnunet-daemon-hostlist command line options. | 69 | * gnunet-daemon-hostlist command line options. |
70 | */ | 70 | */ |
71 | static struct GNUNET_GETOPT_CommandLineOption options[] = { | 71 | static struct GNUNET_GETOPT_CommandLineOption options[] = { |
72 | { 'a', "advertise", NULL, gettext_noop ("advertise our hostlist to other peers"), | 72 | { 'a', "advertise", NULL, |
73 | gettext_noop ("advertise our hostlist to other peers"), | ||
73 | GNUNET_NO, &GNUNET_GETOPT_set_one, &advertising }, | 74 | GNUNET_NO, &GNUNET_GETOPT_set_one, &advertising }, |
74 | { 'b', "bootstrap", NULL, gettext_noop ("bootstrap using hostlists (it is highly recommended that you always use this option)"), | 75 | { 'b', "bootstrap", NULL, |
76 | gettext_noop ("bootstrap using hostlists (it is highly recommended that you always use this option)"), | ||
75 | GNUNET_NO, &GNUNET_GETOPT_set_one, &bootstrapping }, | 77 | GNUNET_NO, &GNUNET_GETOPT_set_one, &bootstrapping }, |
76 | { 'e', "enable-learning", NULL, gettext_noop ("enable learning about hostlist servers from other peers"), | 78 | { 'e', "enable-learning", NULL, |
79 | gettext_noop ("enable learning about hostlist servers from other peers"), | ||
77 | GNUNET_NO, &GNUNET_GETOPT_set_one, &learning}, | 80 | GNUNET_NO, &GNUNET_GETOPT_set_one, &learning}, |
78 | { 'p', "provide-hostlist", NULL, gettext_noop ("provide a hostlist server"), | 81 | { 'p', "provide-hostlist", NULL, |
82 | gettext_noop ("provide a hostlist server"), | ||
79 | GNUNET_NO, &GNUNET_GETOPT_set_one, &provide_hostlist}, | 83 | GNUNET_NO, &GNUNET_GETOPT_set_one, &provide_hostlist}, |
80 | GNUNET_GETOPT_OPTION_END | 84 | GNUNET_GETOPT_OPTION_END |
81 | }; | 85 | }; |
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, | |||
142 | } | 142 | } |
143 | 143 | ||
144 | 144 | ||
145 | 145 | /** | |
146 | * Hostlist access policy (very permissive, allows everything). | ||
147 | */ | ||
146 | static int | 148 | static int |
147 | accept_policy_callback (void *cls, | 149 | accept_policy_callback (void *cls, |
148 | const struct sockaddr *addr, socklen_t addrlen) | 150 | const struct sockaddr *addr, socklen_t addrlen) |
@@ -151,6 +153,9 @@ accept_policy_callback (void *cls, | |||
151 | } | 153 | } |
152 | 154 | ||
153 | 155 | ||
156 | /** | ||
157 | * Main request handler. | ||
158 | */ | ||
154 | static int | 159 | static int |
155 | access_handler_callback (void *cls, | 160 | access_handler_callback (void *cls, |
156 | struct MHD_Connection *connection, | 161 | struct MHD_Connection *connection, |
@@ -178,6 +183,67 @@ access_handler_callback (void *cls, | |||
178 | 183 | ||
179 | 184 | ||
180 | /** | 185 | /** |
186 | * Function that queries MHD's select sets and | ||
187 | * starts the task waiting for them. | ||
188 | */ | ||
189 | static void | ||
190 | prepare_daemon (void); | ||
191 | |||
192 | |||
193 | static void | ||
194 | run_daemon (void *cls, | ||
195 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
196 | { | ||
197 | GNUNET_assert (MHD_YES == MHD_run (daemon_handle)); | ||
198 | prepare_daemon (); | ||
199 | } | ||
200 | |||
201 | |||
202 | /** | ||
203 | * Function that queries MHD's select sets and | ||
204 | * starts the task waiting for them. | ||
205 | */ | ||
206 | static void | ||
207 | prepare_daemon () | ||
208 | { | ||
209 | fd_set rs; | ||
210 | fd_set ws; | ||
211 | fd_set es; | ||
212 | int max; | ||
213 | unsigned long long timeout; | ||
214 | int haveto; | ||
215 | struct GNUNET_TIME_Relative tv; | ||
216 | |||
217 | FD_ZERO(&rs); | ||
218 | FD_ZERO(&ws); | ||
219 | FD_ZERO(&es); | ||
220 | max = -1; | ||
221 | GNUNET_assert (MHD_YES == | ||
222 | MHD_get_fdset (daemon_handle, | ||
223 | &rs, | ||
224 | &ws, | ||
225 | &es, | ||
226 | &max)); | ||
227 | haveto = MHD_get_timeout (daemon_handle, &timeout); | ||
228 | if (haveto == MHD_YES) | ||
229 | tv.value = (uint64_t) timeout; | ||
230 | else | ||
231 | tv = GNUNET_TIME_UNIT_FOREVER_REL; | ||
232 | GNUNET_SCHEDULER_add_select (sched, | ||
233 | GNUNET_NO, | ||
234 | GNUNET_SCHEDULER_PRIORITY_HIGH, | ||
235 | GNUNET_SCHEDULER_NO_PREREQUISITE_TASK, | ||
236 | tv, | ||
237 | max, | ||
238 | &rs, | ||
239 | &ws, | ||
240 | &run_daemon, | ||
241 | NULL); | ||
242 | } | ||
243 | |||
244 | |||
245 | |||
246 | /** | ||
181 | * Start server offering our hostlist. | 247 | * Start server offering our hostlist. |
182 | * | 248 | * |
183 | * @return GNUNET_OK on success | 249 | * @return GNUNET_OK on success |
@@ -196,9 +262,7 @@ GNUNET_HOSTLIST_server_start (struct GNUNET_CONFIGURATION_Handle *c, | |||
196 | "PORT", | 262 | "PORT", |
197 | &port)) | 263 | &port)) |
198 | return GNUNET_SYSERR; | 264 | return GNUNET_SYSERR; |
199 | /* FIXME: must use *external* SELECT mode since our | 265 | daemon_handle = MHD_start_daemon (MHD_USE_IPv6, |
200 | code is NOT thread safe! Integrate with scheduler! */ | ||
201 | daemon_handle = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY | MHD_USE_IPv6, | ||
202 | (unsigned short) port, | 266 | (unsigned short) port, |
203 | &accept_policy_callback, | 267 | &accept_policy_callback, |
204 | NULL, | 268 | NULL, |
@@ -216,6 +280,7 @@ GNUNET_HOSTLIST_server_start (struct GNUNET_CONFIGURATION_Handle *c, | |||
216 | (unsigned short) port); | 280 | (unsigned short) port); |
217 | return GNUNET_SYSERR; | 281 | return GNUNET_SYSERR; |
218 | } | 282 | } |
283 | prepare_daemon (); | ||
219 | return GNUNET_OK; | 284 | return GNUNET_OK; |
220 | } | 285 | } |
221 | 286 | ||