aboutsummaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2009-11-04 14:10:32 +0000
committerChristian Grothoff <christian@grothoff.org>2009-11-04 14:10:32 +0000
commitcf45b8dff29c366d51aa2e6ea6a64b99b514b9c9 (patch)
tree5cb37c041743daff5af528dbbe24f5c563ce702e /src/util
parentb91546a3de767292e6472c6b1927480adba43d88 (diff)
downloadgnunet-cf45b8dff29c366d51aa2e6ea6a64b99b514b9c9.tar.gz
gnunet-cf45b8dff29c366d51aa2e6ea6a64b99b514b9c9.zip
bugfixes and redesigning scheduler API
Diffstat (limited to 'src/util')
-rw-r--r--src/util/client.c13
-rw-r--r--src/util/connection.c37
-rw-r--r--src/util/crypto_hash.c15
-rw-r--r--src/util/disk.c8
-rw-r--r--src/util/gnunet-service-resolver.c2
-rw-r--r--src/util/resolver_api.c9
-rw-r--r--src/util/scheduler.c555
-rw-r--r--src/util/server.c4
-rw-r--r--src/util/service.c31
-rw-r--r--src/util/test_connection.c3
-rw-r--r--src/util/test_connection_addressing.c3
-rw-r--r--src/util/test_connection_receive_cancel.c6
-rw-r--r--src/util/test_crypto_hash.c2
-rw-r--r--src/util/test_scheduler.c105
-rw-r--r--src/util/test_scheduler_delay.c3
-rw-r--r--src/util/test_server.c3
-rw-r--r--src/util/test_server_disconnect.c6
-rw-r--r--src/util/test_server_with_client.c3
-rw-r--r--src/util/test_service.c32
19 files changed, 366 insertions, 474 deletions
diff --git a/src/util/client.c b/src/util/client.c
index 60aa6f101..05f579b9f 100644
--- a/src/util/client.c
+++ b/src/util/client.c
@@ -308,8 +308,6 @@ GNUNET_CLIENT_disconnect (struct GNUNET_CLIENT_Connection *sock)
308 sock->in_receive = GNUNET_SYSERR; 308 sock->in_receive = GNUNET_SYSERR;
309 else 309 else
310 GNUNET_SCHEDULER_add_after (sock->sched, 310 GNUNET_SCHEDULER_add_after (sock->sched,
311 GNUNET_YES,
312 GNUNET_SCHEDULER_PRIORITY_KEEP,
313 GNUNET_SCHEDULER_NO_TASK, 311 GNUNET_SCHEDULER_NO_TASK,
314 &finish_cleanup, sock); 312 &finish_cleanup, sock);
315} 313}
@@ -353,8 +351,6 @@ receive_helper (void *cls,
353 GNUNET_assert (conn->msg_complete == GNUNET_NO); 351 GNUNET_assert (conn->msg_complete == GNUNET_NO);
354 if (GNUNET_SYSERR == conn->in_receive) 352 if (GNUNET_SYSERR == conn->in_receive)
355 GNUNET_SCHEDULER_add_after (conn->sched, 353 GNUNET_SCHEDULER_add_after (conn->sched,
356 GNUNET_YES,
357 GNUNET_SCHEDULER_PRIORITY_KEEP,
358 GNUNET_SCHEDULER_NO_TASK, 354 GNUNET_SCHEDULER_NO_TASK,
359 &finish_cleanup, conn); 355 &finish_cleanup, conn);
360 conn->in_receive = GNUNET_NO; 356 conn->in_receive = GNUNET_NO;
@@ -412,8 +408,6 @@ receive_task (void *scls, const struct GNUNET_SCHEDULER_TaskContext *tc)
412 408
413 if (GNUNET_SYSERR == sock->in_receive) 409 if (GNUNET_SYSERR == sock->in_receive)
414 GNUNET_SCHEDULER_add_after (sock->sched, 410 GNUNET_SCHEDULER_add_after (sock->sched,
415 GNUNET_YES,
416 GNUNET_SCHEDULER_PRIORITY_KEEP,
417 GNUNET_SCHEDULER_NO_TASK, 411 GNUNET_SCHEDULER_NO_TASK,
418 &finish_cleanup, sock); 412 &finish_cleanup, sock);
419 sock->in_receive = GNUNET_NO; 413 sock->in_receive = GNUNET_NO;
@@ -457,8 +451,6 @@ GNUNET_CLIENT_receive (struct GNUNET_CLIENT_Connection *sock,
457 sock->in_receive = GNUNET_YES; 451 sock->in_receive = GNUNET_YES;
458 if (GNUNET_YES == sock->msg_complete) 452 if (GNUNET_YES == sock->msg_complete)
459 GNUNET_SCHEDULER_add_after (sock->sched, 453 GNUNET_SCHEDULER_add_after (sock->sched,
460 GNUNET_YES,
461 GNUNET_SCHEDULER_PRIORITY_KEEP,
462 GNUNET_SCHEDULER_NO_TASK, 454 GNUNET_SCHEDULER_NO_TASK,
463 &receive_task, sock); 455 &receive_task, sock);
464 else 456 else
@@ -522,7 +514,6 @@ service_test_error (struct GNUNET_SCHEDULER_Handle *s,
522 GNUNET_SCHEDULER_Task task, void *task_cls) 514 GNUNET_SCHEDULER_Task task, void *task_cls)
523{ 515{
524 GNUNET_SCHEDULER_add_continuation (s, 516 GNUNET_SCHEDULER_add_continuation (s,
525 GNUNET_YES,
526 task, 517 task,
527 task_cls, 518 task_cls,
528 GNUNET_SCHEDULER_REASON_TIMEOUT); 519 GNUNET_SCHEDULER_REASON_TIMEOUT);
@@ -549,7 +540,6 @@ confirm_handler (void *cls, const struct GNUNET_MessageHeader *msg)
549 "Received confirmation that service is running.\n"); 540 "Received confirmation that service is running.\n");
550#endif 541#endif
551 GNUNET_SCHEDULER_add_continuation (conn->sched, 542 GNUNET_SCHEDULER_add_continuation (conn->sched,
552 GNUNET_YES,
553 conn->test_cb, 543 conn->test_cb,
554 conn->test_cb_cls, 544 conn->test_cb_cls,
555 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 545 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
@@ -719,9 +709,6 @@ client_notify (void *cls, size_t size, void *buf)
719 GNUNET_assert (NULL != th->sock->sock); 709 GNUNET_assert (NULL != th->sock->sock);
720 delay = GNUNET_TIME_relative_min (delay, GNUNET_TIME_UNIT_SECONDS); 710 delay = GNUNET_TIME_relative_min (delay, GNUNET_TIME_UNIT_SECONDS);
721 th->task = GNUNET_SCHEDULER_add_delayed (th->sock->sched, 711 th->task = GNUNET_SCHEDULER_add_delayed (th->sock->sched,
722 GNUNET_NO,
723 GNUNET_SCHEDULER_PRIORITY_KEEP,
724 GNUNET_SCHEDULER_NO_TASK,
725 delay, 712 delay,
726 &client_delayed_retry, th); 713 &client_delayed_retry, th);
727 th->sock->th = th; 714 th->sock->th = th;
diff --git a/src/util/connection.c b/src/util/connection.c
index 066b81bbe..9bf2aa975 100644
--- a/src/util/connection.c
+++ b/src/util/connection.c
@@ -476,8 +476,6 @@ destroy_continuation (void *cls,
476 "Destroy waits for write_task to be done (%p)\n", sock); 476 "Destroy waits for write_task to be done (%p)\n", sock);
477#endif 477#endif
478 GNUNET_SCHEDULER_add_after (sock->sched, 478 GNUNET_SCHEDULER_add_after (sock->sched,
479 GNUNET_YES,
480 GNUNET_SCHEDULER_PRIORITY_KEEP,
481 sock->write_task, 479 sock->write_task,
482 &destroy_continuation, sock); 480 &destroy_continuation, sock);
483 return; 481 return;
@@ -498,8 +496,6 @@ destroy_continuation (void *cls,
498 if (sock->read_task != GNUNET_SCHEDULER_NO_TASK) 496 if (sock->read_task != GNUNET_SCHEDULER_NO_TASK)
499 { 497 {
500 GNUNET_SCHEDULER_add_after (sock->sched, 498 GNUNET_SCHEDULER_add_after (sock->sched,
501 GNUNET_YES,
502 GNUNET_SCHEDULER_PRIORITY_KEEP,
503 sock->read_task, 499 sock->read_task,
504 &destroy_continuation, sock); 500 &destroy_continuation, sock);
505 return; 501 return;
@@ -569,8 +565,6 @@ connect_fail_continuation (struct GNUNET_CONNECTION_Handle *h)
569#endif 565#endif
570 h->ccs -= COCO_RECEIVE_AGAIN; 566 h->ccs -= COCO_RECEIVE_AGAIN;
571 h->read_task = GNUNET_SCHEDULER_add_after (h->sched, 567 h->read_task = GNUNET_SCHEDULER_add_after (h->sched,
572 GNUNET_NO,
573 GNUNET_SCHEDULER_PRIORITY_KEEP,
574 GNUNET_SCHEDULER_NO_TASK, 568 GNUNET_SCHEDULER_NO_TASK,
575 &receive_again, h); 569 &receive_again, h);
576 } 570 }
@@ -586,8 +580,6 @@ connect_fail_continuation (struct GNUNET_CONNECTION_Handle *h)
586 h->nth.timeout_task = GNUNET_SCHEDULER_NO_TASK; 580 h->nth.timeout_task = GNUNET_SCHEDULER_NO_TASK;
587 h->ccs -= COCO_TRANSMIT_READY; 581 h->ccs -= COCO_TRANSMIT_READY;
588 h->write_task = GNUNET_SCHEDULER_add_after (h->sched, 582 h->write_task = GNUNET_SCHEDULER_add_after (h->sched,
589 GNUNET_NO,
590 GNUNET_SCHEDULER_PRIORITY_KEEP,
591 GNUNET_SCHEDULER_NO_TASK, 583 GNUNET_SCHEDULER_NO_TASK,
592 &transmit_ready, h); 584 &transmit_ready, h);
593 } 585 }
@@ -600,7 +592,6 @@ connect_fail_continuation (struct GNUNET_CONNECTION_Handle *h)
600#endif 592#endif
601 h->ccs -= COCO_DESTROY_CONTINUATION; 593 h->ccs -= COCO_DESTROY_CONTINUATION;
602 GNUNET_SCHEDULER_add_continuation (h->sched, 594 GNUNET_SCHEDULER_add_continuation (h->sched,
603 GNUNET_NO,
604 &destroy_continuation, 595 &destroy_continuation,
605 h, GNUNET_SCHEDULER_REASON_TIMEOUT); 596 h, GNUNET_SCHEDULER_REASON_TIMEOUT);
606 } 597 }
@@ -630,8 +621,6 @@ connect_success_continuation (struct GNUNET_CONNECTION_Handle *h)
630#endif 621#endif
631 h->ccs -= COCO_RECEIVE_AGAIN; 622 h->ccs -= COCO_RECEIVE_AGAIN;
632 h->read_task = GNUNET_SCHEDULER_add_after (h->sched, 623 h->read_task = GNUNET_SCHEDULER_add_after (h->sched,
633 GNUNET_NO,
634 GNUNET_SCHEDULER_PRIORITY_KEEP,
635 GNUNET_SCHEDULER_NO_TASK, 624 GNUNET_SCHEDULER_NO_TASK,
636 &receive_again, h); 625 &receive_again, h);
637 } 626 }
@@ -648,9 +637,6 @@ connect_success_continuation (struct GNUNET_CONNECTION_Handle *h)
648 h->ccs -= COCO_TRANSMIT_READY; 637 h->ccs -= COCO_TRANSMIT_READY;
649 h->write_task = 638 h->write_task =
650 GNUNET_SCHEDULER_add_write_net (h->sched, 639 GNUNET_SCHEDULER_add_write_net (h->sched,
651 GNUNET_NO,
652 GNUNET_SCHEDULER_PRIORITY_KEEP,
653 GNUNET_SCHEDULER_NO_TASK,
654 GNUNET_TIME_absolute_get_remaining 640 GNUNET_TIME_absolute_get_remaining
655 (h->nth.transmit_timeout), h->sock, 641 (h->nth.transmit_timeout), h->sock,
656 &transmit_ready, h); 642 &transmit_ready, h);
@@ -664,7 +650,6 @@ connect_success_continuation (struct GNUNET_CONNECTION_Handle *h)
664#endif 650#endif
665 h->ccs -= COCO_DESTROY_CONTINUATION; 651 h->ccs -= COCO_DESTROY_CONTINUATION;
666 GNUNET_SCHEDULER_add_continuation (h->sched, 652 GNUNET_SCHEDULER_add_continuation (h->sched,
667 GNUNET_NO,
668 &destroy_continuation, 653 &destroy_continuation,
669 h, 654 h,
670 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 655 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
@@ -808,9 +793,8 @@ try_connect_using_address (void *cls,
808 GNUNET_TIME_absolute_get_remaining (h-> 793 GNUNET_TIME_absolute_get_remaining (h->
809 receive_timeout)); 794 receive_timeout));
810 ap->task = 795 ap->task =
811 GNUNET_SCHEDULER_add_write_net (h->sched, GNUNET_NO, 796 GNUNET_SCHEDULER_add_write_net (h->sched,
812 GNUNET_SCHEDULER_PRIORITY_KEEP, 797 delay, ap->sock,
813 GNUNET_SCHEDULER_NO_TASK, delay, ap->sock,
814 &connect_probe_continuation, ap); 798 &connect_probe_continuation, ap);
815} 799}
816 800
@@ -956,8 +940,6 @@ GNUNET_CONNECTION_destroy (struct GNUNET_CONNECTION_Handle *sock)
956 } 940 }
957 GNUNET_assert (sock->sched != NULL); 941 GNUNET_assert (sock->sched != NULL);
958 GNUNET_SCHEDULER_add_after (sock->sched, 942 GNUNET_SCHEDULER_add_after (sock->sched,
959 GNUNET_YES,
960 GNUNET_SCHEDULER_PRIORITY_KEEP,
961 GNUNET_SCHEDULER_NO_TASK, 943 GNUNET_SCHEDULER_NO_TASK,
962 &destroy_continuation, sock); 944 &destroy_continuation, sock);
963} 945}
@@ -1101,9 +1083,6 @@ receive_again (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1101 GNUNET_assert (sh->sock != NULL); 1083 GNUNET_assert (sh->sock != NULL);
1102 /* connect succeeded, wait for data! */ 1084 /* connect succeeded, wait for data! */
1103 sh->read_task = GNUNET_SCHEDULER_add_read_net (tc->sched, 1085 sh->read_task = GNUNET_SCHEDULER_add_read_net (tc->sched,
1104 GNUNET_YES,
1105 GNUNET_SCHEDULER_PRIORITY_KEEP,
1106 GNUNET_SCHEDULER_NO_TASK,
1107 GNUNET_TIME_absolute_get_remaining 1086 GNUNET_TIME_absolute_get_remaining
1108 (sh->receive_timeout), 1087 (sh->receive_timeout),
1109 sh->sock, 1088 sh->sock,
@@ -1406,9 +1385,6 @@ SCHEDULE_WRITE:
1406 if (sock->write_task == GNUNET_SCHEDULER_NO_TASK) 1385 if (sock->write_task == GNUNET_SCHEDULER_NO_TASK)
1407 sock->write_task = 1386 sock->write_task =
1408 GNUNET_SCHEDULER_add_write_net (tc->sched, 1387 GNUNET_SCHEDULER_add_write_net (tc->sched,
1409 GNUNET_NO,
1410 GNUNET_SCHEDULER_PRIORITY_KEEP,
1411 GNUNET_SCHEDULER_NO_TASK,
1412 GNUNET_TIME_absolute_get_remaining 1388 GNUNET_TIME_absolute_get_remaining
1413 (sock->nth.transmit_timeout), 1389 (sock->nth.transmit_timeout),
1414 sock->sock, &transmit_ready, sock); 1390 sock->sock, &transmit_ready, sock);
@@ -1453,9 +1429,6 @@ GNUNET_CONNECTION_notify_transmit_ready (struct GNUNET_CONNECTION_Handle
1453 (sock->ap_head == NULL) && (sock->dns_active == NULL)) 1429 (sock->ap_head == NULL) && (sock->dns_active == NULL))
1454 { 1430 {
1455 sock->write_task = GNUNET_SCHEDULER_add_delayed (sock->sched, 1431 sock->write_task = GNUNET_SCHEDULER_add_delayed (sock->sched,
1456 GNUNET_NO,
1457 GNUNET_SCHEDULER_PRIORITY_KEEP,
1458 GNUNET_SCHEDULER_NO_TASK,
1459 GNUNET_TIME_UNIT_ZERO, 1432 GNUNET_TIME_UNIT_ZERO,
1460 &connect_error, sock); 1433 &connect_error, sock);
1461 return &sock->nth; 1434 return &sock->nth;
@@ -1469,9 +1442,6 @@ GNUNET_CONNECTION_notify_transmit_ready (struct GNUNET_CONNECTION_Handle
1469 "Scheduling transmit_ready (%p).\n", sock); 1442 "Scheduling transmit_ready (%p).\n", sock);
1470#endif 1443#endif
1471 sock->write_task = GNUNET_SCHEDULER_add_write_net (sock->sched, 1444 sock->write_task = GNUNET_SCHEDULER_add_write_net (sock->sched,
1472 GNUNET_NO,
1473 GNUNET_SCHEDULER_PRIORITY_KEEP,
1474 GNUNET_SCHEDULER_NO_TASK,
1475 GNUNET_TIME_absolute_get_remaining 1445 GNUNET_TIME_absolute_get_remaining
1476 (sock->nth. 1446 (sock->nth.
1477 transmit_timeout), 1447 transmit_timeout),
@@ -1488,9 +1458,6 @@ GNUNET_CONNECTION_notify_transmit_ready (struct GNUNET_CONNECTION_Handle
1488#endif 1458#endif
1489 sock->ccs |= COCO_TRANSMIT_READY; 1459 sock->ccs |= COCO_TRANSMIT_READY;
1490 sock->nth.timeout_task = GNUNET_SCHEDULER_add_delayed (sock->sched, 1460 sock->nth.timeout_task = GNUNET_SCHEDULER_add_delayed (sock->sched,
1491 GNUNET_NO,
1492 GNUNET_SCHEDULER_PRIORITY_KEEP,
1493 GNUNET_SCHEDULER_NO_TASK,
1494 timeout, 1461 timeout,
1495 &transmit_timeout, 1462 &transmit_timeout,
1496 sock); 1463 sock);
diff --git a/src/util/crypto_hash.c b/src/util/crypto_hash.c
index 3f5869489..dcee545f7 100644
--- a/src/util/crypto_hash.c
+++ b/src/util/crypto_hash.c
@@ -416,11 +416,6 @@ struct FileHashContext
416 uint64_t offset; 416 uint64_t offset;
417 417
418 /** 418 /**
419 * Run on shutdown?
420 */
421 int run_on_shutdown;
422
423 /**
424 * File descriptor. 419 * File descriptor.
425 */ 420 */
426 struct GNUNET_DISK_FileHandle *fh; 421 struct GNUNET_DISK_FileHandle *fh;
@@ -476,8 +471,6 @@ file_hash_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
476 return; 471 return;
477 } 472 }
478 GNUNET_SCHEDULER_add_after (tc->sched, 473 GNUNET_SCHEDULER_add_after (tc->sched,
479 fhc->run_on_shutdown,
480 GNUNET_SCHEDULER_PRIORITY_KEEP,
481 GNUNET_SCHEDULER_NO_TASK, &file_hash_task, fhc); 474 GNUNET_SCHEDULER_NO_TASK, &file_hash_task, fhc);
482} 475}
483 476
@@ -487,7 +480,6 @@ file_hash_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
487 * 480 *
488 * @param sched scheduler to use 481 * @param sched scheduler to use
489 * @param priority scheduling priority to use 482 * @param priority scheduling priority to use
490 * @param run_on_shutdown should we complete even on shutdown?
491 * @param filename name of file to hash 483 * @param filename name of file to hash
492 * @param blocksize number of bytes to process in one task 484 * @param blocksize number of bytes to process in one task
493 * @param callback function to call upon completion 485 * @param callback function to call upon completion
@@ -496,7 +488,6 @@ file_hash_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
496void 488void
497GNUNET_CRYPTO_hash_file (struct GNUNET_SCHEDULER_Handle *sched, 489GNUNET_CRYPTO_hash_file (struct GNUNET_SCHEDULER_Handle *sched,
498 enum GNUNET_SCHEDULER_Priority priority, 490 enum GNUNET_SCHEDULER_Priority priority,
499 int run_on_shutdown,
500 const char *filename, 491 const char *filename,
501 size_t blocksize, 492 size_t blocksize,
502 GNUNET_CRYPTO_HashCompletedCallback callback, 493 GNUNET_CRYPTO_HashCompletedCallback callback,
@@ -518,7 +509,6 @@ GNUNET_CRYPTO_hash_file (struct GNUNET_SCHEDULER_Handle *sched,
518 file_hash_finish (fhc, NULL); 509 file_hash_finish (fhc, NULL);
519 return; 510 return;
520 } 511 }
521 fhc->run_on_shutdown = run_on_shutdown;
522 fhc->fh = GNUNET_DISK_file_open (filename, 512 fhc->fh = GNUNET_DISK_file_open (filename,
523 GNUNET_DISK_OPEN_READ, 513 GNUNET_DISK_OPEN_READ,
524 GNUNET_DISK_PERM_NONE); 514 GNUNET_DISK_PERM_NONE);
@@ -527,10 +517,7 @@ GNUNET_CRYPTO_hash_file (struct GNUNET_SCHEDULER_Handle *sched,
527 file_hash_finish (fhc, NULL); 517 file_hash_finish (fhc, NULL);
528 return; 518 return;
529 } 519 }
530 GNUNET_SCHEDULER_add_after (sched, 520 GNUNET_SCHEDULER_add_with_priority (sched, priority, &file_hash_task, fhc);
531 run_on_shutdown,
532 priority,
533 GNUNET_SCHEDULER_NO_TASK, &file_hash_task, fhc);
534} 521}
535 522
536 523
diff --git a/src/util/disk.c b/src/util/disk.c
index 9f93a1ee2..3b3cb9e65 100644
--- a/src/util/disk.c
+++ b/src/util/disk.c
@@ -856,11 +856,9 @@ GNUNET_DISK_directory_iterator_next (struct GNUNET_DISK_DirectoryIterator
856 GNUNET_DISK_directory_iterator_next (iter, GNUNET_YES); 856 GNUNET_DISK_directory_iterator_next (iter, GNUNET_YES);
857 return GNUNET_NO; 857 return GNUNET_NO;
858 } 858 }
859 GNUNET_SCHEDULER_add_after (iter->sched, 859 GNUNET_SCHEDULER_add_with_priority (iter->sched,
860 GNUNET_YES, 860 iter->priority,
861 iter->priority, 861 &directory_iterator_task, iter);
862 GNUNET_SCHEDULER_NO_TASK,
863 &directory_iterator_task, iter);
864 return GNUNET_YES; 862 return GNUNET_YES;
865} 863}
866 864
diff --git a/src/util/gnunet-service-resolver.c b/src/util/gnunet-service-resolver.c
index f8dd2e166..4dcabface 100644
--- a/src/util/gnunet-service-resolver.c
+++ b/src/util/gnunet-service-resolver.c
@@ -516,7 +516,7 @@ main (int argc, char *const *argv)
516 ret = (GNUNET_OK == 516 ret = (GNUNET_OK ==
517 GNUNET_SERVICE_run (argc, 517 GNUNET_SERVICE_run (argc,
518 argv, 518 argv,
519 "resolver", &run, NULL, NULL, NULL)) ? 0 : 1; 519 "resolver", &run, NULL)) ? 0 : 1;
520 520
521 while (head != NULL) 521 while (head != NULL)
522 { 522 {
diff --git a/src/util/resolver_api.c b/src/util/resolver_api.c
index 69d143bc1..812cdc84e 100644
--- a/src/util/resolver_api.c
+++ b/src/util/resolver_api.c
@@ -442,9 +442,6 @@ GNUNET_RESOLVER_ip_get (struct GNUNET_SCHEDULER_Handle *sched,
442 ((domain == AF_INET6) || (domain == AF_UNSPEC)))) 442 ((domain == AF_INET6) || (domain == AF_UNSPEC))))
443 { 443 {
444 rh->task = GNUNET_SCHEDULER_add_delayed (sched, 444 rh->task = GNUNET_SCHEDULER_add_delayed (sched,
445 GNUNET_NO,
446 GNUNET_SCHEDULER_PRIORITY_KEEP,
447 GNUNET_SCHEDULER_NO_TASK,
448 GNUNET_TIME_UNIT_ZERO, 445 GNUNET_TIME_UNIT_ZERO,
449 &numeric_resolution, rh); 446 &numeric_resolution, rh);
450 return rh; 447 return rh;
@@ -455,9 +452,6 @@ GNUNET_RESOLVER_ip_get (struct GNUNET_SCHEDULER_Handle *sched,
455 if (0 == strcasecmp (loopback[i++], hostname)) 452 if (0 == strcasecmp (loopback[i++], hostname))
456 { 453 {
457 rh->task = GNUNET_SCHEDULER_add_delayed (sched, 454 rh->task = GNUNET_SCHEDULER_add_delayed (sched,
458 GNUNET_NO,
459 GNUNET_SCHEDULER_PRIORITY_KEEP,
460 GNUNET_SCHEDULER_NO_TASK,
461 GNUNET_TIME_UNIT_ZERO, 455 GNUNET_TIME_UNIT_ZERO,
462 &loopback_resolution, rh); 456 &loopback_resolution, rh);
463 return rh; 457 return rh;
@@ -623,9 +617,6 @@ GNUNET_RESOLVER_hostname_get (struct GNUNET_SCHEDULER_Handle *sched,
623 if (GNUNET_NO == do_resolve) 617 if (GNUNET_NO == do_resolve)
624 { 618 {
625 rh->task = GNUNET_SCHEDULER_add_delayed (sched, 619 rh->task = GNUNET_SCHEDULER_add_delayed (sched,
626 GNUNET_NO,
627 GNUNET_SCHEDULER_PRIORITY_KEEP,
628 GNUNET_SCHEDULER_NO_TASK,
629 GNUNET_TIME_UNIT_ZERO, 620 GNUNET_TIME_UNIT_ZERO,
630 &numeric_reverse, rh); 621 &numeric_reverse, rh);
631 return rh; 622 return rh;
diff --git a/src/util/scheduler.c b/src/util/scheduler.c
index 2bb356eb6..16f65b457 100644
--- a/src/util/scheduler.c
+++ b/src/util/scheduler.c
@@ -95,11 +95,6 @@ struct Task
95 */ 95 */
96 enum GNUNET_SCHEDULER_Priority priority; 96 enum GNUNET_SCHEDULER_Priority priority;
97 97
98 /**
99 * Should this task be run on shutdown?
100 */
101 int run_on_shutdown;
102
103}; 98};
104 99
105 100
@@ -135,12 +130,6 @@ struct GNUNET_SCHEDULER_Handle
135 GNUNET_SCHEDULER_TaskIdentifier lowest_pending_id; 130 GNUNET_SCHEDULER_TaskIdentifier lowest_pending_id;
136 131
137 /** 132 /**
138 * GNUNET_NO if we are running normally,
139 * GNUNET_YES if we are in shutdown mode.
140 */
141 int shutdown;
142
143 /**
144 * Number of tasks on the ready list. 133 * Number of tasks on the ready list.
145 */ 134 */
146 unsigned int ready_count; 135 unsigned int ready_count;
@@ -260,6 +249,8 @@ update_sets (struct GNUNET_SCHEDULER_Handle *sched,
260 GNUNET_NETWORK_fdset_add (rs, pos->read_set); 249 GNUNET_NETWORK_fdset_add (rs, pos->read_set);
261 if (pos->write_set != NULL) 250 if (pos->write_set != NULL)
262 GNUNET_NETWORK_fdset_add (ws, pos->write_set); 251 GNUNET_NETWORK_fdset_add (ws, pos->write_set);
252 if (pos->reason != 0)
253 *timeout = GNUNET_TIME_UNIT_ZERO;
263 pos = pos->next; 254 pos = pos->next;
264 } 255 }
265} 256}
@@ -309,12 +300,7 @@ is_ready (struct GNUNET_SCHEDULER_Handle *sched,
309 const struct GNUNET_NETWORK_FDSet *rs, 300 const struct GNUNET_NETWORK_FDSet *rs,
310 const struct GNUNET_NETWORK_FDSet *ws) 301 const struct GNUNET_NETWORK_FDSet *ws)
311{ 302{
312 if ((GNUNET_NO == task->run_on_shutdown) && (GNUNET_YES == sched->shutdown)) 303 if (now.value >= task->timeout.value)
313 return GNUNET_NO;
314 if ((GNUNET_YES == task->run_on_shutdown) &&
315 (GNUNET_YES == sched->shutdown))
316 task->reason |= GNUNET_SCHEDULER_REASON_SHUTDOWN;
317 if (now.value >= task->timeout.value)
318 task->reason |= GNUNET_SCHEDULER_REASON_TIMEOUT; 304 task->reason |= GNUNET_SCHEDULER_REASON_TIMEOUT;
319 if ((0 == (task->reason & GNUNET_SCHEDULER_REASON_READ_READY)) && 305 if ((0 == (task->reason & GNUNET_SCHEDULER_REASON_READ_READY)) &&
320 (rs != NULL) && (set_overlaps (rs, task->read_set))) 306 (rs != NULL) && (set_overlaps (rs, task->read_set)))
@@ -395,6 +381,32 @@ check_ready (struct GNUNET_SCHEDULER_Handle *handle,
395 381
396 382
397/** 383/**
384 * Request the shutdown of a scheduler. Marks all currently
385 * pending tasks as ready because of shutdown. This will
386 * cause all tasks to run (as soon as possible, respecting
387 * priorities and prerequisite tasks). Note that tasks
388 * scheduled AFTER this call may still be delayed arbitrarily.
389 *
390 * @param sched the scheduler
391 */
392void
393GNUNET_SCHEDULER_shutdown (struct GNUNET_SCHEDULER_Handle *sched)
394{
395 struct Task *pos;
396
397 pos = sched->pending;
398 while (pos != NULL)
399 {
400 pos->reason |= GNUNET_SCHEDULER_REASON_SHUTDOWN;
401 /* we don't move the task into the ready queue yet; check_ready
402 will do that later, possibly adding additional
403 readyness-factors */
404 pos = pos->next;
405 }
406}
407
408
409/**
398 * Destroy a task (release associated resources) 410 * Destroy a task (release associated resources)
399 * 411 *
400 * @param t task to destroy 412 * @param t task to destroy
@@ -415,7 +427,7 @@ destroy_task (struct Task *t)
415 * empty. Keep running tasks until we are either no longer running 427 * empty. Keep running tasks until we are either no longer running
416 * "URGENT" tasks or until we have at least one "pending" task (which 428 * "URGENT" tasks or until we have at least one "pending" task (which
417 * may become ready, hence we should select on it). Naturally, if 429 * may become ready, hence we should select on it). Naturally, if
418 * there are no more ready tasks, we also return. 430 * there are no more ready tasks, we also return.
419 * 431 *
420 * @param sched the scheduler 432 * @param sched the scheduler
421 */ 433 */
@@ -459,7 +471,7 @@ run_ready (struct GNUNET_SCHEDULER_Handle *sched)
459 while ((sched->pending == NULL) || (p == GNUNET_SCHEDULER_PRIORITY_URGENT)); 471 while ((sched->pending == NULL) || (p == GNUNET_SCHEDULER_PRIORITY_URGENT));
460} 472}
461 473
462 474#ifndef MINGW
463/** 475/**
464 * Pipe used to communicate shutdown via signal. 476 * Pipe used to communicate shutdown via signal.
465 */ 477 */
@@ -478,19 +490,25 @@ sighandler_shutdown ()
478 (sigpipe, GNUNET_DISK_PIPE_END_WRITE), &c, 490 (sigpipe, GNUNET_DISK_PIPE_END_WRITE), &c,
479 sizeof (c)); 491 sizeof (c));
480} 492}
493#endif
481 494
482 495
483/** 496/**
484 * Initialize a scheduler using this thread. This function will 497 * Initialize and run scheduler. This function will return when all
485 * return when either a shutdown was initiated (via signal) and all 498 * tasks have completed. On systems with signals, receiving a SIGTERM
486 * tasks marked to "run_on_shutdown" have been completed or when all 499 * (and other similar signals) will cause "GNUNET_SCHEDULER_shutdown"
487 * tasks in general have been completed. 500 * to be run after the active task is complete. As a result, SIGTERM
501 * causes all active tasks to be scheduled with reason
502 * "GNUNET_SCHEDULER_REASON_SHUTDOWN". (However, tasks added
503 * afterwards will execute normally!). Note that any particular signal
504 * will only shut down one scheduler; applications should always only
505 * create a single scheduler.
488 * 506 *
489 * @param task task to run immediately 507 * @param task task to run immediately
490 * @param cls closure of task 508 * @param task_cls closure of task
491 */ 509 */
492void 510void
493GNUNET_SCHEDULER_run (GNUNET_SCHEDULER_Task task, void *cls) 511GNUNET_SCHEDULER_run (GNUNET_SCHEDULER_Task task, void *task_cls)
494{ 512{
495 struct GNUNET_SCHEDULER_Handle sched; 513 struct GNUNET_SCHEDULER_Handle sched;
496 struct GNUNET_NETWORK_FDSet *rs; 514 struct GNUNET_NETWORK_FDSet *rs;
@@ -501,12 +519,12 @@ GNUNET_SCHEDULER_run (GNUNET_SCHEDULER_Task task, void *cls)
501 struct GNUNET_SIGNAL_Context *shc_term; 519 struct GNUNET_SIGNAL_Context *shc_term;
502 struct GNUNET_SIGNAL_Context *shc_quit; 520 struct GNUNET_SIGNAL_Context *shc_quit;
503 struct GNUNET_SIGNAL_Context *shc_hup; 521 struct GNUNET_SIGNAL_Context *shc_hup;
504 struct Task *tpos;
505 unsigned long long last_tr; 522 unsigned long long last_tr;
506 unsigned int busy_wait_warning; 523 unsigned int busy_wait_warning;
507#ifndef MINGW 524#ifndef MINGW
508 const struct GNUNET_DISK_FileHandle *pr; 525 const struct GNUNET_DISK_FileHandle *pr;
509#endif 526#endif
527 char c;
510 528
511 rs = GNUNET_NETWORK_fdset_create (); 529 rs = GNUNET_NETWORK_fdset_create ();
512 ws = GNUNET_NETWORK_fdset_create (); 530 ws = GNUNET_NETWORK_fdset_create ();
@@ -516,38 +534,40 @@ GNUNET_SCHEDULER_run (GNUNET_SCHEDULER_Task task, void *cls)
516 GNUNET_assert (sigpipe != NULL); 534 GNUNET_assert (sigpipe != NULL);
517 pr = GNUNET_DISK_pipe_handle (sigpipe, GNUNET_DISK_PIPE_END_READ); 535 pr = GNUNET_DISK_pipe_handle (sigpipe, GNUNET_DISK_PIPE_END_READ);
518 GNUNET_assert (pr != NULL); 536 GNUNET_assert (pr != NULL);
519 shc_int = GNUNET_SIGNAL_handler_install (SIGINT, &sighandler_shutdown); 537 shc_int = GNUNET_SIGNAL_handler_install (SIGINT, &sighandler_shutdown);
520 shc_term = GNUNET_SIGNAL_handler_install (SIGTERM, &sighandler_shutdown); 538 shc_term = GNUNET_SIGNAL_handler_install (SIGTERM, &sighandler_shutdown);
521 shc_quit = GNUNET_SIGNAL_handler_install (SIGQUIT, &sighandler_shutdown); 539 shc_quit = GNUNET_SIGNAL_handler_install (SIGQUIT, &sighandler_shutdown);
522 shc_hup = GNUNET_SIGNAL_handler_install (SIGHUP, &sighandler_shutdown); 540 shc_hup = GNUNET_SIGNAL_handler_install (SIGHUP, &sighandler_shutdown);
523#endif 541#endif
524 memset (&sched, 0, sizeof (sched)); 542 memset (&sched, 0, sizeof (sched));
525 sched.current_priority = GNUNET_SCHEDULER_PRIORITY_DEFAULT; 543 sched.current_priority = GNUNET_SCHEDULER_PRIORITY_DEFAULT;
526 GNUNET_SCHEDULER_add_continuation (&sched, 544 GNUNET_SCHEDULER_add_continuation (&sched,
527 GNUNET_YES,
528 task, 545 task,
529 cls, GNUNET_SCHEDULER_REASON_STARTUP); 546 task_cls,
547 GNUNET_SCHEDULER_REASON_STARTUP);
530 last_tr = 0; 548 last_tr = 0;
531 busy_wait_warning = 0; 549 busy_wait_warning = 0;
532 while ((GNUNET_NO == sched.shutdown) && 550 while ( (sched.pending != NULL) || (sched.ready_count > 0) )
533 ((sched.pending != NULL) || (sched.ready_count > 0)))
534 { 551 {
535 GNUNET_NETWORK_fdset_zero (rs); 552 GNUNET_NETWORK_fdset_zero (rs);
536 GNUNET_NETWORK_fdset_zero (ws); 553 GNUNET_NETWORK_fdset_zero (ws);
537 timeout = GNUNET_TIME_relative_get_forever (); 554 timeout = GNUNET_TIME_UNIT_FOREVER_REL;
538 update_sets (&sched, rs, ws, &timeout); 555 update_sets (&sched, rs, ws, &timeout);
539#ifndef MINGW
540 GNUNET_NETWORK_fdset_handle_set (rs, pr); 556 GNUNET_NETWORK_fdset_handle_set (rs, pr);
541#endif
542 if (sched.ready_count > 0) 557 if (sched.ready_count > 0)
543 { 558 {
544 /* no blocking, more work already ready! */ 559 /* no blocking, more work already ready! */
545 timeout = GNUNET_TIME_relative_get_zero (); 560 timeout = GNUNET_TIME_UNIT_ZERO;
546 } 561 }
547 ret = GNUNET_NETWORK_socket_select (rs, ws, NULL, timeout); 562 ret = GNUNET_NETWORK_socket_select (rs, ws, NULL, timeout);
548#ifndef MINGW 563#ifndef MINGW
549 if (GNUNET_NETWORK_fdset_handle_isset (rs, pr)) 564 if (GNUNET_NETWORK_fdset_handle_isset (rs, pr))
550 break; 565 {
566 /* consume the signal */
567 GNUNET_DISK_file_read (pr, &c, sizeof(c));
568 /* mark all active tasks as ready due to shutdown */
569 GNUNET_SCHEDULER_shutdown (&sched);
570 }
551#endif 571#endif
552 if (last_tr == sched.tasks_run) 572 if (last_tr == sched.tasks_run)
553 { 573 {
@@ -574,7 +594,6 @@ GNUNET_SCHEDULER_run (GNUNET_SCHEDULER_Task task, void *cls)
574 check_ready (&sched, rs, ws); 594 check_ready (&sched, rs, ws);
575 run_ready (&sched); 595 run_ready (&sched);
576 } 596 }
577 sched.shutdown = GNUNET_YES;
578#ifndef MINGW 597#ifndef MINGW
579 GNUNET_SIGNAL_handler_uninstall (shc_int); 598 GNUNET_SIGNAL_handler_uninstall (shc_int);
580 GNUNET_SIGNAL_handler_uninstall (shc_term); 599 GNUNET_SIGNAL_handler_uninstall (shc_term);
@@ -583,36 +602,11 @@ GNUNET_SCHEDULER_run (GNUNET_SCHEDULER_Task task, void *cls)
583 GNUNET_DISK_pipe_close (sigpipe); 602 GNUNET_DISK_pipe_close (sigpipe);
584 sigpipe = NULL; 603 sigpipe = NULL;
585#endif 604#endif
586 do
587 {
588 run_ready (&sched);
589 check_ready (&sched, NULL, NULL);
590 }
591 while (sched.ready_count > 0);
592 while (NULL != (tpos = sched.pending))
593 {
594 sched.pending = tpos->next;
595 GNUNET_free (tpos);
596 }
597 GNUNET_NETWORK_fdset_destroy (rs); 605 GNUNET_NETWORK_fdset_destroy (rs);
598 GNUNET_NETWORK_fdset_destroy (ws); 606 GNUNET_NETWORK_fdset_destroy (ws);
599} 607}
600 608
601 609
602/**
603 * Request the shutdown of a scheduler. This function can be used to
604 * stop a scheduling thread when created with the
605 * "GNUNET_SCHEDULER_init_thread" function or from within the signal
606 * handler for signals causing shutdowns.
607 *
608 * @param sched the scheduler
609 */
610void
611GNUNET_SCHEDULER_shutdown (struct GNUNET_SCHEDULER_Handle *sched)
612{
613 sched->shutdown = GNUNET_YES;
614}
615
616 610
617/** 611/**
618 * Get information about the current load of this scheduler. Use this 612 * Get information about the current load of this scheduler. Use this
@@ -715,102 +709,113 @@ GNUNET_SCHEDULER_cancel (struct GNUNET_SCHEDULER_Handle *sched,
715 * and the reason code can be specified. 709 * and the reason code can be specified.
716 * 710 *
717 * @param sched scheduler to use 711 * @param sched scheduler to use
718 * @param run_on_shutdown should this task be run if we are shutting down? 712 * @param task main function of the task
719 * @param main main function of the task 713 * @param task_cls closure for 'main'
720 * @param cls closure for 'main'
721 * @param reason reason for task invocation 714 * @param reason reason for task invocation
722 */ 715 */
723void 716void
724GNUNET_SCHEDULER_add_continuation (struct GNUNET_SCHEDULER_Handle *sched, 717GNUNET_SCHEDULER_add_continuation (struct GNUNET_SCHEDULER_Handle *sched,
725 int run_on_shutdown, 718 GNUNET_SCHEDULER_Task task,
726 GNUNET_SCHEDULER_Task main, 719 void *task_cls,
727 void *cls,
728 enum GNUNET_SCHEDULER_Reason reason) 720 enum GNUNET_SCHEDULER_Reason reason)
729{ 721{
730 struct Task *task; 722 struct Task *t;
731 723
732 task = GNUNET_malloc (sizeof (struct Task)); 724 t = GNUNET_malloc (sizeof (struct Task));
733 task->callback = main; 725 t->callback = task;
734 task->callback_cls = cls; 726 t->callback_cls = task_cls;
735 task->id = ++sched->last_id; 727 t->id = ++sched->last_id;
736 task->reason = reason; 728 t->reason = reason;
737 task->priority = sched->current_priority; 729 t->priority = sched->current_priority;
738 task->run_on_shutdown = run_on_shutdown;
739#if DEBUG_TASKS 730#if DEBUG_TASKS
740 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 731 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
741 "Adding continuation task: %llu / %p\n", 732 "Adding continuation task: %llu / %p\n",
742 task->id, task->callback_cls); 733 t->id, t->callback_cls);
743#endif 734#endif
744 queue_ready_task (sched, task); 735 queue_ready_task (sched, t);
745} 736}
746 737
747 738
739
748/** 740/**
749 * Schedule a new task to be run after the specified 741 * Schedule a new task to be run after the specified prerequisite task
750 * prerequisite task has completed. 742 * has completed. It will be run with the priority of the calling
743 * task.
751 * 744 *
752 * @param sched scheduler to use 745 * @param sched scheduler to use
753 * @param run_on_shutdown run on shutdown?
754 * @param prio how important is this task?
755 * @param prerequisite_task run this task after the task with the given 746 * @param prerequisite_task run this task after the task with the given
756 * task identifier completes (and any of our other 747 * task identifier completes (and any of our other
757 * conditions, such as delay, read or write-readyness 748 * conditions, such as delay, read or write-readyness
758 * are satisfied). Use GNUNET_SCHEDULER_NO_TASK to not have any dependency 749 * are satisfied). Use GNUNET_SCHEDULER_NO_TASK to not have any dependency
759 * on completion of other tasks. 750 * on completion of other tasks (this will cause the task to run as
760 * @param main main function of the task 751 * soon as possible).
761 * @param cls closure for 'main' 752 * @param task main function of the task
753 * @param task_cls closure of task
762 * @return unique task identifier for the job 754 * @return unique task identifier for the job
763 * only valid until "main" is started! 755 * only valid until "task" is started!
764 */ 756 */
765GNUNET_SCHEDULER_TaskIdentifier 757GNUNET_SCHEDULER_TaskIdentifier
766GNUNET_SCHEDULER_add_after (struct GNUNET_SCHEDULER_Handle *sched, 758GNUNET_SCHEDULER_add_after (struct GNUNET_SCHEDULER_Handle *sched,
767 int run_on_shutdown,
768 enum GNUNET_SCHEDULER_Priority prio,
769 GNUNET_SCHEDULER_TaskIdentifier prerequisite_task, 759 GNUNET_SCHEDULER_TaskIdentifier prerequisite_task,
770 GNUNET_SCHEDULER_Task main, void *cls) 760 GNUNET_SCHEDULER_Task task,
761 void *task_cls)
771{ 762{
772 return GNUNET_SCHEDULER_add_select (sched, run_on_shutdown, prio, 763 return GNUNET_SCHEDULER_add_select (sched,
764 GNUNET_SCHEDULER_PRIORITY_KEEP,
773 prerequisite_task, 765 prerequisite_task,
774 GNUNET_TIME_UNIT_ZERO, 766 GNUNET_TIME_UNIT_ZERO,
775 NULL, NULL, main, cls); 767 NULL, NULL, task, task_cls);
776} 768}
777 769
778 770
779/** 771/**
772 * Schedule a new task to be run with a specified priority.
773 *
774 * @param sched scheduler to use
775 * @param prio how important is the new task?
776 * @param task main function of the task
777 * @param task_cls closure of task
778 * @return unique task identifier for the job
779 * only valid until "task" is started!
780 */
781GNUNET_SCHEDULER_TaskIdentifier
782GNUNET_SCHEDULER_add_with_priority (struct GNUNET_SCHEDULER_Handle *sched,
783 enum GNUNET_SCHEDULER_Priority prio,
784 GNUNET_SCHEDULER_Task task,
785 void *task_cls)
786{
787 return GNUNET_SCHEDULER_add_select (sched,
788 prio,
789 GNUNET_SCHEDULER_NO_TASK,
790 GNUNET_TIME_UNIT_ZERO,
791 NULL, NULL, task, task_cls);
792}
793
794
795
796/**
780 * Schedule a new task to be run with a specified delay. The task 797 * Schedule a new task to be run with a specified delay. The task
781 * will be scheduled for execution once the delay has expired and the 798 * will be scheduled for execution once the delay has expired. It
782 * prerequisite task has completed. 799 * will be run with the priority of the calling task.
783 * 800 *
784 * @param sched scheduler to use 801 * @param sched scheduler to use
785 * @param run_on_shutdown run on shutdown? You can use this 802 * @param delay when should this operation time out? Use
786 * argument to run a function only during shutdown 803 * GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown"
787 * by setting delay to -1. Set this 804 * @param task main function of the task
788 * argument to GNUNET_NO to skip this task if 805 * @param task_cls closure of task
789 * the user requested process termination.
790 * @param prio how important is this task?
791 * @param prerequisite_task run this task after the task with the given
792 * task identifier completes (and any of our other
793 * conditions, such as delay, read or write-readyness
794 * are satisfied). Use GNUNET_SCHEDULER_NO_TASK to not have any dependency
795 * on completion of other tasks.
796 * @param delay how long should we wait? Use GNUNET_TIME_UNIT_FOREVER_REL for "forever"
797 * @param main main function of the task
798 * @param cls closure of task
799 * @return unique task identifier for the job 806 * @return unique task identifier for the job
800 * only valid until "main" is started! 807 * only valid until "task" is started!
801 */ 808 */
802GNUNET_SCHEDULER_TaskIdentifier 809GNUNET_SCHEDULER_TaskIdentifier
803GNUNET_SCHEDULER_add_delayed (struct GNUNET_SCHEDULER_Handle * sched, 810GNUNET_SCHEDULER_add_delayed (struct GNUNET_SCHEDULER_Handle *sched,
804 int run_on_shutdown,
805 enum GNUNET_SCHEDULER_Priority prio,
806 GNUNET_SCHEDULER_TaskIdentifier
807 prerequisite_task,
808 struct GNUNET_TIME_Relative delay, 811 struct GNUNET_TIME_Relative delay,
809 GNUNET_SCHEDULER_Task main, void *cls) 812 GNUNET_SCHEDULER_Task task,
813 void *task_cls)
810{ 814{
811 return GNUNET_SCHEDULER_add_select (sched, run_on_shutdown, prio, 815 return GNUNET_SCHEDULER_add_select (sched,
812 prerequisite_task, delay, 816 GNUNET_SCHEDULER_PRIORITY_KEEP,
813 NULL, NULL, main, cls); 817 GNUNET_SCHEDULER_NO_TASK, delay,
818 NULL, NULL, task, task_cls);
814} 819}
815 820
816 821
@@ -819,34 +824,24 @@ GNUNET_SCHEDULER_add_delayed (struct GNUNET_SCHEDULER_Handle * sched,
819 * specified file descriptor is ready for reading. The delay can be 824 * specified file descriptor is ready for reading. The delay can be
820 * used as a timeout on the socket being ready. The task will be 825 * used as a timeout on the socket being ready. The task will be
821 * scheduled for execution once either the delay has expired or the 826 * scheduled for execution once either the delay has expired or the
822 * socket operation is ready. 827 * socket operation is ready. It will be run with the priority of
828 * the calling task.
823 * 829 *
824 * @param sched scheduler to use 830 * @param sched scheduler to use
825 * @param run_on_shutdown run on shutdown? Set this 831 * @param delay when should this operation time out? Use
826 * argument to GNUNET_NO to skip this task if 832 * GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown"
827 * the user requested process termination.
828 * @param prio how important is this task?
829 * @param prerequisite_task run this task after the task with the given
830 * task identifier completes (and any of our other
831 * conditions, such as delay, read or write-readyness
832 * are satisfied). Use GNUNET_SCHEDULER_NO_TASK to not have any dependency
833 * on completion of other tasks.
834 * @param delay how long should we wait? Use GNUNET_TIME_UNIT_FOREVER_REL for "forever"
835 * @param rfd read file-descriptor 833 * @param rfd read file-descriptor
836 * @param main main function of the task 834 * @param task main function of the task
837 * @param cls closure of task 835 * @param task_cls closure of task
838 * @return unique task identifier for the job 836 * @return unique task identifier for the job
839 * only valid until "main" is started! 837 * only valid until "task" is started!
840 */ 838 */
841GNUNET_SCHEDULER_TaskIdentifier 839GNUNET_SCHEDULER_TaskIdentifier
842GNUNET_SCHEDULER_add_read_net (struct GNUNET_SCHEDULER_Handle * sched, 840GNUNET_SCHEDULER_add_read_net (struct GNUNET_SCHEDULER_Handle *sched,
843 int run_on_shutdown, 841 struct GNUNET_TIME_Relative delay,
844 enum GNUNET_SCHEDULER_Priority prio, 842 struct GNUNET_NETWORK_Handle *rfd,
845 GNUNET_SCHEDULER_TaskIdentifier 843 GNUNET_SCHEDULER_Task task,
846 prerequisite_task, 844 void *task_cls)
847 struct GNUNET_TIME_Relative delay,
848 struct GNUNET_NETWORK_Handle * rfd,
849 GNUNET_SCHEDULER_Task main, void *cls)
850{ 845{
851 struct GNUNET_NETWORK_FDSet *rs; 846 struct GNUNET_NETWORK_FDSet *rs;
852 GNUNET_SCHEDULER_TaskIdentifier ret; 847 GNUNET_SCHEDULER_TaskIdentifier ret;
@@ -854,9 +849,11 @@ GNUNET_SCHEDULER_add_read_net (struct GNUNET_SCHEDULER_Handle * sched,
854 GNUNET_assert (rfd != NULL); 849 GNUNET_assert (rfd != NULL);
855 rs = GNUNET_NETWORK_fdset_create (); 850 rs = GNUNET_NETWORK_fdset_create ();
856 GNUNET_NETWORK_fdset_set (rs, rfd); 851 GNUNET_NETWORK_fdset_set (rs, rfd);
857 ret = GNUNET_SCHEDULER_add_select (sched, run_on_shutdown, prio, 852 ret = GNUNET_SCHEDULER_add_select (sched,
858 prerequisite_task, delay, 853 GNUNET_SCHEDULER_PRIORITY_KEEP,
859 rs, NULL, main, cls); 854 GNUNET_SCHEDULER_NO_TASK,
855 delay,
856 rs, NULL, task, task_cls);
860 GNUNET_NETWORK_fdset_destroy (rs); 857 GNUNET_NETWORK_fdset_destroy (rs);
861 return ret; 858 return ret;
862} 859}
@@ -867,34 +864,24 @@ GNUNET_SCHEDULER_add_read_net (struct GNUNET_SCHEDULER_Handle * sched,
867 * specified file descriptor is ready for writing. The delay can be 864 * specified file descriptor is ready for writing. The delay can be
868 * used as a timeout on the socket being ready. The task will be 865 * used as a timeout on the socket being ready. The task will be
869 * scheduled for execution once either the delay has expired or the 866 * scheduled for execution once either the delay has expired or the
870 * socket operation is ready. 867 * socket operation is ready. It will be run with the priority of
868 * the calling task.
871 * 869 *
872 * @param sched scheduler to use 870 * @param sched scheduler to use
873 * @param run_on_shutdown run on shutdown? Set this 871 * @param delay when should this operation time out? Use
874 * argument to GNUNET_NO to skip this task if 872 * GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown"
875 * the user requested process termination.
876 * @param prio how important is this task?
877 * @param prerequisite_task run this task after the task with the given
878 * task identifier completes (and any of our other
879 * conditions, such as delay, read or write-readyness
880 * are satisfied). Use GNUNET_SCHEDULER_NO_TASK to not have any dependency
881 * on completion of other tasks.
882 * @param delay how long should we wait? Use GNUNET_TIME_UNIT_FOREVER_REL for "forever"
883 * @param wfd write file-descriptor 873 * @param wfd write file-descriptor
884 * @param main main function of the task 874 * @param task main function of the task
885 * @param cls closure of task 875 * @param task_cls closure of task
886 * @return unique task identifier for the job 876 * @return unique task identifier for the job
887 * only valid until "main" is started! 877 * only valid until "task" is started!
888 */ 878 */
889GNUNET_SCHEDULER_TaskIdentifier 879GNUNET_SCHEDULER_TaskIdentifier
890GNUNET_SCHEDULER_add_write_net (struct GNUNET_SCHEDULER_Handle * sched, 880GNUNET_SCHEDULER_add_write_net (struct GNUNET_SCHEDULER_Handle *sched,
891 int run_on_shutdown, 881 struct GNUNET_TIME_Relative delay,
892 enum GNUNET_SCHEDULER_Priority prio, 882 struct GNUNET_NETWORK_Handle *wfd,
893 GNUNET_SCHEDULER_TaskIdentifier 883 GNUNET_SCHEDULER_Task task,
894 prerequisite_task, 884 void *task_cls)
895 struct GNUNET_TIME_Relative delay,
896 struct GNUNET_NETWORK_Handle * wfd,
897 GNUNET_SCHEDULER_Task main, void *cls)
898{ 885{
899 struct GNUNET_NETWORK_FDSet *ws; 886 struct GNUNET_NETWORK_FDSet *ws;
900 GNUNET_SCHEDULER_TaskIdentifier ret; 887 GNUNET_SCHEDULER_TaskIdentifier ret;
@@ -902,14 +889,95 @@ GNUNET_SCHEDULER_add_write_net (struct GNUNET_SCHEDULER_Handle * sched,
902 GNUNET_assert (wfd != NULL); 889 GNUNET_assert (wfd != NULL);
903 ws = GNUNET_NETWORK_fdset_create (); 890 ws = GNUNET_NETWORK_fdset_create ();
904 GNUNET_NETWORK_fdset_set (ws, wfd); 891 GNUNET_NETWORK_fdset_set (ws, wfd);
905 ret = GNUNET_SCHEDULER_add_select (sched, run_on_shutdown, prio, 892 ret = GNUNET_SCHEDULER_add_select (sched,
906 prerequisite_task, delay, 893 GNUNET_SCHEDULER_PRIORITY_KEEP,
907 NULL, ws, main, cls); 894 GNUNET_SCHEDULER_NO_TASK, delay,
895 NULL, ws, task, task_cls);
896 GNUNET_NETWORK_fdset_destroy (ws);
897 return ret;
898}
899
900
901/**
902 * Schedule a new task to be run with a specified delay or when the
903 * specified file descriptor is ready for reading. The delay can be
904 * used as a timeout on the socket being ready. The task will be
905 * scheduled for execution once either the delay has expired or the
906 * socket operation is ready. It will be run with the priority of
907 * the calling task.
908 *
909 * @param sched scheduler to use
910 * @param delay when should this operation time out? Use
911 * GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown"
912 * @param rfd read file-descriptor
913 * @param task main function of the task
914 * @param task_cls closure of task
915 * @return unique task identifier for the job
916 * only valid until "task" is started!
917 */
918GNUNET_SCHEDULER_TaskIdentifier
919GNUNET_SCHEDULER_add_read_file (struct GNUNET_SCHEDULER_Handle *sched,
920 struct GNUNET_TIME_Relative delay,
921 const struct GNUNET_DISK_FileHandle *rfd,
922 GNUNET_SCHEDULER_Task task,
923 void *task_cls)
924{
925 struct GNUNET_NETWORK_FDSet *rs;
926 GNUNET_SCHEDULER_TaskIdentifier ret;
927
928 GNUNET_assert (rfd != NULL);
929 rs = GNUNET_NETWORK_fdset_create ();
930 GNUNET_NETWORK_fdset_handle_set (rs, rfd);
931 ret = GNUNET_SCHEDULER_add_select (sched,
932 GNUNET_SCHEDULER_PRIORITY_KEEP,
933 GNUNET_SCHEDULER_NO_TASK, delay,
934 rs, NULL, task, task_cls);
935 GNUNET_NETWORK_fdset_destroy (rs);
936 return ret;
937}
938
939
940/**
941 * Schedule a new task to be run with a specified delay or when the
942 * specified file descriptor is ready for writing. The delay can be
943 * used as a timeout on the socket being ready. The task will be
944 * scheduled for execution once either the delay has expired or the
945 * socket operation is ready. It will be run with the priority of
946 * the calling task.
947 *
948 * @param sched scheduler to use
949 * @param delay when should this operation time out? Use
950 * GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown"
951 * @param wfd write file-descriptor
952 * @param task main function of the task
953 * @param task_cls closure of task
954 * @return unique task identifier for the job
955 * only valid until "task" is started!
956 */
957GNUNET_SCHEDULER_TaskIdentifier
958GNUNET_SCHEDULER_add_write_file (struct GNUNET_SCHEDULER_Handle *sched,
959 struct GNUNET_TIME_Relative delay,
960 const struct GNUNET_DISK_FileHandle *wfd,
961 GNUNET_SCHEDULER_Task task,
962 void *task_cls)
963{
964 struct GNUNET_NETWORK_FDSet *ws;
965 GNUNET_SCHEDULER_TaskIdentifier ret;
966
967 GNUNET_assert (wfd != NULL);
968 ws = GNUNET_NETWORK_fdset_create ();
969 GNUNET_NETWORK_fdset_handle_set (ws, wfd);
970 ret = GNUNET_SCHEDULER_add_select (sched,
971 GNUNET_SCHEDULER_PRIORITY_KEEP,
972 GNUNET_SCHEDULER_NO_TASK,
973 delay,
974 NULL, ws, task, task_cls);
908 GNUNET_NETWORK_fdset_destroy (ws); 975 GNUNET_NETWORK_fdset_destroy (ws);
909 return ret; 976 return ret;
910} 977}
911 978
912 979
980
913/** 981/**
914 * Schedule a new task to be run with a specified delay or when any of 982 * Schedule a new task to be run with a specified delay or when any of
915 * the specified file descriptor sets is ready. The delay can be used 983 * the specified file descriptor sets is ready. The delay can be used
@@ -928,160 +996,61 @@ GNUNET_SCHEDULER_add_write_net (struct GNUNET_SCHEDULER_Handle * sched,
928 * </code> 996 * </code>
929 * 997 *
930 * @param sched scheduler to use 998 * @param sched scheduler to use
931 * @param run_on_shutdown run on shutdown? Set this
932 * argument to GNUNET_NO to skip this task if
933 * the user requested process termination.
934 * @param prio how important is this task? 999 * @param prio how important is this task?
935 * @param prerequisite_task run this task after the task with the given 1000 * @param prerequisite_task run this task after the task with the given
936 * task identifier completes (and any of our other 1001 * task identifier completes (and any of our other
937 * conditions, such as delay, read or write-readyness 1002 * conditions, such as delay, read or write-readyness
938 * are satisfied). Use GNUNET_SCHEDULER_NO_TASK to not have any dependency 1003 * are satisfied). Use GNUNET_SCHEDULER_NO_TASK to not have any dependency
939 * on completion of other tasks. 1004 * on completion of other tasks.
940 * @param delay how long should we wait? Use GNUNET_TIME_UNIT_FOREVER_REL for "forever" 1005 * @param delay how long should we wait? Use GNUNET_TIME_UNIT_FOREVER_REL for "forever",
1006 * which means that the task will only be run after we receive SIGTERM
941 * @param rs set of file descriptors we want to read (can be NULL) 1007 * @param rs set of file descriptors we want to read (can be NULL)
942 * @param ws set of file descriptors we want to write (can be NULL) 1008 * @param ws set of file descriptors we want to write (can be NULL)
943 * @param main main function of the task 1009 * @param task main function of the task
944 * @param cls closure of task 1010 * @param task_cls closure of task
945 * @return unique task identifier for the job 1011 * @return unique task identifier for the job
946 * only valid until "main" is started! 1012 * only valid until "task" is started!
947 */ 1013 */
948GNUNET_SCHEDULER_TaskIdentifier 1014GNUNET_SCHEDULER_TaskIdentifier
949GNUNET_SCHEDULER_add_select (struct GNUNET_SCHEDULER_Handle * sched, 1015GNUNET_SCHEDULER_add_select (struct GNUNET_SCHEDULER_Handle *sched,
950 int run_on_shutdown,
951 enum GNUNET_SCHEDULER_Priority prio, 1016 enum GNUNET_SCHEDULER_Priority prio,
952 GNUNET_SCHEDULER_TaskIdentifier 1017 GNUNET_SCHEDULER_TaskIdentifier
953 prerequisite_task, 1018 prerequisite_task,
954 struct GNUNET_TIME_Relative delay, 1019 struct GNUNET_TIME_Relative delay,
955 const struct GNUNET_NETWORK_FDSet * rs, 1020 const struct GNUNET_NETWORK_FDSet * rs,
956 const struct GNUNET_NETWORK_FDSet * ws, 1021 const struct GNUNET_NETWORK_FDSet * ws,
957 GNUNET_SCHEDULER_Task main, void *cls) 1022 GNUNET_SCHEDULER_Task task,
1023 void *task_cls)
958{ 1024{
959 struct Task *task; 1025 struct Task *t;
960 1026
961 task = GNUNET_malloc (sizeof (struct Task)); 1027 t = GNUNET_malloc (sizeof (struct Task));
962 task->callback = main; 1028 t->callback = task;
963 task->callback_cls = cls; 1029 t->callback_cls = task_cls;
964 if (rs != NULL) 1030 if (rs != NULL)
965 { 1031 {
966 task->read_set = GNUNET_NETWORK_fdset_create (); 1032 t->read_set = GNUNET_NETWORK_fdset_create ();
967 GNUNET_NETWORK_fdset_copy (task->read_set, rs); 1033 GNUNET_NETWORK_fdset_copy (t->read_set, rs);
968 } 1034 }
969 if (ws != NULL) 1035 if (ws != NULL)
970 { 1036 {
971 task->write_set = GNUNET_NETWORK_fdset_create (); 1037 t->write_set = GNUNET_NETWORK_fdset_create ();
972 GNUNET_NETWORK_fdset_copy (task->write_set, ws); 1038 GNUNET_NETWORK_fdset_copy (t->write_set, ws);
973 } 1039 }
974 task->id = ++sched->last_id; 1040 t->id = ++sched->last_id;
975 task->prereq_id = prerequisite_task; 1041 t->prereq_id = prerequisite_task;
976 task->timeout = GNUNET_TIME_relative_to_absolute (delay); 1042 t->timeout = GNUNET_TIME_relative_to_absolute (delay);
977 task->priority = 1043 t->priority =
978 check_priority ((prio == 1044 check_priority ((prio ==
979 GNUNET_SCHEDULER_PRIORITY_KEEP) ? sched->current_priority 1045 GNUNET_SCHEDULER_PRIORITY_KEEP) ? sched->current_priority
980 : prio); 1046 : prio);
981 task->run_on_shutdown = run_on_shutdown; 1047 t->next = sched->pending;
982 task->next = sched->pending; 1048 sched->pending = t;
983 sched->pending = task;
984#if DEBUG_TASKS 1049#if DEBUG_TASKS
985 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1050 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
986 "Adding task: %llu / %p\n", task->id, task->callback_cls); 1051 "Adding task: %llu / %p\n", t->id, t->callback_cls);
987#endif 1052#endif
988 return task->id; 1053 return t->id;
989} 1054}
990 1055
991/**
992 * Schedule a new task to be run with a specified delay or when the
993 * specified file descriptor is ready for reading. The delay can be
994 * used as a timeout on the socket being ready. The task will be
995 * scheduled for execution once either the delay has expired or the
996 * socket operation is ready.
997 *
998 * @param sched scheduler to use
999 * @param run_on_shutdown run on shutdown? Set this
1000 * argument to GNUNET_NO to skip this task if
1001 * the user requested process termination.
1002 * @param prio how important is this task?
1003 * @param prerequisite_task run this task after the task with the given
1004 * task identifier completes (and any of our other
1005 * conditions, such as delay, read or write-readyness
1006 * are satisfied). Use GNUNET_SCHEDULER_NO_TASK to not have any dependency
1007 * on completion of other tasks.
1008 * @param delay how long should we wait? Use GNUNET_TIME_UNIT_FOREVER_REL for "forever"
1009 * @param rfd read file-descriptor
1010 * @param main main function of the task
1011 * @param cls closure of task
1012 * @return unique task identifier for the job
1013 * only valid until "main" is started!
1014 */
1015GNUNET_SCHEDULER_TaskIdentifier
1016GNUNET_SCHEDULER_add_read_file (struct GNUNET_SCHEDULER_Handle * sched,
1017 int run_on_shutdown,
1018 enum GNUNET_SCHEDULER_Priority prio,
1019 GNUNET_SCHEDULER_TaskIdentifier
1020 prerequisite_task,
1021 struct GNUNET_TIME_Relative delay,
1022 const struct GNUNET_DISK_FileHandle * rfd,
1023 GNUNET_SCHEDULER_Task main, void *cls)
1024{
1025 struct GNUNET_NETWORK_FDSet *rs;
1026 GNUNET_SCHEDULER_TaskIdentifier ret;
1027
1028 GNUNET_assert (rfd != NULL);
1029 rs = GNUNET_NETWORK_fdset_create ();
1030 GNUNET_NETWORK_fdset_handle_set (rs, rfd);
1031 ret = GNUNET_SCHEDULER_add_select (sched, run_on_shutdown, prio,
1032 prerequisite_task, delay,
1033 rs, NULL, main, cls);
1034 GNUNET_NETWORK_fdset_destroy (rs);
1035 return ret;
1036}
1037
1038
1039/**
1040 * Schedule a new task to be run with a specified delay or when the
1041 * specified file descriptor is ready for writing. The delay can be
1042 * used as a timeout on the socket being ready. The task will be
1043 * scheduled for execution once either the delay has expired or the
1044 * socket operation is ready.
1045 *
1046 * @param sched scheduler to use
1047 * @param run_on_shutdown run on shutdown? Set this
1048 * argument to GNUNET_NO to skip this task if
1049 * the user requested process termination.
1050 * @param prio how important is this task?
1051 * @param prerequisite_task run this task after the task with the given
1052 * task identifier completes (and any of our other
1053 * conditions, such as delay, read or write-readyness
1054 * are satisfied). Use GNUNET_SCHEDULER_NO_TASK to not have any dependency
1055 * on completion of other tasks.
1056 * @param delay how long should we wait? Use GNUNET_TIME_UNIT_FOREVER_REL for "forever"
1057 * @param wfd write file-descriptor
1058 * @param main main function of the task
1059 * @param cls closure of task
1060 * @return unique task identifier for the job
1061 * only valid until "main" is started!
1062 */
1063GNUNET_SCHEDULER_TaskIdentifier
1064GNUNET_SCHEDULER_add_write_file (struct GNUNET_SCHEDULER_Handle * sched,
1065 int run_on_shutdown,
1066 enum GNUNET_SCHEDULER_Priority prio,
1067 GNUNET_SCHEDULER_TaskIdentifier
1068 prerequisite_task,
1069 struct GNUNET_TIME_Relative delay,
1070 const struct GNUNET_DISK_FileHandle * wfd,
1071 GNUNET_SCHEDULER_Task main, void *cls)
1072{
1073 struct GNUNET_NETWORK_FDSet *ws;
1074 GNUNET_SCHEDULER_TaskIdentifier ret;
1075
1076 GNUNET_assert (wfd != NULL);
1077 ws = GNUNET_NETWORK_fdset_create ();
1078 GNUNET_NETWORK_fdset_handle_set (ws, wfd);
1079 ret = GNUNET_SCHEDULER_add_select (sched, run_on_shutdown, prio,
1080 prerequisite_task, delay,
1081 NULL, ws, main, cls);
1082 GNUNET_NETWORK_fdset_destroy (ws);
1083 return ret;
1084}
1085
1086
1087/* end of scheduler.c */ 1056/* end of scheduler.c */
diff --git a/src/util/server.c b/src/util/server.c
index 42fa8c46c..ff9c8c192 100644
--- a/src/util/server.c
+++ b/src/util/server.c
@@ -349,7 +349,6 @@ process_listen_socket (void *cls,
349 GNUNET_NETWORK_fdset_set (r, server->listen_socket); 349 GNUNET_NETWORK_fdset_set (r, server->listen_socket);
350 GNUNET_NETWORK_fdset_handle_set (r, shutpipe); 350 GNUNET_NETWORK_fdset_handle_set (r, shutpipe);
351 GNUNET_SCHEDULER_add_select (server->sched, 351 GNUNET_SCHEDULER_add_select (server->sched,
352 GNUNET_YES,
353 GNUNET_SCHEDULER_PRIORITY_HIGH, 352 GNUNET_SCHEDULER_PRIORITY_HIGH,
354 GNUNET_SCHEDULER_NO_TASK, 353 GNUNET_SCHEDULER_NO_TASK,
355 GNUNET_TIME_UNIT_FOREVER_REL, 354 GNUNET_TIME_UNIT_FOREVER_REL,
@@ -475,7 +474,7 @@ GNUNET_SERVER_create (struct GNUNET_SCHEDULER_Handle *sched,
475 GNUNET_NETWORK_fdset_handle_set (r, 474 GNUNET_NETWORK_fdset_handle_set (r,
476 GNUNET_DISK_pipe_handle (ret->shutpipe, 475 GNUNET_DISK_pipe_handle (ret->shutpipe,
477 GNUNET_DISK_PIPE_END_READ)); 476 GNUNET_DISK_PIPE_END_READ));
478 GNUNET_SCHEDULER_add_select (sched, GNUNET_YES, 477 GNUNET_SCHEDULER_add_select (sched,
479 GNUNET_SCHEDULER_PRIORITY_HIGH, 478 GNUNET_SCHEDULER_PRIORITY_HIGH,
480 GNUNET_SCHEDULER_NO_TASK, 479 GNUNET_SCHEDULER_NO_TASK,
481 GNUNET_TIME_UNIT_FOREVER_REL, r, NULL, 480 GNUNET_TIME_UNIT_FOREVER_REL, r, NULL,
@@ -1167,7 +1166,6 @@ GNUNET_SERVER_receive_done (struct GNUNET_SERVER_Client *client, int success)
1167 if (GNUNET_YES != client->shutdown_now) 1166 if (GNUNET_YES != client->shutdown_now)
1168 { 1167 {
1169 GNUNET_SCHEDULER_add_continuation (client->server->sched, 1168 GNUNET_SCHEDULER_add_continuation (client->server->sched,
1170 GNUNET_NO,
1171 &restart_processing, 1169 &restart_processing,
1172 client, 1170 client,
1173 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 1171 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
diff --git a/src/util/service.c b/src/util/service.c
index 0a33809be..173c0f566 100644
--- a/src/util/service.c
+++ b/src/util/service.c
@@ -1068,6 +1068,22 @@ write_pid_file (struct GNUNET_SERVICE_Context *sctx, pid_t pid)
1068 1068
1069 1069
1070/** 1070/**
1071 * Task run during shutdown.
1072 *
1073 * @param cls unused
1074 * @param tc unused
1075 */
1076static void
1077shutdown_task (void *cls,
1078 const struct GNUNET_SCHEDULER_TaskContext *tc)
1079{
1080 struct GNUNET_SERVER_Handle *server = cls;
1081
1082 GNUNET_SERVER_destroy (server);
1083}
1084
1085
1086/**
1071 * Initial task for the service. 1087 * Initial task for the service.
1072 */ 1088 */
1073static void 1089static void
@@ -1092,6 +1108,10 @@ service_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1092 sctx->ret = GNUNET_SYSERR; 1108 sctx->ret = GNUNET_SYSERR;
1093 return; 1109 return;
1094 } 1110 }
1111 GNUNET_SCHEDULER_add_delayed (tc->sched,
1112 GNUNET_TIME_UNIT_FOREVER_REL,
1113 &shutdown_task,
1114 sctx->server);
1095 sctx->my_handlers = GNUNET_malloc (sizeof (defhandlers)); 1115 sctx->my_handlers = GNUNET_malloc (sizeof (defhandlers));
1096 memcpy (sctx->my_handlers, defhandlers, sizeof (defhandlers)); 1116 memcpy (sctx->my_handlers, defhandlers, sizeof (defhandlers));
1097 i = 0; 1117 i = 0;
@@ -1249,6 +1269,7 @@ pid_file_delete (struct GNUNET_SERVICE_Context *sctx)
1249 GNUNET_free (pif); 1269 GNUNET_free (pif);
1250} 1270}
1251 1271
1272
1252/** 1273/**
1253 * Run a standard GNUnet service startup sequence (initialize loggers 1274 * Run a standard GNUnet service startup sequence (initialize loggers
1254 * and configuration, parse options). 1275 * and configuration, parse options).
@@ -1258,8 +1279,6 @@ pid_file_delete (struct GNUNET_SERVICE_Context *sctx)
1258 * @param serviceName our service name 1279 * @param serviceName our service name
1259 * @param task main task of the service 1280 * @param task main task of the service
1260 * @param task_cls closure for task 1281 * @param task_cls closure for task
1261 * @param term termination task of the service
1262 * @param term_cls closure for term
1263 * @return GNUNET_SYSERR on error, GNUNET_OK 1282 * @return GNUNET_SYSERR on error, GNUNET_OK
1264 * if we shutdown nicely 1283 * if we shutdown nicely
1265 */ 1284 */
@@ -1268,7 +1287,7 @@ GNUNET_SERVICE_run (int argc,
1268 char *const *argv, 1287 char *const *argv,
1269 const char *serviceName, 1288 const char *serviceName,
1270 GNUNET_SERVICE_Main task, 1289 GNUNET_SERVICE_Main task,
1271 void *task_cls, GNUNET_SERVICE_Term term, void *term_cls) 1290 void *task_cls)
1272{ 1291{
1273 char *cfg_fn; 1292 char *cfg_fn;
1274 char *loglev; 1293 char *loglev;
@@ -1347,12 +1366,8 @@ GNUNET_SERVICE_run (int argc,
1347 } 1366 }
1348 1367
1349 /* shutdown */ 1368 /* shutdown */
1350 if (term != NULL)
1351 term (term_cls, sctx.cfg);
1352 if ((do_daemonize == 1) && (sctx.server != NULL)) 1369 if ((do_daemonize == 1) && (sctx.server != NULL))
1353 pid_file_delete (&sctx); 1370 pid_file_delete (&sctx);
1354 if (sctx.server != NULL)
1355 GNUNET_SERVER_destroy (sctx.server);
1356 GNUNET_free_non_null (sctx.my_handlers); 1371 GNUNET_free_non_null (sctx.my_handlers);
1357 GNUNET_CONFIGURATION_destroy (cfg); 1372 GNUNET_CONFIGURATION_destroy (cfg);
1358 GNUNET_free_non_null (sctx.addr); 1373 GNUNET_free_non_null (sctx.addr);
@@ -1413,8 +1428,6 @@ GNUNET_SERVICE_start (const char *serviceName,
1413 while ((sctx->my_handlers[i].callback != NULL)) 1428 while ((sctx->my_handlers[i].callback != NULL))
1414 sctx->my_handlers[i++].callback_cls = sctx; 1429 sctx->my_handlers[i++].callback_cls = sctx;
1415 GNUNET_SERVER_add_handlers (sctx->server, sctx->my_handlers); 1430 GNUNET_SERVER_add_handlers (sctx->server, sctx->my_handlers);
1416
1417
1418 return sctx; 1431 return sctx;
1419} 1432}
1420 1433
diff --git a/src/util/test_connection.c b/src/util/test_connection.c
index 0f4c46b3b..07b5e843d 100644
--- a/src/util/test_connection.c
+++ b/src/util/test_connection.c
@@ -175,9 +175,6 @@ task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
175 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test prepares to accept\n"); 175 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test prepares to accept\n");
176#endif 176#endif
177 GNUNET_SCHEDULER_add_read_net (tc->sched, 177 GNUNET_SCHEDULER_add_read_net (tc->sched,
178 GNUNET_NO,
179 GNUNET_SCHEDULER_PRIORITY_HIGH,
180 GNUNET_SCHEDULER_NO_TASK,
181 GNUNET_TIME_UNIT_FOREVER_REL, 178 GNUNET_TIME_UNIT_FOREVER_REL,
182 ls, &run_accept, cls); 179 ls, &run_accept, cls);
183} 180}
diff --git a/src/util/test_connection_addressing.c b/src/util/test_connection_addressing.c
index 1b85dfac6..d6ac309f7 100644
--- a/src/util/test_connection_addressing.c
+++ b/src/util/test_connection_addressing.c
@@ -169,9 +169,6 @@ task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
169 &make_hello, NULL)); 169 &make_hello, NULL));
170 GNUNET_CONNECTION_destroy (csock); 170 GNUNET_CONNECTION_destroy (csock);
171 GNUNET_SCHEDULER_add_read_net (tc->sched, 171 GNUNET_SCHEDULER_add_read_net (tc->sched,
172 GNUNET_NO,
173 GNUNET_SCHEDULER_PRIORITY_HIGH,
174 GNUNET_SCHEDULER_NO_TASK,
175 GNUNET_TIME_UNIT_FOREVER_REL, 172 GNUNET_TIME_UNIT_FOREVER_REL,
176 ls, &run_accept, cls); 173 ls, &run_accept, cls);
177} 174}
diff --git a/src/util/test_connection_receive_cancel.c b/src/util/test_connection_receive_cancel.c
index 5856e27ed..b90191384 100644
--- a/src/util/test_connection_receive_cancel.c
+++ b/src/util/test_connection_receive_cancel.c
@@ -124,15 +124,9 @@ task_receive_cancel (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
124 "localhost", PORT, 1024); 124 "localhost", PORT, 1024);
125 GNUNET_assert (csock != NULL); 125 GNUNET_assert (csock != NULL);
126 GNUNET_SCHEDULER_add_read_net (tc->sched, 126 GNUNET_SCHEDULER_add_read_net (tc->sched,
127 GNUNET_NO,
128 GNUNET_SCHEDULER_PRIORITY_HIGH,
129 GNUNET_SCHEDULER_NO_TASK,
130 GNUNET_TIME_UNIT_FOREVER_REL, 127 GNUNET_TIME_UNIT_FOREVER_REL,
131 ls, &run_accept_cancel, cls); 128 ls, &run_accept_cancel, cls);
132 GNUNET_SCHEDULER_add_delayed (tc->sched, 129 GNUNET_SCHEDULER_add_delayed (tc->sched,
133 GNUNET_NO,
134 GNUNET_SCHEDULER_PRIORITY_KEEP,
135 GNUNET_SCHEDULER_NO_TASK,
136 GNUNET_TIME_UNIT_SECONDS, 130 GNUNET_TIME_UNIT_SECONDS,
137 &receive_cancel_task, cls); 131 &receive_cancel_task, cls);
138} 132}
diff --git a/src/util/test_crypto_hash.c b/src/util/test_crypto_hash.c
index 97ef4ec88..b650355c0 100644
--- a/src/util/test_crypto_hash.c
+++ b/src/util/test_crypto_hash.c
@@ -124,7 +124,7 @@ file_hasher (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
124{ 124{
125 GNUNET_CRYPTO_hash_file (tc->sched, 125 GNUNET_CRYPTO_hash_file (tc->sched,
126 GNUNET_SCHEDULER_PRIORITY_DEFAULT, 126 GNUNET_SCHEDULER_PRIORITY_DEFAULT,
127 GNUNET_NO, FILENAME, 1024, &finished_task, cls); 127 FILENAME, 1024, &finished_task, cls);
128} 128}
129 129
130 130
diff --git a/src/util/test_scheduler.c b/src/util/test_scheduler.c
index 98dce6f97..3021dce19 100644
--- a/src/util/test_scheduler.c
+++ b/src/util/test_scheduler.c
@@ -30,14 +30,6 @@
30#define VERBOSE GNUNET_NO 30#define VERBOSE GNUNET_NO
31 31
32static void 32static void
33task2 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
34{
35 int *ok = cls;
36 GNUNET_assert (2 == *ok);
37 (*ok) = 3;
38}
39
40static void
41task3 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 33task3 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
42{ 34{
43 int *ok = cls; 35 int *ok = cls;
@@ -48,6 +40,19 @@ task3 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
48 (*ok) = 4; 40 (*ok) = 4;
49} 41}
50 42
43
44static void
45task2 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
46{
47 int *ok = cls;
48 GNUNET_assert (2 == *ok);
49 (*ok) = 3;
50 /* t3 will go before t4: higher priority */
51 GNUNET_SCHEDULER_add_with_priority (tc->sched,
52 GNUNET_SCHEDULER_PRIORITY_UI,
53 &task3, cls);
54}
55
51static void 56static void
52task4 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 57task4 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
53{ 58{
@@ -96,14 +101,9 @@ taskRd (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
96 GNUNET_assert (GNUNET_NETWORK_fdset_handle_isset (tc->read_ready, fds[0])); 101 GNUNET_assert (GNUNET_NETWORK_fdset_handle_isset (tc->read_ready, fds[0]));
97 GNUNET_assert (1 == GNUNET_DISK_file_read (fds[0], &c, 1)); 102 GNUNET_assert (1 == GNUNET_DISK_file_read (fds[0], &c, 1));
98 (*ok) = 8; 103 (*ok) = 8;
99 GNUNET_SCHEDULER_add_after (tc->sched, 104 GNUNET_SCHEDULER_add_with_priority (tc->sched,
100 GNUNET_NO, 105 GNUNET_SCHEDULER_PRIORITY_IDLE,
101 GNUNET_SCHEDULER_PRIORITY_UI, 106 &taskLast, cls);
102 0, &taskNeverRun, NULL);
103 GNUNET_SCHEDULER_add_after (tc->sched,
104 GNUNET_YES,
105 GNUNET_SCHEDULER_PRIORITY_IDLE,
106 0, &taskLast, cls);
107 GNUNET_SCHEDULER_shutdown (tc->sched); 107 GNUNET_SCHEDULER_shutdown (tc->sched);
108} 108}
109 109
@@ -119,15 +119,9 @@ task5 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
119 fds[0] = GNUNET_DISK_pipe_handle (p, GNUNET_DISK_PIPE_END_READ); 119 fds[0] = GNUNET_DISK_pipe_handle (p, GNUNET_DISK_PIPE_END_READ);
120 fds[1] = GNUNET_DISK_pipe_handle (p, GNUNET_DISK_PIPE_END_WRITE); 120 fds[1] = GNUNET_DISK_pipe_handle (p, GNUNET_DISK_PIPE_END_WRITE);
121 GNUNET_SCHEDULER_add_read_file (tc->sched, 121 GNUNET_SCHEDULER_add_read_file (tc->sched,
122 GNUNET_NO,
123 GNUNET_SCHEDULER_PRIORITY_DEFAULT,
124 GNUNET_SCHEDULER_NO_TASK,
125 GNUNET_TIME_UNIT_FOREVER_REL, 122 GNUNET_TIME_UNIT_FOREVER_REL,
126 fds[0], &taskRd, cls); 123 fds[0], &taskRd, cls);
127 GNUNET_SCHEDULER_add_write_file (tc->sched, 124 GNUNET_SCHEDULER_add_write_file (tc->sched,
128 GNUNET_NO,
129 GNUNET_SCHEDULER_PRIORITY_DEFAULT,
130 GNUNET_SCHEDULER_NO_TASK,
131 GNUNET_TIME_UNIT_FOREVER_REL, 125 GNUNET_TIME_UNIT_FOREVER_REL,
132 fds[1], &taskWrt, cls); 126 fds[1], &taskWrt, cls);
133} 127}
@@ -144,24 +138,13 @@ task1 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
144 (*ok) = 2; 138 (*ok) = 2;
145 /* t2 will go first -- prereq for all */ 139 /* t2 will go first -- prereq for all */
146 t2 = GNUNET_SCHEDULER_add_after (tc->sched, 140 t2 = GNUNET_SCHEDULER_add_after (tc->sched,
147 GNUNET_NO,
148 GNUNET_SCHEDULER_PRIORITY_IDLE,
149 GNUNET_SCHEDULER_NO_TASK, &task2, cls); 141 GNUNET_SCHEDULER_NO_TASK, &task2, cls);
150 /* t3 will go before t4: higher priority */ 142 /* t4 will go after t2 ('add after') and after t3 (priority) */
151 t4 = GNUNET_SCHEDULER_add_after (tc->sched, 143 t4 = GNUNET_SCHEDULER_add_after (tc->sched,
152 GNUNET_NO,
153 GNUNET_SCHEDULER_PRIORITY_IDLE,
154 t2, &task4, cls); 144 t2, &task4, cls);
155 GNUNET_SCHEDULER_add_delayed (tc->sched, 145 /* t5 will go last (after p4) */
156 GNUNET_NO,
157 GNUNET_SCHEDULER_PRIORITY_DEFAULT,
158 t2,
159 GNUNET_TIME_relative_get_zero (),
160 &task3, cls);
161 /* t4 will go first: lower prio, but prereq! */
162 GNUNET_SCHEDULER_add_after (tc->sched, 146 GNUNET_SCHEDULER_add_after (tc->sched,
163 GNUNET_NO, 147 t4, &task5, cls);
164 GNUNET_SCHEDULER_PRIORITY_UI, t4, &task5, cls);
165} 148}
166 149
167 150
@@ -182,20 +165,47 @@ check ()
182 165
183 166
184static void 167static void
168taskShutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
169{
170 int *ok = cls;
171 GNUNET_assert (1 == *ok);
172 *ok = 8;
173 GNUNET_SCHEDULER_add_delayed (tc->sched,
174 GNUNET_TIME_UNIT_FOREVER_REL,
175 &taskLast, cls);
176 GNUNET_SCHEDULER_shutdown (tc->sched);
177}
178
179
180/**
181 * Main method, starts scheduler with task1,
182 * checks that "ok" is correct at the end.
183 */
184static int
185checkShutdown ()
186{
187 int ok;
188
189 ok = 1;
190 GNUNET_SCHEDULER_run (&taskShutdown, &ok);
191 return ok;
192}
193
194
195static void
185taskSig (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 196taskSig (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
186{ 197{
187 int *ok = cls; 198 int *ok = cls;
188 GNUNET_assert (1 == *ok); 199 GNUNET_assert (1 == *ok);
189 *ok = 8; 200 *ok = 8;
190 GNUNET_SCHEDULER_add_after (tc->sched, 201 GNUNET_SCHEDULER_add_delayed (tc->sched,
191 GNUNET_NO, 202 GNUNET_TIME_UNIT_FOREVER_REL,
192 GNUNET_SCHEDULER_PRIORITY_UI, 203 &taskLast, cls);
193 0, &taskNeverRun, NULL); 204#ifndef MINGW
194 GNUNET_SCHEDULER_add_after (tc->sched,
195 GNUNET_YES,
196 GNUNET_SCHEDULER_PRIORITY_UI,
197 0, &taskLast, cls);
198 GNUNET_break (0 == PLIBC_KILL (getpid (), SIGTERM)); 205 GNUNET_break (0 == PLIBC_KILL (getpid (), SIGTERM));
206#else
207 GNUNET_SCHEDULER_shutdown (tc->sched);
208#endif
199} 209}
200 210
201 211
@@ -214,8 +224,6 @@ checkSignal ()
214} 224}
215 225
216 226
217
218
219static void 227static void
220taskCancel (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 228taskCancel (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
221{ 229{
@@ -225,9 +233,7 @@ taskCancel (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
225 *ok = 0; 233 *ok = 0;
226 GNUNET_SCHEDULER_cancel (tc->sched, 234 GNUNET_SCHEDULER_cancel (tc->sched,
227 GNUNET_SCHEDULER_add_after (tc->sched, 235 GNUNET_SCHEDULER_add_after (tc->sched,
228 GNUNET_NO, 236 GNUNET_SCHEDULER_NO_TASK,
229 GNUNET_SCHEDULER_PRIORITY_UI,
230 0,
231 &taskNeverRun, NULL)); 237 &taskNeverRun, NULL));
232} 238}
233 239
@@ -256,6 +262,7 @@ main (int argc, char *argv[])
256 GNUNET_log_setup ("test_scheduler", "WARNING", NULL); 262 GNUNET_log_setup ("test_scheduler", "WARNING", NULL);
257 ret += check (); 263 ret += check ();
258 ret += checkSignal (); 264 ret += checkSignal ();
265 ret += checkShutdown ();
259 ret += checkCancel (); 266 ret += checkCancel ();
260 GNUNET_DISK_pipe_close (p); 267 GNUNET_DISK_pipe_close (p);
261 268
diff --git a/src/util/test_scheduler_delay.c b/src/util/test_scheduler_delay.c
index f5477fd4c..d1d61c3e4 100644
--- a/src/util/test_scheduler_delay.c
+++ b/src/util/test_scheduler_delay.c
@@ -66,9 +66,6 @@ test_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
66 return; 66 return;
67 } 67 }
68 GNUNET_SCHEDULER_add_delayed (tc->sched, 68 GNUNET_SCHEDULER_add_delayed (tc->sched,
69 GNUNET_NO,
70 GNUNET_SCHEDULER_PRIORITY_DEFAULT,
71 GNUNET_SCHEDULER_NO_TASK,
72 GNUNET_TIME_relative_multiply 69 GNUNET_TIME_relative_multiply
73 (GNUNET_TIME_UNIT_MILLISECONDS, i), 70 (GNUNET_TIME_UNIT_MILLISECONDS, i),
74 &test_task, NULL); 71 &test_task, NULL);
diff --git a/src/util/test_server.c b/src/util/test_server.c
index ae5609de0..95206c0f1 100644
--- a/src/util/test_server.c
+++ b/src/util/test_server.c
@@ -100,9 +100,6 @@ my_receive (void *cls,
100 stctx->cb = receiver; 100 stctx->cb = receiver;
101 stctx->cb_cls = receiver_cls; 101 stctx->cb_cls = receiver_cls;
102 ret = GNUNET_SCHEDULER_add_delayed (sched, 102 ret = GNUNET_SCHEDULER_add_delayed (sched,
103 GNUNET_NO,
104 GNUNET_SCHEDULER_PRIORITY_KEEP,
105 GNUNET_SCHEDULER_NO_TASK,
106 timeout, &signal_timeout, stctx); 103 timeout, &signal_timeout, stctx);
107 break; 104 break;
108 default: 105 default:
diff --git a/src/util/test_server_disconnect.c b/src/util/test_server_disconnect.c
index c5ce5e736..30fc34b08 100644
--- a/src/util/test_server_disconnect.c
+++ b/src/util/test_server_disconnect.c
@@ -95,9 +95,6 @@ recv_cb (void *cls,
95 case 2: 95 case 2:
96 ok++; 96 ok++;
97 GNUNET_SCHEDULER_add_delayed (sched, 97 GNUNET_SCHEDULER_add_delayed (sched,
98 GNUNET_YES,
99 GNUNET_SCHEDULER_PRIORITY_KEEP,
100 GNUNET_SCHEDULER_NO_TASK,
101 GNUNET_TIME_relative_multiply 98 GNUNET_TIME_relative_multiply
102 (GNUNET_TIME_UNIT_MILLISECONDS, 50), 99 (GNUNET_TIME_UNIT_MILLISECONDS, 50),
103 &send_done, argclient); 100 &send_done, argclient);
@@ -105,9 +102,6 @@ recv_cb (void *cls,
105 case 4: 102 case 4:
106 ok++; 103 ok++;
107 GNUNET_SCHEDULER_add_delayed (sched, 104 GNUNET_SCHEDULER_add_delayed (sched,
108 GNUNET_YES,
109 GNUNET_SCHEDULER_PRIORITY_KEEP,
110 GNUNET_SCHEDULER_NO_TASK,
111 GNUNET_TIME_relative_multiply 105 GNUNET_TIME_relative_multiply
112 (GNUNET_TIME_UNIT_MILLISECONDS, 50), 106 (GNUNET_TIME_UNIT_MILLISECONDS, 50),
113 &server_disconnect, argclient); 107 &server_disconnect, argclient);
diff --git a/src/util/test_server_with_client.c b/src/util/test_server_with_client.c
index 508c505b1..860ed3837 100644
--- a/src/util/test_server_with_client.c
+++ b/src/util/test_server_with_client.c
@@ -87,9 +87,6 @@ recv_cb (void *cls,
87 case 2: 87 case 2:
88 ok++; 88 ok++;
89 GNUNET_SCHEDULER_add_delayed (sched, 89 GNUNET_SCHEDULER_add_delayed (sched,
90 GNUNET_YES,
91 GNUNET_SCHEDULER_PRIORITY_KEEP,
92 GNUNET_SCHEDULER_NO_TASK,
93 GNUNET_TIME_relative_multiply 90 GNUNET_TIME_relative_multiply
94 (GNUNET_TIME_UNIT_MILLISECONDS, 50), 91 (GNUNET_TIME_UNIT_MILLISECONDS, 50),
95 &send_done, argclient); 92 &send_done, argclient);
diff --git a/src/util/test_service.c b/src/util/test_service.c
index 93cafb4d2..fa35da6e9 100644
--- a/src/util/test_service.c
+++ b/src/util/test_service.c
@@ -30,6 +30,7 @@
30#include "gnunet_scheduler_lib.h" 30#include "gnunet_scheduler_lib.h"
31#include "gnunet_time_lib.h" 31#include "gnunet_time_lib.h"
32 32
33
33#define VERBOSE GNUNET_NO 34#define VERBOSE GNUNET_NO
34 35
35#define PORT 12435 36#define PORT 12435
@@ -40,6 +41,9 @@ static struct GNUNET_SCHEDULER_Handle *sched;
40 41
41static struct GNUNET_SERVICE_Context *sctx; 42static struct GNUNET_SERVICE_Context *sctx;
42 43
44static int ok = 1;
45
46
43static void 47static void
44end_it (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 48end_it (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
45{ 49{
@@ -47,8 +51,11 @@ end_it (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
47 51
48 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down service\n"); 52 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down service\n");
49 GNUNET_CLIENT_service_shutdown (client); 53 GNUNET_CLIENT_service_shutdown (client);
50 if (sctx != NULL) 54 if (sctx != NULL)
51 GNUNET_SERVICE_stop (sctx); 55 GNUNET_SERVICE_stop (sctx);
56 else
57 GNUNET_SCHEDULER_shutdown (sched);
58 ok = 0;
52} 59}
53 60
54 61
@@ -63,7 +70,6 @@ build_msg (void *cls, size_t size, void *buf)
63 msg->type = htons (MY_TYPE); 70 msg->type = htons (MY_TYPE);
64 msg->size = htons (sizeof (struct GNUNET_MessageHeader)); 71 msg->size = htons (sizeof (struct GNUNET_MessageHeader));
65 GNUNET_SCHEDULER_add_continuation (sched, 72 GNUNET_SCHEDULER_add_continuation (sched,
66 GNUNET_YES,
67 &end_it, 73 &end_it,
68 client, 74 client,
69 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 75 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
@@ -103,6 +109,9 @@ static struct GNUNET_SERVER_MessageHandler myhandlers[] = {
103 {NULL, NULL, 0, 0} 109 {NULL, NULL, 0, 0}
104}; 110};
105 111
112
113
114
106static void 115static void
107runner (void *cls, 116runner (void *cls,
108 struct GNUNET_SCHEDULER_Handle *sched, 117 struct GNUNET_SCHEDULER_Handle *sched,
@@ -117,12 +126,6 @@ runner (void *cls,
117 (void *) cfg); 126 (void *) cfg);
118} 127}
119 128
120static void
121term (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
122{
123 int *ok = cls;
124 *ok = 0;
125}
126 129
127/** 130/**
128 * Main method, starts scheduler with task1, 131 * Main method, starts scheduler with task1,
@@ -131,7 +134,7 @@ term (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
131static int 134static int
132check () 135check ()
133{ 136{
134 int ok = 1; 137 ok = 1;
135 char *const argv[] = { 138 char *const argv[] = {
136 "test_service", 139 "test_service",
137 "-c", 140 "-c",
@@ -149,12 +152,12 @@ check ()
149 GNUNET_SERVICE_run (5, 152 GNUNET_SERVICE_run (5,
150 argv, 153 argv,
151 "test_service", 154 "test_service",
152 &runner, &ok, &term, &ok)); 155 &runner, &ok));
153 GNUNET_assert (0 == ok); 156 GNUNET_assert (0 == ok);
154 return ok; 157 return ok;
155} 158}
156 159
157static void 160static void
158ready6 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 161ready6 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
159{ 162{
160 const struct GNUNET_CONFIGURATION_Handle *cfg = cls; 163 const struct GNUNET_CONFIGURATION_Handle *cfg = cls;
@@ -193,7 +196,6 @@ runner6 (void *cls,
193static int 196static int
194check6 () 197check6 ()
195{ 198{
196 int ok = 1;
197 char *const argv[] = { 199 char *const argv[] = {
198 "test_service6", 200 "test_service6",
199 "-c", 201 "-c",
@@ -211,7 +213,7 @@ check6 ()
211 GNUNET_SERVICE_run (5, 213 GNUNET_SERVICE_run (5,
212 argv, 214 argv,
213 "test_service6", 215 "test_service6",
214 &runner6, &ok, &term, &ok)); 216 &runner6, &ok));
215 GNUNET_assert (0 == ok); 217 GNUNET_assert (0 == ok);
216 return ok; 218 return ok;
217} 219}
@@ -224,7 +226,7 @@ check6 ()
224static int 226static int
225check6d () 227check6d ()
226{ 228{
227 int ok = 1; 229 ok = 1;
228 char *const argv[] = { 230 char *const argv[] = {
229 "test_service6", 231 "test_service6",
230 "-c", 232 "-c",
@@ -243,7 +245,7 @@ check6d ()
243 GNUNET_SERVICE_run (6, 245 GNUNET_SERVICE_run (6,
244 argv, 246 argv,
245 "test_service6", 247 "test_service6",
246 &runner6, &ok, &term, &ok)); 248 &runner6, &ok));
247 GNUNET_break (0 == ok); 249 GNUNET_break (0 == ok);
248 return ok; 250 return ok;
249} 251}