aboutsummaryrefslogtreecommitdiff
path: root/src/util/server.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-09-17 10:45:23 +0000
committerChristian Grothoff <christian@grothoff.org>2012-09-17 10:45:23 +0000
commit7e065c18499688141eb68513058131a49344cac1 (patch)
treee441b44c8f0db8a4f214775e4945039cc820cf2f /src/util/server.c
parentb3ad920b6e0107c3da946fe1f2f720955dbac151 (diff)
downloadgnunet-7e065c18499688141eb68513058131a49344cac1.tar.gz
gnunet-7e065c18499688141eb68513058131a49344cac1.zip
fixing #1551/#2503
Diffstat (limited to 'src/util/server.c')
-rw-r--r--src/util/server.c95
1 files changed, 55 insertions, 40 deletions
diff --git a/src/util/server.c b/src/util/server.c
index ff4584677..4622e0779 100644
--- a/src/util/server.c
+++ b/src/util/server.c
@@ -334,43 +334,6 @@ process_listen_socket (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
334 334
335 335
336/** 336/**
337 * Add a listen task with the scheduler for this server.
338 *
339 * @param server handle to our server for which we are adding the listen
340 * socket
341 */
342static void
343schedule_listen_task (struct GNUNET_SERVER_Handle *server)
344{
345 struct GNUNET_NETWORK_FDSet *r;
346 unsigned int i;
347
348 if (NULL == server->listen_sockets[0])
349 return; /* nothing to do, no listen sockets! */
350 if (NULL == server->listen_sockets[1])
351 {
352 /* simplified method: no fd set needed; this is then much simpler and
353 much more efficient */
354 server->listen_task =
355 GNUNET_SCHEDULER_add_read_net_with_priority (GNUNET_TIME_UNIT_FOREVER_REL,
356 GNUNET_SCHEDULER_PRIORITY_HIGH,
357 server->listen_sockets[0],
358 &process_listen_socket, server);
359 return;
360 }
361 r = GNUNET_NETWORK_fdset_create ();
362 i = 0;
363 while (NULL != server->listen_sockets[i])
364 GNUNET_NETWORK_fdset_set (r, server->listen_sockets[i++]);
365 server->listen_task =
366 GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_HIGH,
367 GNUNET_TIME_UNIT_FOREVER_REL, r, NULL,
368 &process_listen_socket, server);
369 GNUNET_NETWORK_fdset_destroy (r);
370}
371
372
373/**
374 * Scheduler says our listen socket is ready. Process it! 337 * Scheduler says our listen socket is ready. Process it!
375 * 338 *
376 * @param cls handle to our server for which we are processing the listen 339 * @param cls handle to our server for which we are processing the listen
@@ -389,7 +352,7 @@ process_listen_socket (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
389 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) 352 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
390 { 353 {
391 /* ignore shutdown, someone else will take care of it! */ 354 /* ignore shutdown, someone else will take care of it! */
392 schedule_listen_task (server); 355 GNUNET_SERVER_resume (server);
393 return; 356 return;
394 } 357 }
395 i = 0; 358 i = 0;
@@ -412,7 +375,7 @@ process_listen_socket (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
412 i++; 375 i++;
413 } 376 }
414 /* listen for more! */ 377 /* listen for more! */
415 schedule_listen_task (server); 378 GNUNET_SERVER_resume (server);
416} 379}
417 380
418 381
@@ -536,7 +499,7 @@ GNUNET_SERVER_create_with_sockets (GNUNET_CONNECTION_AccessCheck access,
536 server->access_cls = access_cls; 499 server->access_cls = access_cls;
537 server->require_found = require_found; 500 server->require_found = require_found;
538 if (NULL != lsocks) 501 if (NULL != lsocks)
539 schedule_listen_task (server); 502 GNUNET_SERVER_resume (server);
540 return server; 503 return server;
541} 504}
542 505
@@ -671,6 +634,58 @@ test_monitor_clients (struct GNUNET_SERVER_Handle *server)
671 634
672 635
673/** 636/**
637 * Suspend accepting connections from the listen socket temporarily.
638 *
639 * @param server server to stop accepting connections.
640 */
641void
642GNUNET_SERVER_suspend (struct GNUNET_SERVER_Handle *server)
643{
644 if (GNUNET_SCHEDULER_NO_TASK != server->listen_task)
645 {
646 GNUNET_SCHEDULER_cancel (server->listen_task);
647 server->listen_task = GNUNET_SCHEDULER_NO_TASK;
648 }
649}
650
651
652/**
653 * Resume accepting connections from the listen socket.
654 *
655 * @param server server to stop accepting connections.
656 */
657void
658GNUNET_SERVER_resume (struct GNUNET_SERVER_Handle *server)
659{
660 struct GNUNET_NETWORK_FDSet *r;
661 unsigned int i;
662
663 if (NULL == server->listen_sockets[0])
664 return; /* nothing to do, no listen sockets! */
665 if (NULL == server->listen_sockets[1])
666 {
667 /* simplified method: no fd set needed; this is then much simpler and
668 much more efficient */
669 server->listen_task =
670 GNUNET_SCHEDULER_add_read_net_with_priority (GNUNET_TIME_UNIT_FOREVER_REL,
671 GNUNET_SCHEDULER_PRIORITY_HIGH,
672 server->listen_sockets[0],
673 &process_listen_socket, server);
674 return;
675 }
676 r = GNUNET_NETWORK_fdset_create ();
677 i = 0;
678 while (NULL != server->listen_sockets[i])
679 GNUNET_NETWORK_fdset_set (r, server->listen_sockets[i++]);
680 server->listen_task =
681 GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_HIGH,
682 GNUNET_TIME_UNIT_FOREVER_REL, r, NULL,
683 &process_listen_socket, server);
684 GNUNET_NETWORK_fdset_destroy (r);
685}
686
687
688/**
674 * Stop the listen socket and get ready to shutdown the server 689 * Stop the listen socket and get ready to shutdown the server
675 * once only 'monitor' clients are left. 690 * once only 'monitor' clients are left.
676 * 691 *