diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2011-09-15 09:31:18 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2011-09-15 09:31:18 +0000 |
commit | c2a2296221c174ae68fb82f3373a5594391474cb (patch) | |
tree | 53a284d9e0fcb274712f3d551bcdb00c1223d062 /src/transport/plugin_transport_http_server.c | |
parent | d0cdb1cc4a8d030fd106475e1bbc520c7486fc24 (diff) | |
download | gnunet-c2a2296221c174ae68fb82f3373a5594391474cb.tar.gz gnunet-c2a2296221c174ae68fb82f3373a5594391474cb.zip |
more functionality
Diffstat (limited to 'src/transport/plugin_transport_http_server.c')
-rw-r--r-- | src/transport/plugin_transport_http_server.c | 151 |
1 files changed, 150 insertions, 1 deletions
diff --git a/src/transport/plugin_transport_http_server.c b/src/transport/plugin_transport_http_server.c index 96d3e27ae..b74f68b96 100644 --- a/src/transport/plugin_transport_http_server.c +++ b/src/transport/plugin_transport_http_server.c | |||
@@ -48,7 +48,12 @@ server_log (void *arg, const char *fmt, va_list ap) | |||
48 | static int | 48 | static int |
49 | server_accept_cb (void *cls, const struct sockaddr *addr, socklen_t addr_len) | 49 | server_accept_cb (void *cls, const struct sockaddr *addr, socklen_t addr_len) |
50 | { | 50 | { |
51 | return 0; | 51 | struct Plugin * plugin = cls; |
52 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "server: server_accept_cb\n"); | ||
53 | if (plugin->cur_connections <= plugin->max_connections) | ||
54 | return MHD_YES; | ||
55 | else | ||
56 | return MHD_NO; | ||
52 | } | 57 | } |
53 | 58 | ||
54 | 59 | ||
@@ -220,6 +225,7 @@ server_access_cb (void *cls, struct MHD_Connection *mhd_connection, | |||
220 | const char *upload_data, size_t * upload_data_size, | 225 | const char *upload_data, size_t * upload_data_size, |
221 | void **httpSessionCache) | 226 | void **httpSessionCache) |
222 | { | 227 | { |
228 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "server: server_access_cb\n"); | ||
223 | return 0; | 229 | return 0; |
224 | } | 230 | } |
225 | 231 | ||
@@ -227,6 +233,7 @@ static void | |||
227 | server_disconnect_cb (void *cls, struct MHD_Connection *connection, | 233 | server_disconnect_cb (void *cls, struct MHD_Connection *connection, |
228 | void **httpSessionCache) | 234 | void **httpSessionCache) |
229 | { | 235 | { |
236 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "server: server_disconnect_cb\n"); | ||
230 | } | 237 | } |
231 | 238 | ||
232 | int | 239 | int |
@@ -241,6 +248,132 @@ server_send (struct Session *s, const char *msgbuf, size_t msgbuf_size) | |||
241 | return GNUNET_OK; | 248 | return GNUNET_OK; |
242 | } | 249 | } |
243 | 250 | ||
251 | /** | ||
252 | * Function that queries MHD's select sets and | ||
253 | * starts the task waiting for them. | ||
254 | * @param plugin plugin | ||
255 | * @param daemon_handle the MHD daemon handle | ||
256 | * @return gnunet task identifier | ||
257 | */ | ||
258 | static GNUNET_SCHEDULER_TaskIdentifier | ||
259 | server_schedule_daemon (struct Plugin *plugin, struct MHD_Daemon *daemon_handle); | ||
260 | |||
261 | /** | ||
262 | * Call MHD IPv4 to process pending requests and then go back | ||
263 | * and schedule the next run. | ||
264 | * @param cls plugin as closure | ||
265 | * @param tc task context | ||
266 | */ | ||
267 | static void | ||
268 | http_server_daemon_v4_run (void *cls, | ||
269 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
270 | { | ||
271 | struct Plugin *plugin = cls; | ||
272 | GNUNET_assert (cls != NULL); | ||
273 | |||
274 | plugin->server_v4_task = GNUNET_SCHEDULER_NO_TASK; | ||
275 | |||
276 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | ||
277 | return; | ||
278 | |||
279 | GNUNET_assert (MHD_YES == MHD_run (plugin->server_v4)); | ||
280 | plugin->server_v4_task = server_schedule_daemon (plugin, plugin->server_v4); | ||
281 | } | ||
282 | |||
283 | |||
284 | /** | ||
285 | * Call MHD IPv6 to process pending requests and then go back | ||
286 | * and schedule the next run. | ||
287 | * @param cls plugin as closure | ||
288 | * @param tc task context | ||
289 | */ | ||
290 | static void | ||
291 | http_server_daemon_v6_run (void *cls, | ||
292 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
293 | { | ||
294 | struct Plugin *plugin = cls; | ||
295 | GNUNET_assert (cls != NULL); | ||
296 | |||
297 | plugin->server_v6_task = GNUNET_SCHEDULER_NO_TASK; | ||
298 | |||
299 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | ||
300 | return; | ||
301 | |||
302 | GNUNET_assert (MHD_YES == MHD_run (plugin->server_v6)); | ||
303 | plugin->server_v6_task = server_schedule_daemon (plugin, plugin->server_v6); | ||
304 | } | ||
305 | |||
306 | /** | ||
307 | * Function that queries MHD's select sets and | ||
308 | * starts the task waiting for them. | ||
309 | * @param plugin plugin | ||
310 | * @param daemon_handle the MHD daemon handle | ||
311 | * @return gnunet task identifier | ||
312 | */ | ||
313 | static GNUNET_SCHEDULER_TaskIdentifier | ||
314 | server_schedule_daemon (struct Plugin *plugin, struct MHD_Daemon *daemon_handle) | ||
315 | { | ||
316 | GNUNET_SCHEDULER_TaskIdentifier ret; | ||
317 | fd_set rs; | ||
318 | fd_set ws; | ||
319 | fd_set es; | ||
320 | struct GNUNET_NETWORK_FDSet *wrs; | ||
321 | struct GNUNET_NETWORK_FDSet *wws; | ||
322 | struct GNUNET_NETWORK_FDSet *wes; | ||
323 | int max; | ||
324 | unsigned long long timeout; | ||
325 | int haveto; | ||
326 | struct GNUNET_TIME_Relative tv; | ||
327 | |||
328 | ret = GNUNET_SCHEDULER_NO_TASK; | ||
329 | FD_ZERO (&rs); | ||
330 | FD_ZERO (&ws); | ||
331 | FD_ZERO (&es); | ||
332 | wrs = GNUNET_NETWORK_fdset_create (); | ||
333 | wes = GNUNET_NETWORK_fdset_create (); | ||
334 | wws = GNUNET_NETWORK_fdset_create (); | ||
335 | max = -1; | ||
336 | GNUNET_assert (MHD_YES == MHD_get_fdset (daemon_handle, &rs, &ws, &es, &max)); | ||
337 | haveto = MHD_get_timeout (daemon_handle, &timeout); | ||
338 | if (haveto == MHD_YES) | ||
339 | tv.rel_value = (uint64_t) timeout; | ||
340 | else | ||
341 | tv = GNUNET_TIME_UNIT_SECONDS; | ||
342 | GNUNET_NETWORK_fdset_copy_native (wrs, &rs, max + 1); | ||
343 | GNUNET_NETWORK_fdset_copy_native (wws, &ws, max + 1); | ||
344 | GNUNET_NETWORK_fdset_copy_native (wes, &es, max + 1); | ||
345 | if (daemon_handle == plugin->server_v4) | ||
346 | { | ||
347 | if (plugin->server_v4_task != GNUNET_SCHEDULER_NO_TASK) | ||
348 | { | ||
349 | GNUNET_SCHEDULER_cancel (plugin->server_v4_task); | ||
350 | plugin->server_v4_task = GNUNET_SCHEDULER_NO_TASK; | ||
351 | } | ||
352 | |||
353 | ret = | ||
354 | GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, | ||
355 | GNUNET_SCHEDULER_NO_TASK, tv, wrs, wws, | ||
356 | &http_server_daemon_v4_run, plugin); | ||
357 | } | ||
358 | if (daemon_handle == plugin->server_v6) | ||
359 | { | ||
360 | if (plugin->server_v6_task != GNUNET_SCHEDULER_NO_TASK) | ||
361 | { | ||
362 | GNUNET_SCHEDULER_cancel (plugin->server_v6_task); | ||
363 | plugin->server_v6_task = GNUNET_SCHEDULER_NO_TASK; | ||
364 | } | ||
365 | |||
366 | ret = | ||
367 | GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, | ||
368 | GNUNET_SCHEDULER_NO_TASK, tv, wrs, wws, | ||
369 | &http_server_daemon_v6_run, plugin); | ||
370 | } | ||
371 | GNUNET_NETWORK_fdset_destroy (wrs); | ||
372 | GNUNET_NETWORK_fdset_destroy (wws); | ||
373 | GNUNET_NETWORK_fdset_destroy (wes); | ||
374 | return ret; | ||
375 | } | ||
376 | |||
244 | int | 377 | int |
245 | server_start (struct Plugin *plugin) | 378 | server_start (struct Plugin *plugin) |
246 | { | 379 | { |
@@ -334,6 +467,11 @@ server_start (struct Plugin *plugin) | |||
334 | res = GNUNET_SYSERR; | 467 | res = GNUNET_SYSERR; |
335 | } | 468 | } |
336 | 469 | ||
470 | if (plugin->server_v4 != NULL) | ||
471 | plugin->server_v4_task = server_schedule_daemon (plugin, plugin->server_v4); | ||
472 | if (plugin->server_v6 != NULL) | ||
473 | plugin->server_v6_task = server_schedule_daemon (plugin, plugin->server_v6); | ||
474 | |||
337 | #if DEBUG_HTTP | 475 | #if DEBUG_HTTP |
338 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, | 476 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, |
339 | "%s server component started on port %u\n", plugin->name, | 477 | "%s server component started on port %u\n", plugin->name, |
@@ -345,6 +483,17 @@ server_start (struct Plugin *plugin) | |||
345 | void | 483 | void |
346 | server_stop (struct Plugin *plugin) | 484 | server_stop (struct Plugin *plugin) |
347 | { | 485 | { |
486 | if (plugin->server_v4_task != GNUNET_SCHEDULER_NO_TASK) | ||
487 | { | ||
488 | GNUNET_SCHEDULER_cancel (plugin->server_v4_task); | ||
489 | plugin->server_v4_task = GNUNET_SCHEDULER_NO_TASK; | ||
490 | } | ||
491 | |||
492 | if (plugin->server_v6_task != GNUNET_SCHEDULER_NO_TASK) | ||
493 | { | ||
494 | GNUNET_SCHEDULER_cancel (plugin->server_v6_task); | ||
495 | plugin->server_v6_task = GNUNET_SCHEDULER_NO_TASK; | ||
496 | } | ||
348 | 497 | ||
349 | if (plugin->server_v4 != NULL) | 498 | if (plugin->server_v4 != NULL) |
350 | { | 499 | { |