We are not tracking them in Mantis yet since there are too many and no
sane end-user should care about this codebase yet anyway.
+* TESTING:
+ - connection.c:553 fails when "make check" is run!
+ (check if this could be memory corruption).
+
* UTIL:
- container_bloomfilter: improve efficiency (see FIXME)
break;
}
GNUNET_SCHEDULER_add_continuation (sched,
- GNUNET_NO,
&cps_loop,
NULL,
GNUNET_SCHEDULER_REASON_PREREQ_DONE);
else
fprintf (stdout, _("Service `%s' is not running.\n"), service);
GNUNET_SCHEDULER_add_continuation (sched,
- GNUNET_NO,
&cps_loop,
NULL,
GNUNET_SCHEDULER_REASON_PREREQ_DONE);
return;
}
GNUNET_SCHEDULER_add_continuation (sched,
- GNUNET_NO,
&cps_loop,
NULL,
GNUNET_SCHEDULER_REASON_PREREQ_DONE);
pos->kill_continuation_cls = client;
GNUNET_SERVER_client_keep (client);
GNUNET_SCHEDULER_add_delayed (sched,
- GNUNET_YES,
- GNUNET_SCHEDULER_PRIORITY_IDLE,
- GNUNET_SCHEDULER_NO_TASK,
MAINT_FAST_FREQUENCY, &maint, NULL);
}
else
}
if (cls == NULL)
GNUNET_SCHEDULER_add_delayed (tc->sched,
- GNUNET_YES,
- GNUNET_SCHEDULER_PRIORITY_IDLE,
- GNUNET_SCHEDULER_NO_TASK,
MAINT_FREQUENCY, &maint, NULL);
/* check for services that died (WAITPID) */
GNUNET_SERVER_add_handlers (server, handlers);
/* manage services */
- GNUNET_SCHEDULER_add_delayed (sched,
- GNUNET_YES,
- GNUNET_SCHEDULER_PRIORITY_IDLE,
- GNUNET_SCHEDULER_NO_TASK,
- MAINT_FREQUENCY, &maint, NULL);
+ GNUNET_SCHEDULER_add_with_priority (sched,
+ GNUNET_SCHEDULER_PRIORITY_IDLE,
+ &maint, NULL);
}
{
return (GNUNET_OK ==
GNUNET_SERVICE_run (argc,
- argv, "arm", &run, NULL, NULL, NULL)) ? 0 : 1;
+ argv, "arm", &run, NULL)) ? 0 : 1;
}
/* end of gnunet-service-arm.c */
}
/* create new timeout task (in case core takes too long to respond!) */
th->timeout_task = GNUNET_SCHEDULER_add_delayed (h->sched,
- GNUNET_NO,
- GNUNET_SCHEDULER_PRIORITY_KEEP,
- GNUNET_SCHEDULER_NO_TASK,
GNUNET_TIME_absolute_get_remaining
(th->timeout),
&timeout_request, th);
h->startup_timeout =
GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_MINUTES);
h->reconnect_task =
- GNUNET_SCHEDULER_add_delayed (h->sched, GNUNET_NO,
- GNUNET_SCHEDULER_PRIORITY_IDLE,
- GNUNET_SCHEDULER_NO_TASK,
+ GNUNET_SCHEDULER_add_delayed (h->sched,
delay, &reconnect_task, h);
return 0;
}
th->info_cls = info_cls;
th->timeout = GNUNET_TIME_relative_to_absolute (timeout);
th->timeout_task = GNUNET_SCHEDULER_add_delayed (handle->sched,
- GNUNET_NO,
- GNUNET_SCHEDULER_PRIORITY_KEEP,
- GNUNET_SCHEDULER_NO_TASK,
timeout,
&timeout_request, th);
th->msize = sizeof (struct RequestConfigureMessage);
th->peer = *target;
th->timeout = GNUNET_TIME_relative_to_absolute (maxdelay);
th->timeout_task = GNUNET_SCHEDULER_add_delayed (handle->sched,
- GNUNET_NO,
- GNUNET_SCHEDULER_PRIORITY_KEEP,
- GNUNET_SCHEDULER_NO_TASK,
maxdelay,
&timeout_request, th);
th->priority = priority;
/* no messages selected for sending, try again later... */
n->retry_plaintext_task =
GNUNET_SCHEDULER_add_delayed (sched,
- GNUNET_NO,
- GNUNET_SCHEDULER_PRIORITY_IDLE,
- GNUNET_SCHEDULER_NO_TASK,
retry_time,
&retry_plaintext_processing, n);
return;
if (n->status != PEER_STATE_KEY_CONFIRMED)
n->retry_set_key_task
= GNUNET_SCHEDULER_add_delayed (sched,
- GNUNET_NO,
- GNUNET_SCHEDULER_PRIORITY_KEEP,
- GNUNET_SCHEDULER_NO_TASK,
n->set_key_retry_frequency,
&set_key_retry_task, n);
}
GNUNET_SCHEDULER_NO_TASK);
n->quota_update_task
= GNUNET_SCHEDULER_add_delayed (sched,
- GNUNET_NO,
- GNUNET_SCHEDULER_PRIORITY_IDLE,
- GNUNET_SCHEDULER_NO_TASK,
QUOTA_UPDATE_FREQUENCY,
&neighbour_quota_update,
n);
}
while (NULL != (c = clients))
handle_client_disconnect (NULL, c->client_handle);
+ if (my_private_key != NULL)
+ GNUNET_CRYPTO_rsa_key_free (my_private_key);
}
&handle_transport_notify_disconnect);
GNUNET_assert (NULL != transport);
GNUNET_SCHEDULER_add_delayed (sched,
- GNUNET_YES,
- GNUNET_SCHEDULER_PRIORITY_IDLE,
- GNUNET_SCHEDULER_NO_TASK,
GNUNET_TIME_UNIT_FOREVER_REL,
&cleaning_task, NULL);
/* process client requests */
}
-/**
- * Function called during shutdown. Clean up our state.
- */
-static void
-cleanup (void *cls,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
-{
- if (my_private_key != NULL)
- GNUNET_CRYPTO_rsa_key_free (my_private_key);
-}
-
/**
* The main function for the transport service.
return (GNUNET_OK ==
GNUNET_SERVICE_run (argc,
argv,
- "core", &run, NULL, &cleanup, NULL)) ? 0 : 1;
+ "core", &run, NULL)) ? 0 : 1;
}
/* end of gnunet-service-core.c */
OKPP;
GNUNET_SCHEDULER_cancel (sched, err_task);
GNUNET_SCHEDULER_add_delayed (sched,
- GNUNET_NO,
- GNUNET_SCHEDULER_PRIORITY_KEEP,
- GNUNET_SCHEDULER_NO_TASK,
GNUNET_TIME_UNIT_ZERO, &terminate_task, NULL);
return GNUNET_OK;
}
m->size = htons (sizeof (struct GNUNET_MessageHeader));
err_task =
GNUNET_SCHEDULER_add_delayed (sched,
- GNUNET_NO,
- GNUNET_SCHEDULER_PRIORITY_KEEP,
- GNUNET_SCHEDULER_NO_TASK,
GNUNET_TIME_UNIT_MINUTES, &terminate_task_error, NULL);
return sizeof (struct GNUNET_MessageHeader);
"-L", "DEBUG",
#endif
"-c", cfgname, NULL);
- sleep (1); /* allow ARM to start */
#endif
GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
GNUNET_ARM_start_services (p->cfg, sched, "core", NULL);
"-L", "DEBUG",
#endif
"-c", cfgname, NULL);
- sleep (1); /* allow ARM to start */
#endif
GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
GNUNET_ARM_start_services (p->cfg, sched, "core", NULL);
{
expired_kill_task
= GNUNET_SCHEDULER_add_delayed (sched,
- GNUNET_NO,
- GNUNET_SCHEDULER_PRIORITY_IDLE,
- GNUNET_SCHEDULER_NO_TASK,
MAX_EXPIRE_DELAY,
&delete_expired,
NULL);
GNUNET_CONTAINER_bloomfilter_free (filter);
filter = NULL;
}
- // GNUNET_ARM_stop_services (cfg, tc->sched, "statistics", NULL);
+ GNUNET_ARM_stop_services (cfg, tc->sched, "statistics", NULL);
}
_("Failed to initialize bloomfilter.\n"));
return;
}
-// GNUNET_ARM_start_services (cfg, sched, "statistics", NULL);
+ GNUNET_ARM_start_services (cfg, sched, "statistics", NULL);
plugin = load_plugin ();
if (NULL == plugin)
{
GNUNET_CONTAINER_bloomfilter_free (filter);
filter = NULL;
-// GNUNET_ARM_stop_services (cfg, sched, "statistics", NULL);
+ GNUNET_ARM_stop_services (cfg, sched, "statistics", NULL);
return;
}
GNUNET_SERVER_disconnect_notify (server, &cleanup_reservations, NULL);
GNUNET_SERVER_add_handlers (server, handlers);
expired_kill_task
- = GNUNET_SCHEDULER_add_delayed (sched,
- GNUNET_NO,
- GNUNET_SCHEDULER_PRIORITY_IDLE,
- GNUNET_SCHEDULER_NO_TASK,
- GNUNET_TIME_UNIT_ZERO,
- &delete_expired, NULL);
+ = GNUNET_SCHEDULER_add_with_priority (sched,
+ GNUNET_SCHEDULER_PRIORITY_IDLE,
+ &delete_expired, NULL);
GNUNET_SCHEDULER_add_delayed (sched,
- GNUNET_YES,
- GNUNET_SCHEDULER_PRIORITY_IDLE,
- GNUNET_SCHEDULER_NO_TASK,
GNUNET_TIME_UNIT_FOREVER_REL,
&cleaning_task, NULL);
ret = (GNUNET_OK ==
GNUNET_SERVICE_run (argc,
argv,
- "datastore", &run, NULL, NULL, NULL)) ? 0 : 1;
+ "datastore", &run, NULL)) ? 0 : 1;
return ret;
}
crc->phase = RP_CUT;
}
GNUNET_SCHEDULER_add_continuation (crc->sched,
- GNUNET_NO,
&run_continuation,
crc,
GNUNET_SCHEDULER_REASON_PREREQ_DONE);
#endif
GNUNET_assert (GNUNET_OK == success);
GNUNET_SCHEDULER_add_continuation (crc->sched,
- GNUNET_NO,
&run_continuation,
crc,
GNUNET_SCHEDULER_REASON_PREREQ_DONE);
{
crc->phase = RP_REPORT;
GNUNET_SCHEDULER_add_continuation (crc->sched,
- GNUNET_NO,
&run_continuation,
crc,
GNUNET_SCHEDULER_REASON_PREREQ_DONE);
return;
}
- GNUNET_SCHEDULER_add_after (crc->sched,
- GNUNET_NO,
- GNUNET_SCHEDULER_PRIORITY_HIGH,
- GNUNET_SCHEDULER_NO_TASK,
- &do_delete,
- crc);
+ GNUNET_SCHEDULER_add_with_priority (crc->sched,
+ GNUNET_SCHEDULER_PRIORITY_HIGH,
+ &do_delete,
+ crc);
return;
}
stored_ops++;
crc->phase = RP_PUT;
crc->j = 0;
GNUNET_SCHEDULER_add_continuation (crc->sched,
- GNUNET_NO,
&run_continuation,
crc,
GNUNET_SCHEDULER_REASON_PREREQ_DONE);
crc->cfg = cfg;
crc->phase = RP_PUT;
GNUNET_SCHEDULER_add_continuation (crc->sched,
- GNUNET_NO,
&run_continuation,
crc,
GNUNET_SCHEDULER_REASON_PREREQ_DONE);
"-L", "DEBUG",
#endif
"-c", "test_datastore_api_data.conf", NULL);
- sleep (1);
GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
argv, "perf-datastore-api", "nohelp",
options, &run, NULL);
crc->phase = RP_PUT;
}
GNUNET_SCHEDULER_add_after (crc->sched,
- GNUNET_NO,
- GNUNET_SCHEDULER_PRIORITY_KEEP,
GNUNET_SCHEDULER_NO_TASK,
&test, crc);
return GNUNET_OK;
crc->i++;
crc->phase = RP_LP_GET;
GNUNET_SCHEDULER_add_after (crc->sched,
- GNUNET_NO,
- GNUNET_SCHEDULER_PRIORITY_KEEP,
GNUNET_SCHEDULER_NO_TASK,
&test, crc);
break;
break;
case RP_DONE:
crc->api->drop (crc->api->cls);
- GNUNET_SCHEDULER_add_delayed (crc->sched,
- GNUNET_YES,
+ GNUNET_SCHEDULER_add_with_priority (crc->sched,
GNUNET_SCHEDULER_PRIORITY_IDLE,
- GNUNET_SCHEDULER_NO_TASK,
- GNUNET_TIME_UNIT_ZERO,
&cleaning_task, crc);
break;
}
crc->cfg = c;
crc->phase = RP_PUT;
GNUNET_SCHEDULER_add_after (s,
- GNUNET_YES,
- GNUNET_SCHEDULER_PRIORITY_KEEP,
GNUNET_SCHEDULER_NO_TASK,
&test, crc);
}
if (GNUNET_YES == end_it)
nc->end_it = GNUNET_YES;
GNUNET_SCHEDULER_add_continuation (nc->plugin->env->sched,
- GNUNET_NO,
&sqlite_next_request_cont,
nc,
GNUNET_SCHEDULER_REASON_PREREQ_DONE);
GNUNET_free_non_null (crc->data);
crc->data = NULL;
GNUNET_SCHEDULER_add_continuation (crc->sched,
- GNUNET_NO,
&run_continuation,
crc,
GNUNET_SCHEDULER_REASON_PREREQ_DONE);
GNUNET_assert (0 < success);
crc->rid = success;
GNUNET_SCHEDULER_add_continuation (crc->sched,
- GNUNET_NO,
&run_continuation,
crc,
GNUNET_SCHEDULER_REASON_PREREQ_DONE);
crc->i = ITERATIONS;
}
GNUNET_SCHEDULER_add_continuation (crc->sched,
- GNUNET_NO,
&run_continuation,
crc,
GNUNET_SCHEDULER_REASON_PREREQ_DONE);
{
crc->phase = RP_DO_DEL;
GNUNET_SCHEDULER_add_continuation (crc->sched,
- GNUNET_NO,
&run_continuation,
crc,
GNUNET_SCHEDULER_REASON_PREREQ_DONE);
crc->phase = RP_RESERVE;
}
GNUNET_SCHEDULER_add_continuation (crc->sched,
- GNUNET_NO,
&run_continuation,
crc,
GNUNET_SCHEDULER_REASON_PREREQ_DONE);
GNUNET_assert (crc->phase == RP_GET_MULTIPLE_DONE);
crc->phase = RP_UPDATE;
GNUNET_SCHEDULER_add_continuation (crc->sched,
- GNUNET_NO,
&run_continuation,
crc,
GNUNET_SCHEDULER_REASON_PREREQ_DONE);
GNUNET_assert (crc->phase == RP_UPDATE_DONE);
crc->phase = RP_DONE;
GNUNET_SCHEDULER_add_continuation (crc->sched,
- GNUNET_NO,
&run_continuation,
crc,
GNUNET_SCHEDULER_REASON_PREREQ_DONE);
now = GNUNET_TIME_absolute_get ();
datastore = GNUNET_DATASTORE_connect (cfg, sched);
GNUNET_SCHEDULER_add_continuation (crc->sched,
- GNUNET_NO,
&run_continuation,
crc,
GNUNET_SCHEDULER_REASON_PREREQ_DONE);
"-L", "DEBUG",
#endif
"-c", "test_datastore_api_data.conf", NULL);
- sleep (1);
GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
argv, "test-datastore-api", "nohelp",
options, &run, NULL);
GNUNET_free_non_null (crc->data);
crc->data = NULL;
GNUNET_SCHEDULER_add_continuation (crc->sched,
- GNUNET_NO,
&run_continuation,
crc,
GNUNET_SCHEDULER_REASON_PREREQ_DONE);
if (0 == crc->i)
crc->phase = RP_DONE;
GNUNET_SCHEDULER_add_continuation (crc->sched,
- GNUNET_NO,
&run_continuation,
crc,
GNUNET_SCHEDULER_REASON_PREREQ_DONE);
if (0 == --crc->i)
crc->phase = RP_DONE;
GNUNET_SCHEDULER_add_continuation (crc->sched,
- GNUNET_NO,
&run_continuation,
crc,
GNUNET_SCHEDULER_REASON_PREREQ_DONE);
now = GNUNET_TIME_absolute_get ();
datastore = GNUNET_DATASTORE_connect (cfg, sched);
GNUNET_SCHEDULER_add_continuation (crc->sched,
- GNUNET_NO,
&run_continuation,
crc,
GNUNET_SCHEDULER_REASON_PREREQ_DONE);
"-L", "DEBUG",
#endif
"-c", "test_datastore_api_data.conf", NULL);
- sleep (1);
GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
argv, "test-datastore-api", "nohelp",
options, &run, NULL);
}
dc->task
= GNUNET_SCHEDULER_add_delayed (dc->h->sched,
- GNUNET_NO,
- GNUNET_SCHEDULER_PRIORITY_IDLE,
- GNUNET_SCHEDULER_NO_TASK,
GNUNET_TIME_UNIT_SECONDS,
&do_reconnect,
dc);
"GET_INDEXED",
"fs");
GNUNET_SCHEDULER_add_continuation (gic->h->sched,
- GNUNET_NO,
gic->cont,
gic->cont_cls,
GNUNET_SCHEDULER_REASON_TIMEOUT);
{
/* normal end-of-list */
GNUNET_SCHEDULER_add_continuation (gic->h->sched,
- GNUNET_NO,
gic->cont,
gic->cont_cls,
GNUNET_SCHEDULER_REASON_PREREQ_DONE);
"GET_INDEXED",
"fs");
GNUNET_SCHEDULER_add_continuation (gic->h->sched,
- GNUNET_NO,
gic->cont,
gic->cont_cls,
GNUNET_SCHEDULER_REASON_TIMEOUT);
&iim->file_id))
{
GNUNET_SCHEDULER_add_continuation (gic->h->sched,
- GNUNET_NO,
gic->cont,
gic->cont_cls,
GNUNET_SCHEDULER_REASON_PREREQ_DONE);
_("Failed to not connect to `%s' service.\n"),
"fs");
GNUNET_SCHEDULER_add_continuation (h->sched,
- GNUNET_NO,
cont,
cont_cls,
GNUNET_SCHEDULER_REASON_TIMEOUT);
GNUNET_FS_file_information_sync (pcc->p);
if (NULL != pcc->cont)
pcc->sc->upload_task
- = GNUNET_SCHEDULER_add_delayed (pcc->sc->h->sched,
- GNUNET_NO,
- GNUNET_SCHEDULER_PRIORITY_BACKGROUND,
- GNUNET_SCHEDULER_NO_TASK,
- GNUNET_TIME_UNIT_ZERO,
- pcc->cont,
- pcc->cont_cls);
+ = GNUNET_SCHEDULER_add_with_priority (pcc->sc->h->sched,
+ GNUNET_SCHEDULER_PRIORITY_BACKGROUND,
+ pcc->cont,
+ pcc->cont_cls);
GNUNET_free (pcc);
}
{
signal_publish_error (p, sc, emsg);
sc->upload_task
- = GNUNET_SCHEDULER_add_delayed (sc->h->sched,
- GNUNET_NO,
- GNUNET_SCHEDULER_PRIORITY_BACKGROUND,
- GNUNET_SCHEDULER_NO_TASK,
- GNUNET_TIME_UNIT_ZERO,
- &do_upload,
- sc);
+ = GNUNET_SCHEDULER_add_with_priority (sc->h->sched,
+ GNUNET_SCHEDULER_PRIORITY_BACKGROUND,
+ &do_upload,
+ sc);
return;
}
GNUNET_FS_file_information_sync (p);
else
sc->fi_pos = p->dir;
sc->upload_task
- = GNUNET_SCHEDULER_add_delayed (sc->h->sched,
- GNUNET_NO,
- GNUNET_SCHEDULER_PRIORITY_BACKGROUND,
- GNUNET_SCHEDULER_NO_TASK,
- GNUNET_TIME_UNIT_ZERO,
- &do_upload,
- sc);
+ = GNUNET_SCHEDULER_add_with_priority (sc->h->sched,
+ GNUNET_SCHEDULER_PRIORITY_BACKGROUND,
+ &do_upload,
+ sc);
}
}
/* continue with main */
sc->upload_task
- = GNUNET_SCHEDULER_add_delayed (sc->h->sched,
- GNUNET_NO,
- GNUNET_SCHEDULER_PRIORITY_BACKGROUND,
- GNUNET_SCHEDULER_NO_TASK,
- GNUNET_TIME_UNIT_ZERO,
+ = GNUNET_SCHEDULER_add_with_priority (sc->h->sched,
+ GNUNET_SCHEDULER_PRIORITY_BACKGROUND,
&do_upload,
sc);
}
if (NULL == sc->dsh)
{
sc->upload_task
- = GNUNET_SCHEDULER_add_delayed (sc->h->sched,
- GNUNET_NO,
+ = GNUNET_SCHEDULER_add_with_priority (sc->h->sched,
GNUNET_SCHEDULER_PRIORITY_BACKGROUND,
- GNUNET_SCHEDULER_NO_TASK,
- GNUNET_TIME_UNIT_ZERO,
&do_upload,
sc);
return;
else
GNUNET_CRYPTO_hash_file (sc->h->sched,
GNUNET_SCHEDULER_PRIORITY_IDLE,
- GNUNET_NO,
p->data.file.filename,
HASHING_BLOCKSIZE,
&hash_for_index_cb,
// and reserve as first task (then trigger
// "do_upload" from that continuation)!
ret->upload_task
- = GNUNET_SCHEDULER_add_delayed (h->sched,
- GNUNET_NO,
+ = GNUNET_SCHEDULER_add_with_priority (h->sched,
GNUNET_SCHEDULER_PRIORITY_BACKGROUND,
- GNUNET_SCHEDULER_NO_TASK,
- GNUNET_TIME_UNIT_ZERO,
&do_upload,
ret);
return ret;
return;
}
GNUNET_SCHEDULER_add_continuation (pkc->h->sched,
- GNUNET_NO,
&publish_ksk_cont,
pkc,
GNUNET_SCHEDULER_REASON_PREREQ_DONE);
pkc->cpy->purpose.purpose = htonl(GNUNET_SIGNATURE_PURPOSE_FS_KBLOCK);
pkc->ksk_uri = GNUNET_FS_uri_dup (ksk_uri);
GNUNET_SCHEDULER_add_continuation (h->sched,
- GNUNET_NO,
&publish_ksk_cont,
pkc,
GNUNET_SCHEDULER_REASON_PREREQ_DONE);
}
sc->task
= GNUNET_SCHEDULER_add_delayed (sc->h->sched,
- GNUNET_NO,
- GNUNET_SCHEDULER_PRIORITY_IDLE,
- GNUNET_SCHEDULER_NO_TASK,
GNUNET_TIME_UNIT_SECONDS,
&do_reconnect,
sc);
&te->emsg))
{
GNUNET_SCHEDULER_add_continuation (te->h->sched,
- GNUNET_NO,
te->cont,
te->cls,
GNUNET_SCHEDULER_REASON_TIMEOUT);
te->uri->data.chk.chk = te->chk_tree[0];
te->uri->data.chk.file_length = GNUNET_htonll (te->size);
GNUNET_SCHEDULER_add_continuation (te->h->sched,
- GNUNET_NO,
te->cont,
te->cls,
GNUNET_SCHEDULER_REASON_PREREQ_DONE);
&pi);
GNUNET_CRYPTO_hash_file (h->sched,
GNUNET_SCHEDULER_PRIORITY_IDLE,
- GNUNET_NO,
filename,
HASHING_BLOCKSIZE,
&process_hash,
/* slow validation, need to hash full file (again) */
GNUNET_CRYPTO_hash_file (sched,
GNUNET_SCHEDULER_PRIORITY_IDLE,
- GNUNET_NO,
fn,
HASHING_BLOCKSIZE,
&hash_for_index_val,
if (deadline.value == GNUNET_TIME_UNIT_FOREVER_REL.value)
return e;
e->task = GNUNET_SCHEDULER_add_delayed (sched,
- GNUNET_NO,
- GNUNET_SCHEDULER_PRIORITY_BACKGROUND,
- GNUNET_SCHEDULER_NO_TASK,
deadline,
&timeout_ds_request,
e);
if (NULL == buf)
{
/* timeout, try another peer immediately again */
- pr->task = GNUNET_SCHEDULER_add_delayed (sched,
- GNUNET_NO,
- GNUNET_SCHEDULER_PRIORITY_IDLE,
- GNUNET_SCHEDULER_NO_TASK,
- GNUNET_TIME_UNIT_ZERO,
- &forward_request_task,
- pr);
+ pr->task = GNUNET_SCHEDULER_add_with_priority (sched,
+ GNUNET_SCHEDULER_PRIORITY_IDLE,
+ &forward_request_task,
+ pr);
return 0;
}
/* (2) build query message */
/* (3) schedule job to do it again (or another peer, etc.) */
pr->task = GNUNET_SCHEDULER_add_delayed (sched,
- GNUNET_NO,
- GNUNET_SCHEDULER_PRIORITY_IDLE,
- GNUNET_SCHEDULER_NO_TASK,
get_processing_delay (), // FIXME!
&forward_request_task,
pr);
{
/* try again later; FIXME: we may need to un-reserve "amount"? */
pr->task = GNUNET_SCHEDULER_add_delayed (sched,
- GNUNET_NO,
- GNUNET_SCHEDULER_PRIORITY_IDLE,
- GNUNET_SCHEDULER_NO_TASK,
get_processing_delay (), // FIXME: longer?
&forward_request_task,
pr);
{
/* try again later */
pr->task = GNUNET_SCHEDULER_add_delayed (sched,
- GNUNET_NO,
- GNUNET_SCHEDULER_PRIORITY_IDLE,
- GNUNET_SCHEDULER_NO_TASK,
get_processing_delay (), // FIXME: longer?
&forward_request_task,
pr);
{
/* we're busy transmitting a result, wait a bit */
pr->task = GNUNET_SCHEDULER_add_delayed (sched,
- GNUNET_NO,
- GNUNET_SCHEDULER_PRIORITY_IDLE,
- GNUNET_SCHEDULER_NO_TASK,
get_processing_delay (),
&forward_request_task,
pr);
{
/* no possible target found, wait some time */
pr->task = GNUNET_SCHEDULER_add_delayed (sched,
- GNUNET_NO,
- GNUNET_SCHEDULER_PRIORITY_IDLE,
- GNUNET_SCHEDULER_NO_TASK,
get_processing_delay (), // FIXME: exponential back-off? or at least wait longer...
&forward_request_task,
pr);
pr,
GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
pr->task = GNUNET_SCHEDULER_add_delayed (sched,
- GNUNET_NO,
- GNUNET_SCHEDULER_PRIORITY_IDLE,
- GNUNET_SCHEDULER_NO_TASK,
get_processing_delay (),
&forward_request_task,
pr);
GNUNET_assert (GNUNET_OK == ok);
GNUNET_SCHEDULER_add_continuation (sched,
- GNUNET_NO,
&transmit_local_get,
lgc,
GNUNET_SCHEDULER_REASON_PREREQ_DONE);
destroy_pending_request (eer);
}
pr->task = GNUNET_SCHEDULER_add_delayed (sched,
- GNUNET_NO,
- GNUNET_SCHEDULER_PRIORITY_IDLE,
- GNUNET_SCHEDULER_NO_TASK,
get_processing_delay (),
&forward_request_task,
pr);
(pgc->type == GNUNET_DATASTORE_BLOCKTYPE_SKBLOCK) ) )
{
GNUNET_SCHEDULER_add_continuation (sched,
- GNUNET_NO,
&forward_get_request,
pgc,
GNUNET_SCHEDULER_REASON_PREREQ_DONE);
pgc);
else
GNUNET_SCHEDULER_add_continuation (sched,
- GNUNET_NO,
&forward_get_request,
pgc,
GNUNET_SCHEDULER_REASON_PREREQ_DONE);
if (server == NULL)
{
GNUNET_SCHEDULER_add_delayed (sched,
- GNUNET_NO,
- GNUNET_SCHEDULER_PRIORITY_HIGH,
- GNUNET_SCHEDULER_NO_TASK,
GNUNET_TIME_UNIT_SECONDS,
&core_connect_task,
NULL);
GNUNET_SERVER_add_handlers (server, handlers);
core_connect_task (NULL, NULL);
GNUNET_SCHEDULER_add_delayed (sched,
- GNUNET_YES,
- GNUNET_SCHEDULER_PRIORITY_IDLE,
- GNUNET_SCHEDULER_NO_TASK,
GNUNET_TIME_UNIT_FOREVER_REL,
&shutdown_task,
NULL);
return (GNUNET_OK ==
GNUNET_SERVICE_run (argc,
argv,
- "fs", &run, NULL, NULL, NULL)) ? 0 : 1;
+ "fs", &run, NULL)) ? 0 : 1;
}
/* end of gnunet-service-fs.c */
#include "gnunet_arm_service.h"
#include "gnunet_fs_service.h"
-#define VERBOSE GNUNET_NO
+#define VERBOSE GNUNET_YES
#define START_ARM GNUNET_YES
printf ("Download complete, %llu kbps.\n",
(unsigned long long) (FILESIZE * 1000 / (1+GNUNET_TIME_absolute_get_duration (start).value) / 1024));
GNUNET_SCHEDULER_add_continuation (sched,
- GNUNET_NO,
&abort_download_task,
NULL,
GNUNET_SCHEDULER_REASON_PREREQ_DONE);
event->value.publish.specifics.error.message);
GNUNET_break (0);
GNUNET_SCHEDULER_add_continuation (sched,
- GNUNET_NO,
&abort_publish_task,
NULL,
GNUNET_SCHEDULER_REASON_PREREQ_DONE);
"Error downloading file: %s\n",
event->value.download.specifics.error.message);
GNUNET_SCHEDULER_add_continuation (sched,
- GNUNET_NO,
&abort_download_task,
NULL,
GNUNET_SCHEDULER_REASON_PREREQ_DONE);
case GNUNET_FS_STATUS_DOWNLOAD_STOPPED:
GNUNET_assert (download == event->value.download.dc);
GNUNET_SCHEDULER_add_continuation (sched,
- GNUNET_NO,
&abort_publish_task,
NULL,
GNUNET_SCHEDULER_REASON_PREREQ_DONE);
{
GNUNET_SCHEDULER_add_continuation (sched,
- GNUNET_NO,
&abort_publish_task,
NULL,
GNUNET_SCHEDULER_REASON_PREREQ_DONE);
if (0 == strcmp ("list_indexed-context-dir",
event->value.publish.cctx))
GNUNET_SCHEDULER_add_continuation (sched,
- GNUNET_NO,
&list_indexed_task,
NULL,
GNUNET_SCHEDULER_REASON_PREREQ_DONE);
if (0 == strcmp ("list_indexed-context-dir",
event->value.publish.cctx))
GNUNET_SCHEDULER_add_continuation (sched,
- GNUNET_NO,
&abort_publish_task,
NULL,
GNUNET_SCHEDULER_REASON_PREREQ_DONE);
if (0 == strcmp ("list_indexed-context-dir",
event->value.publish.cctx))
GNUNET_SCHEDULER_add_continuation (sched,
- GNUNET_NO,
&abort_publish_task,
NULL,
GNUNET_SCHEDULER_REASON_PREREQ_DONE);
if (0 == strcmp ("list_indexed-context-dir",
event->value.publish.cctx))
GNUNET_SCHEDULER_add_continuation (sched,
- GNUNET_NO,
&abort_publish_task,
NULL,
GNUNET_SCHEDULER_REASON_PREREQ_DONE);
{
GNUNET_assert (publish == event->value.publish.sc);
GNUNET_SCHEDULER_add_continuation (sched,
- GNUNET_NO,
&abort_publish_task,
NULL,
GNUNET_SCHEDULER_REASON_PREREQ_DONE);
printf ("Search complete.\n");
#endif
GNUNET_SCHEDULER_add_continuation (sched,
- GNUNET_NO,
&abort_search_task,
NULL,
GNUNET_SCHEDULER_REASON_PREREQ_DONE);
event->value.publish.specifics.error.message);
GNUNET_break (0);
GNUNET_SCHEDULER_add_continuation (sched,
- GNUNET_NO,
&abort_publish_task,
NULL,
GNUNET_SCHEDULER_REASON_PREREQ_DONE);
"Error searching file: %s\n",
event->value.search.specifics.error.message);
GNUNET_SCHEDULER_add_continuation (sched,
- GNUNET_NO,
&abort_search_task,
NULL,
GNUNET_SCHEDULER_REASON_PREREQ_DONE);
case GNUNET_FS_STATUS_SEARCH_STOPPED:
GNUNET_assert (search == event->value.search.sc);
GNUNET_SCHEDULER_add_continuation (sched,
- GNUNET_NO,
&abort_publish_task,
NULL,
GNUNET_SCHEDULER_REASON_PREREQ_DONE);
printf ("Unindex complete, %llu kbps.\n",
(unsigned long long) (FILESIZE * 1000 / (1+GNUNET_TIME_absolute_get_duration (start).value) / 1024));
GNUNET_SCHEDULER_add_continuation (sched,
- GNUNET_NO,
&abort_unindex_task,
NULL,
GNUNET_SCHEDULER_REASON_PREREQ_DONE);
event->value.publish.specifics.error.message);
GNUNET_break (0);
GNUNET_SCHEDULER_add_continuation (sched,
- GNUNET_NO,
&abort_publish_task,
NULL,
GNUNET_SCHEDULER_REASON_PREREQ_DONE);
"Error unindexing file: %s\n",
event->value.unindex.specifics.error.message);
GNUNET_SCHEDULER_add_continuation (sched,
- GNUNET_NO,
&abort_unindex_task,
NULL,
GNUNET_SCHEDULER_REASON_PREREQ_DONE);
case GNUNET_FS_STATUS_UNINDEX_STOPPED:
GNUNET_assert (unindex == event->value.unindex.uc);
GNUNET_SCHEDULER_add_continuation (sched,
- GNUNET_NO,
&abort_publish_task,
NULL,
GNUNET_SCHEDULER_REASON_PREREQ_DONE);
NULL, GNUNET_NO,
handlers);
GNUNET_SCHEDULER_add_delayed (sched,
- GNUNET_YES,
- GNUNET_SCHEDULER_PRIORITY_IDLE,
- GNUNET_SCHEDULER_NO_TASK,
GNUNET_TIME_UNIT_FOREVER_REL,
&cleaning_task, NULL);
}
GNUNET_NETWORK_fdset_copy_native (gws, &ws, max);
current_task
= GNUNET_SCHEDULER_add_select (sched,
- GNUNET_NO,
GNUNET_SCHEDULER_PRIORITY_DEFAULT,
GNUNET_SCHEDULER_NO_TASK,
GNUNET_TIME_UNIT_MINUTES,
hostlist_delay.value,
GNUNET_YES);
current_task = GNUNET_SCHEDULER_add_delayed (sched,
- GNUNET_NO,
- GNUNET_SCHEDULER_PRIORITY_IDLE,
- GNUNET_SCHEDULER_NO_TASK,
delay,
&check_task,
NULL);
GNUNET_free (results);
/* schedule next update of the response */
GNUNET_SCHEDULER_add_delayed (sched,
- GNUNET_NO,
- GNUNET_SCHEDULER_PRIORITY_IDLE,
- GNUNET_SCHEDULER_NO_TASK,
RESPONSE_UPDATE_FREQUENCY,
&update_response,
NULL);
GNUNET_NETWORK_fdset_copy_native (wes, &es, max);
hostlist_task
= GNUNET_SCHEDULER_add_select (sched,
- GNUNET_NO,
GNUNET_SCHEDULER_PRIORITY_HIGH,
GNUNET_SCHEDULER_NO_TASK,
tv,
"-L", "DEBUG",
#endif
"-c", cfgname, NULL);
- sleep (1); /* allow ARM to start */
#endif
GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
GNUNET_ARM_start_services (p->cfg, sched, "core", NULL);
*
* @param sched scheduler to use
* @param priority scheduling priority to use
- * @param run_on_shutdown should we complete even on shutdown?
* @param filename name of file to hash
* @param blocksize number of bytes to process in one task
* @param callback function to call upon completion
*/
void GNUNET_CRYPTO_hash_file (struct GNUNET_SCHEDULER_Handle *sched,
enum GNUNET_SCHEDULER_Priority priority,
- int run_on_shutdown,
const char *filename,
size_t blocksize,
GNUNET_CRYPTO_HashCompletedCallback callback,
/**
- * Initialize and run scheduler. This function will return when
- * either a shutdown was initiated (via signal) and all tasks marked
- * to "run_on_shutdown" have been completed or when all tasks in
- * general have been completed.
+ * Initialize and run scheduler. This function will return when all
+ * tasks have completed. On systems with signals, receiving a SIGTERM
+ * (and other similar signals) will cause "GNUNET_SCHEDULER_shutdown"
+ * to be run after the active task is complete. As a result, SIGTERM
+ * causes all active tasks to be scheduled with reason
+ * "GNUNET_SCHEDULER_REASON_SHUTDOWN". (However, tasks added
+ * afterwards will execute normally!). Note that any particular
+ * signal will only shut down one scheduler; applications should
+ * always only create a single scheduler.
*
- * @param task task to run immediately
- * @param cls closure of task
+ * @param task task to run first (and immediately)
+ * @param task_cls closure of task
*/
-void GNUNET_SCHEDULER_run (GNUNET_SCHEDULER_Task task, void *cls);
+void GNUNET_SCHEDULER_run (GNUNET_SCHEDULER_Task task, void *task_cls);
/**
- * Request the shutdown of a scheduler. This function can be used to
- * stop a scheduler, for example from within the signal
- * handler for signals causing shutdowns.
+ * Request the shutdown of a scheduler. Marks all currently
+ * pending tasks as ready because of shutdown. This will
+ * cause all tasks to run (as soon as possible, respecting
+ * priorities and prerequisite tasks). Note that tasks
+ * scheduled AFTER this call may still be delayed arbitrarily.
+ *
+ * @param sched the scheduler
*/
void GNUNET_SCHEDULER_shutdown (struct GNUNET_SCHEDULER_Handle *sched);
*/
void
GNUNET_SCHEDULER_add_continuation (struct GNUNET_SCHEDULER_Handle *sched,
- int run_on_shutdown,
GNUNET_SCHEDULER_Task main,
void *cls,
enum GNUNET_SCHEDULER_Reason reason);
/**
- * Schedule a new task to be run after the specified
- * prerequisite task has completed.
+ * Schedule a new task to be run after the specified prerequisite task
+ * has completed. It will be run with the priority of the calling
+ * task.
*
* @param sched scheduler to use
- * @param run_on_shutdown run on shutdown?
- * @param prio how important is this task?
* @param prerequisite_task run this task after the task with the given
* task identifier completes (and any of our other
* conditions, such as delay, read or write-readyness
* are satisfied). Use GNUNET_SCHEDULER_NO_TASK to not have any dependency
- * on completion of other tasks.
- * @param main main function of the task
- * @param cls closure of task
+ * on completion of other tasks (this will cause the task to run as
+ * soon as possible).
+ * @param task main function of the task
+ * @param task_cls closure of task
* @return unique task identifier for the job
- * only valid until "main" is started!
+ * only valid until "task" is started!
*/
GNUNET_SCHEDULER_TaskIdentifier
GNUNET_SCHEDULER_add_after (struct GNUNET_SCHEDULER_Handle *sched,
- int run_on_shutdown,
- enum GNUNET_SCHEDULER_Priority prio,
GNUNET_SCHEDULER_TaskIdentifier prerequisite_task,
- GNUNET_SCHEDULER_Task main, void *cls);
+ GNUNET_SCHEDULER_Task task,
+ void *task_cls);
+
+
+/**
+ * Schedule a new task to be run with a specified priority.
+ *
+ * @param sched scheduler to use
+ * @param prio how important is the new task?
+ * @param task main function of the task
+ * @param task_cls closure of task
+ * @return unique task identifier for the job
+ * only valid until "task" is started!
+ */
+GNUNET_SCHEDULER_TaskIdentifier
+GNUNET_SCHEDULER_add_with_priority (struct GNUNET_SCHEDULER_Handle *sched,
+ enum GNUNET_SCHEDULER_Priority prio,
+ GNUNET_SCHEDULER_Task task,
+ void *task_cls);
/**
* Schedule a new task to be run with a specified delay. The task
- * will be scheduled for execution once the delay has expired and the
- * prerequisite task has completed.
+ * will be scheduled for execution once the delay has expired. It
+ * will be run with the priority of the calling task.
*
* @param sched scheduler to use
- * @param run_on_shutdown run on shutdown? You can use this
- * argument to run a function only during shutdown
- * by setting delay to -1. Set this
- * argument to GNUNET_NO to skip this task if
- * the user requested process termination.
- * @param prio how important is this task?
- * @param prerequisite_task run this task after the task with the given
- * task identifier completes (and any of our other
- * conditions, such as delay, read or write-readyness
- * are satisfied). Use GNUNET_SCHEDULER_NO_TASK to not have any dependency
- * on completion of other tasks.
- * @param delay how long should we wait? Use GNUNET_TIME_UNIT_FOREVER_REL for "forever"
- * @param main main function of the task
- * @param cls closure of task
+ * @param delay when should this operation time out? Use
+ * GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown"
+ * @param task main function of the task
+ * @param task_cls closure of task
* @return unique task identifier for the job
- * only valid until "main" is started!
+ * only valid until "task" is started!
*/
GNUNET_SCHEDULER_TaskIdentifier
GNUNET_SCHEDULER_add_delayed (struct GNUNET_SCHEDULER_Handle *sched,
- int run_on_shutdown,
- enum GNUNET_SCHEDULER_Priority prio,
- GNUNET_SCHEDULER_TaskIdentifier
- prerequisite_task,
struct GNUNET_TIME_Relative delay,
- GNUNET_SCHEDULER_Task main, void *cls);
+ GNUNET_SCHEDULER_Task task,
+ void *task_cls);
/**
* specified file descriptor is ready for reading. The delay can be
* used as a timeout on the socket being ready. The task will be
* scheduled for execution once either the delay has expired or the
- * socket operation is ready.
+ * socket operation is ready. It will be run with the priority of
+ * the calling task.
*
* @param sched scheduler to use
- * @param run_on_shutdown run on shutdown? Set this
- * argument to GNUNET_NO to skip this task if
- * the user requested process termination.
- * @param prio how important is this task?
- * @param prerequisite_task run this task after the task with the given
- * task identifier completes (and any of our other
- * conditions, such as delay, read or write-readyness
- * are satisfied). Use GNUNET_SCHEDULER_NO_TASK to not have any dependency
- * on completion of other tasks.
- * @param delay how long should we wait? Use GNUNET_TIME_UNIT_FOREVER_REL for "forever"
+ * @param delay when should this operation time out? Use
+ * GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown"
* @param rfd read file-descriptor
- * @param main main function of the task
- * @param cls closure of task
+ * @param task main function of the task
+ * @param task_cls closure of task
* @return unique task identifier for the job
- * only valid until "main" is started!
+ * only valid until "task" is started!
*/
GNUNET_SCHEDULER_TaskIdentifier
GNUNET_SCHEDULER_add_read_net (struct GNUNET_SCHEDULER_Handle *sched,
- int run_on_shutdown,
- enum GNUNET_SCHEDULER_Priority prio,
- GNUNET_SCHEDULER_TaskIdentifier prerequisite_task,
- struct GNUNET_TIME_Relative delay,
- struct GNUNET_NETWORK_Handle *rfd, GNUNET_SCHEDULER_Task main, void *cls);
+ struct GNUNET_TIME_Relative delay,
+ struct GNUNET_NETWORK_Handle *rfd,
+ GNUNET_SCHEDULER_Task task,
+ void *task_cls);
/**
* specified file descriptor is ready for writing. The delay can be
* used as a timeout on the socket being ready. The task will be
* scheduled for execution once either the delay has expired or the
- * socket operation is ready.
+ * socket operation is ready. It will be run with the priority of
+ * the calling task.
*
* @param sched scheduler to use
- * @param run_on_shutdown run on shutdown? Set this
- * argument to GNUNET_NO to skip this task if
- * the user requested process termination.
- * @param prio how important is this task?
- * @param prerequisite_task run this task after the task with the given
- * task identifier completes (and any of our other
- * conditions, such as delay, read or write-readyness
- * are satisfied). Use GNUNET_SCHEDULER_NO_TASK to not have any dependency
- * on completion of other tasks.
- * @param delay how long should we wait? Use GNUNET_TIME_UNIT_FOREVER_REL for "forever"
+ * @param delay when should this operation time out? Use
+ * GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown"
* @param wfd write file-descriptor
- * @param main main function of the task
- * @param cls closure of task
+ * @param task main function of the task
+ * @param task_cls closure of task
* @return unique task identifier for the job
- * only valid until "main" is started!
+ * only valid until "task" is started!
*/
GNUNET_SCHEDULER_TaskIdentifier
GNUNET_SCHEDULER_add_write_net (struct GNUNET_SCHEDULER_Handle *sched,
- int run_on_shutdown,
- enum GNUNET_SCHEDULER_Priority prio,
- GNUNET_SCHEDULER_TaskIdentifier prerequisite_task,
- struct GNUNET_TIME_Relative delay,
- struct GNUNET_NETWORK_Handle *wfd, GNUNET_SCHEDULER_Task main, void *cls);
+ struct GNUNET_TIME_Relative delay,
+ struct GNUNET_NETWORK_Handle *wfd,
+ GNUNET_SCHEDULER_Task task,
+ void *task_cls);
/**
* specified file descriptor is ready for reading. The delay can be
* used as a timeout on the socket being ready. The task will be
* scheduled for execution once either the delay has expired or the
- * socket operation is ready.
+ * socket operation is ready. It will be run with the priority of
+ * the calling task.
*
* @param sched scheduler to use
- * @param run_on_shutdown run on shutdown? Set this
- * argument to GNUNET_NO to skip this task if
- * the user requested process termination.
- * @param prio how important is this task?
- * @param prerequisite_task run this task after the task with the given
- * task identifier completes (and any of our other
- * conditions, such as delay, read or write-readyness
- * are satisfied). Use GNUNET_SCHEDULER_NO_TASK to not have any dependency
- * on completion of other tasks.
- * @param delay how long should we wait? Use GNUNET_TIME_UNIT_FOREVER_REL for "forever"
+ * @param delay when should this operation time out? Use
+ * GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown"
* @param rfd read file-descriptor
- * @param main main function of the task
- * @param cls closure of task
+ * @param task main function of the task
+ * @param task_cls closure of task
* @return unique task identifier for the job
- * only valid until "main" is started!
+ * only valid until "task" is started!
*/
GNUNET_SCHEDULER_TaskIdentifier
GNUNET_SCHEDULER_add_read_file (struct GNUNET_SCHEDULER_Handle *sched,
- int run_on_shutdown,
- enum GNUNET_SCHEDULER_Priority prio,
- GNUNET_SCHEDULER_TaskIdentifier prerequisite_task,
struct GNUNET_TIME_Relative delay,
const struct GNUNET_DISK_FileHandle *rfd,
- GNUNET_SCHEDULER_Task main, void *cls);
+ GNUNET_SCHEDULER_Task task,
+ void *task_cls);
/**
* specified file descriptor is ready for writing. The delay can be
* used as a timeout on the socket being ready. The task will be
* scheduled for execution once either the delay has expired or the
- * socket operation is ready.
+ * socket operation is ready. It will be run with the priority of
+ * the calling task.
*
* @param sched scheduler to use
- * @param run_on_shutdown run on shutdown? Set this
- * argument to GNUNET_NO to skip this task if
- * the user requested process termination.
- * @param prio how important is this task?
- * @param prerequisite_task run this task after the task with the given
- * task identifier completes (and any of our other
- * conditions, such as delay, read or write-readyness
- * are satisfied). Use GNUNET_SCHEDULER_NO_TASK to not have any dependency
- * on completion of other tasks.
- * @param delay how long should we wait? Use GNUNET_TIME_UNIT_FOREVER_REL for "forever"
+ * @param delay when should this operation time out? Use
+ * GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown"
* @param wfd write file-descriptor
- * @param main main function of the task
- * @param cls closure of task
+ * @param task main function of the task
+ * @param task_cls closure of task
* @return unique task identifier for the job
- * only valid until "main" is started!
+ * only valid until "task" is started!
*/
GNUNET_SCHEDULER_TaskIdentifier
GNUNET_SCHEDULER_add_write_file (struct GNUNET_SCHEDULER_Handle *sched,
- int run_on_shutdown,
- enum GNUNET_SCHEDULER_Priority prio,
- GNUNET_SCHEDULER_TaskIdentifier prerequisite_task,
struct GNUNET_TIME_Relative delay,
const struct GNUNET_DISK_FileHandle *wfd,
- GNUNET_SCHEDULER_Task main, void *cls);
+ GNUNET_SCHEDULER_Task task,
+ void *task_cls);
/**
* </code>
*
* @param sched scheduler to use
- * @param run_on_shutdown run on shutdown? Set this
- * argument to GNUNET_NO to skip this task if
- * the user requested process termination.
* @param prio how important is this task?
* @param prerequisite_task run this task after the task with the given
* task identifier completes (and any of our other
* conditions, such as delay, read or write-readyness
* are satisfied). Use GNUNET_SCHEDULER_NO_TASK to not have any dependency
* on completion of other tasks.
- * @param delay how long should we wait? Use GNUNET_TIME_UNIT_FOREVER_REL for "forever"
+ * @param delay how long should we wait? Use GNUNET_TIME_UNIT_FOREVER_REL for "forever",
+ * which means that the task will only be run after we receive SIGTERM
* @param rs set of file descriptors we want to read (can be NULL)
* @param ws set of file descriptors we want to write (can be NULL)
- * @param main main function of the task
- * @param cls closure of task
+ * @param task main function of the task
+ * @param task_cls closure of task
* @return unique task identifier for the job
- * only valid until "main" is started!
+ * only valid until "task" is started!
*/
GNUNET_SCHEDULER_TaskIdentifier
GNUNET_SCHEDULER_add_select (struct GNUNET_SCHEDULER_Handle *sched,
- int run_on_shutdown,
enum GNUNET_SCHEDULER_Priority prio,
GNUNET_SCHEDULER_TaskIdentifier
prerequisite_task,
struct GNUNET_TIME_Relative delay,
const struct GNUNET_NETWORK_FDSet * rs,
const struct GNUNET_NETWORK_FDSet * ws,
- GNUNET_SCHEDULER_Task main, void *cls);
+ GNUNET_SCHEDULER_Task task,
+ void *task_cls);
#if 0 /* keep Emacsens' auto-indent happy */
{
cfg);
-/**
- * Function called when the service shuts
- * down to run service-specific teardown code.
- *
- * @param cls closure
- * @param cfg configuration to use
- */
-typedef void (*GNUNET_SERVICE_Term) (void *cls,
- const struct GNUNET_CONFIGURATION_Handle *
- cfg);
-
-
/**
* Run a standard GNUnet service startup sequence (initialize loggers
* and configuration, parse options).
* @param serviceName our service name
* @param task main task of the service
* @param task_cls closure for task
- * @param term termination task of the service
- * @param term_cls closure for term
* @return GNUNET_SYSERR on error, GNUNET_OK
* if we shutdown nicely
*/
char *const *argv,
const char *serviceName,
GNUNET_SERVICE_Main task,
- void *task_cls,
- GNUNET_SERVICE_Term term, void *term_cls);
+ void *task_cls);
struct GNUNET_SERVICE_Context;
notify_change (nat, ext_addr_natpmp, port_mapped);
}
- nat->pulse_timer = GNUNET_SCHEDULER_add_delayed (nat->sched, GNUNET_NO,
- GNUNET_SCHEDULER_PRIORITY_DEFAULT,
- GNUNET_SCHEDULER_NO_TASK,
+ nat->pulse_timer = GNUNET_SCHEDULER_add_delayed (nat->sched,
GNUNET_TIME_UNIT_SECONDS,
&nat_pulse, nat);
}
nat->natpmp = GNUNET_NAT_NATPMP_init (nat->local_addr, addrlen, nat->public_port);
nat->upnp = GNUNET_NAT_UPNP_init (nat->local_addr, addrlen, nat->public_port);
- nat->pulse_timer = GNUNET_SCHEDULER_add_delayed (sched, GNUNET_NO,
- GNUNET_SCHEDULER_PRIORITY_DEFAULT,
- GNUNET_SCHEDULER_NO_TASK,
+ nat->pulse_timer = GNUNET_SCHEDULER_add_delayed (sched,
GNUNET_TIME_UNIT_SECONDS,
&nat_pulse, nat);
nat = GNUNET_NAT_register (sched, addr, data.addrlen, addr_callback, NULL);
GNUNET_free (addr);
- GNUNET_SCHEDULER_add_delayed (sched, GNUNET_NO,
- GNUNET_SCHEDULER_PRIORITY_DEFAULT,
- GNUNET_SCHEDULER_NO_TASK,
+ GNUNET_SCHEDULER_add_delayed (sched,
GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, TIMEOUT),
stop, nat);
}
static unsigned int retries;
unsigned int count;
+ if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
+ return;
count = 0;
GNUNET_DISK_directory_create (networkIdDirectory);
GNUNET_DISK_directory_scan (networkIdDirectory,
GNUNET_ERROR_TYPE_BULK,
_("Still no peers found in `%s'!\n"), networkIdDirectory);
GNUNET_SCHEDULER_add_delayed (tc->sched,
- GNUNET_NO,
- GNUNET_SCHEDULER_PRIORITY_KEEP,
- GNUNET_SCHEDULER_NO_TASK,
DATA_HOST_FREQ,
&cron_scan_directory_data_hosts, NULL);
}
flush_trust (pos);
pos = pos->next;
}
- if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- GNUNET_SCHEDULER_add_delayed (tc->sched,
- GNUNET_YES,
- GNUNET_SCHEDULER_PRIORITY_KEEP,
- GNUNET_SCHEDULER_NO_TASK,
- TRUST_FLUSH_FREQ, &cron_flush_trust, NULL);
+ if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
+ return;
+ GNUNET_SCHEDULER_add_delayed (tc->sched,
+ TRUST_FLUSH_FREQ, &cron_flush_trust, NULL);
}
{
struct GNUNET_TIME_Absolute now;
+ if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
+ return;
now = GNUNET_TIME_absolute_get ();
GNUNET_DISK_directory_scan (networkIdDirectory,
&discard_hosts_helper, &now);
GNUNET_SCHEDULER_add_delayed (tc->sched,
- GNUNET_NO,
- GNUNET_SCHEDULER_PRIORITY_KEEP,
- GNUNET_SCHEDULER_NO_TASK,
DATA_HOST_CLEAN_FREQ,
&cron_clean_data_hosts, NULL);
}
};
+
/**
* Process statistics requests.
*
&trustDirectory));
GNUNET_DISK_directory_create (networkIdDirectory);
GNUNET_DISK_directory_create (trustDirectory);
- GNUNET_SCHEDULER_add_delayed (sched,
- GNUNET_NO,
- GNUNET_SCHEDULER_PRIORITY_IDLE,
- GNUNET_SCHEDULER_NO_TASK,
- GNUNET_TIME_UNIT_MILLISECONDS,
- &cron_scan_directory_data_hosts, NULL);
- GNUNET_SCHEDULER_add_delayed (sched,
- GNUNET_YES,
- GNUNET_SCHEDULER_PRIORITY_HIGH,
- GNUNET_SCHEDULER_NO_TASK,
- TRUST_FLUSH_FREQ, &cron_flush_trust, NULL);
- GNUNET_SCHEDULER_add_delayed (sched,
- GNUNET_NO,
- GNUNET_SCHEDULER_PRIORITY_IDLE,
- GNUNET_SCHEDULER_NO_TASK,
- DATA_HOST_CLEAN_FREQ,
- &cron_clean_data_hosts, NULL);
+ GNUNET_SCHEDULER_add_with_priority (sched,
+ GNUNET_SCHEDULER_PRIORITY_IDLE,
+ &cron_scan_directory_data_hosts, NULL);
+ GNUNET_SCHEDULER_add_with_priority (sched,
+ GNUNET_SCHEDULER_PRIORITY_HIGH,
+ &cron_flush_trust, NULL);
+ GNUNET_SCHEDULER_add_with_priority (sched,
+ GNUNET_SCHEDULER_PRIORITY_IDLE,
+ &cron_clean_data_hosts, NULL);
GNUNET_SERVER_add_handlers (server, handlers);
}
ret = (GNUNET_OK ==
GNUNET_SERVICE_run (argc,
argv,
- "peerinfo", &run, NULL, NULL, NULL)) ? 0 : 1;
+ "peerinfo", &run, NULL)) ? 0 : 1;
GNUNET_free_non_null (networkIdDirectory);
GNUNET_free_non_null (trustDirectory);
return ret;
"-L", "DEBUG",
#endif
"-c", "test_peerinfo_api_data.conf", NULL);
- sleep (1);
GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
argv, "test-peerinfo-api", "nohelp",
options, &run, &ok);
};
+/**
+ * Our configuration.
+ */
+static const struct GNUNET_CONFIGURATION_Handle *cfg;
+
/**
* Linked list of our active statistics.
*/
* Load persistent values from disk. Disk format is
* exactly the same format that we also use for
* setting the values over the network.
+ *
+ * @param server handle to the server context
*/
static void
-load (struct GNUNET_SERVER_Handle *server,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
+load (struct GNUNET_SERVER_Handle *server)
{
char *fn;
struct GNUNET_DISK_FileHandle *fh;
GNUNET_free (fn);
}
-
/**
* Write persistent statistics to disk.
- *
- * @param cls closure
- * @param cfg configuration to use
*/
static void
-save (void *cls,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
+save ()
{
struct StatsEntry *pos;
char *fn;
};
+/**
+ * Task run during shutdown.
+ *
+ * @param cls unused
+ * @param tc unused
+ */
+static void
+shutdown_task (void *cls,
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ save ();
+}
+
+
/**
* Process statistics requests.
*
* @param cls closure
* @param sched scheduler to use
* @param server the initialized server
- * @param cfg configuration to use
+ * @param c configuration to use
*/
static void
run (void *cls,
struct GNUNET_SCHEDULER_Handle *sched,
struct GNUNET_SERVER_Handle *server,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
+ const struct GNUNET_CONFIGURATION_Handle *c)
{
+ cfg = c;
GNUNET_SERVER_add_handlers (server, handlers);
- load (server, cfg);
+ load (server);
+ GNUNET_SCHEDULER_add_delayed (sched,
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ &shutdown_task,
+ NULL);
}
return (GNUNET_OK ==
GNUNET_SERVICE_run (argc,
argv,
- "statistics", &run, NULL, &save, NULL)) ? 0 : 1;
+ "statistics", &run, NULL)) ? 0 : 1;
}
/* end of gnunet-service-statistics.c */
#include "gnunet_getopt_lib.h"
#include "gnunet_service_lib.h"
-/**
- * Do cleanup here.
- *
- * @param cls closure
- * @param cfg configuration to use
- */
-static void
-finish (void *cls,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
-{
- /* FIXME */
-}
-
/**
* List of handlers for the messages understood by this
{NULL, NULL, 0, 0}
};
+
+/**
+ * Task run during shutdown.
+ *
+ * @param cls unused
+ * @param tc unused
+ */
+static void
+cleanup_task (void *cls,
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ /* FIXME: do clean up here */
+}
+
+
/**
* Process template requests.
*
{
/* FIXME: do setup here */
GNUNET_SERVER_add_handlers (server, handlers);
+ GNUNET_SCHEDULER_add_delayed (sched,
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ &cleanup_task,
+ NULL);
}
return (GNUNET_OK ==
GNUNET_SERVICE_run (argc,
argv,
- "template", &run, NULL, &finish, NULL)) ? 0 : 1;
+ "template", &run, NULL)) ? 0 : 1;
}
/* end of gnunet-service-template.c */
/* wait some more */
d->task
= GNUNET_SCHEDULER_add_delayed (d->sched,
- GNUNET_NO,
- GNUNET_SCHEDULER_PRIORITY_KEEP,
- GNUNET_SCHEDULER_NO_TASK,
GNUNET_CONSTANTS_EXEC_WAIT,
&start_fsm,
d);
d->wait_runs = 0;
d->task
= GNUNET_SCHEDULER_add_delayed (d->sched,
- GNUNET_NO,
- GNUNET_SCHEDULER_PRIORITY_KEEP,
- GNUNET_SCHEDULER_NO_TASK,
GNUNET_CONSTANTS_EXEC_WAIT,
&start_fsm,
d);
/* wait some more */
d->task
= GNUNET_SCHEDULER_add_delayed (d->sched,
- GNUNET_NO,
- GNUNET_SCHEDULER_PRIORITY_KEEP,
- GNUNET_SCHEDULER_NO_TASK,
GNUNET_CONSTANTS_EXEC_WAIT,
&start_fsm,
d);
/* wait some more */
d->task
= GNUNET_SCHEDULER_add_delayed (d->sched,
- GNUNET_NO,
- GNUNET_SCHEDULER_PRIORITY_KEEP,
- GNUNET_SCHEDULER_NO_TASK,
GNUNET_CONSTANTS_EXEC_WAIT,
&start_fsm,
d);
/* wait some more */
d->task
= GNUNET_SCHEDULER_add_delayed (d->sched,
- GNUNET_NO,
- GNUNET_SCHEDULER_PRIORITY_KEEP,
- GNUNET_SCHEDULER_NO_TASK,
GNUNET_CONSTANTS_EXEC_WAIT,
&start_fsm,
d);
}
ret->task
= GNUNET_SCHEDULER_add_delayed (sched,
- GNUNET_YES,
- GNUNET_SCHEDULER_PRIORITY_KEEP,
- GNUNET_SCHEDULER_NO_TASK,
GNUNET_CONSTANTS_EXEC_WAIT,
&start_fsm,
ret);
#endif
ret->phase = SP_COPIED;
GNUNET_SCHEDULER_add_continuation (sched,
- GNUNET_NO,
&start_fsm,
ret,
GNUNET_SCHEDULER_REASON_PREREQ_DONE);
d->dead_cb_cls = cb_cls;
d->task
= GNUNET_SCHEDULER_add_delayed (d->sched,
- GNUNET_YES,
- GNUNET_SCHEDULER_PRIORITY_KEEP,
- GNUNET_SCHEDULER_NO_TASK,
GNUNET_CONSTANTS_EXEC_WAIT,
&start_fsm,
d);
d->update_cb_cls = cb_cls;
d->task
= GNUNET_SCHEDULER_add_delayed (d->sched,
- GNUNET_NO,
- GNUNET_SCHEDULER_PRIORITY_KEEP,
- GNUNET_SCHEDULER_NO_TASK,
GNUNET_CONSTANTS_EXEC_WAIT,
&start_fsm,
d);
GNUNET_TRANSPORT_disconnect (ctx->d2th);
ctx->d2th = NULL;
GNUNET_SCHEDULER_add_continuation (ctx->d1->sched,
- GNUNET_NO,
¬ify_connect_result,
ctx,
(buf == NULL) ?
(unsigned long long) delay.value);
#endif
GNUNET_SCHEDULER_add_delayed (sched,
- GNUNET_NO,
- GNUNET_SCHEDULER_PRIORITY_DEFAULT,
- GNUNET_SCHEDULER_NO_TASK,
delay,
&find_more_peers,
NULL);
#endif
if (autoconnect)
GNUNET_SCHEDULER_add_delayed (sched,
- GNUNET_NO,
- GNUNET_SCHEDULER_PRIORITY_DEFAULT,
- GNUNET_SCHEDULER_NO_TASK,
GNUNET_TIME_UNIT_SECONDS /* give core time to tell us about existing connections */,
&find_more_peers,
NULL);
handlers);
GNUNET_SCHEDULER_add_delayed (sched,
- GNUNET_YES,
- GNUNET_SCHEDULER_PRIORITY_IDLE,
- GNUNET_SCHEDULER_NO_TASK,
GNUNET_TIME_UNIT_FOREVER_REL,
&cleaning_task, NULL);
}
#define VERBOSE GNUNET_YES
-#define NUM_PEERS 10
+#define NUM_PEERS 4
/**
* How long until we give up on connecting the peers?
GNUNET_free (q);
client->message_count--;
}
- GNUNET_assert (tsize > 0);
if (NULL != q)
{
+ GNUNET_assert (msize >= sizeof (struct GNUNET_MessageHeader));
th = GNUNET_SERVER_notify_transmit_ready (client->client,
msize,
GNUNET_TIME_UNIT_FOREVER_REL,
}
client->message_count++;
msize = ntohs (msg->size);
+ GNUNET_assert (msize >= sizeof (struct GNUNET_MessageHeader));
q = GNUNET_malloc (sizeof (struct ClientMessageQueueEntry) + msize);
memcpy (&q[1], msg, msize);
/* append to message queue */
if (min_remaining.value < GNUNET_TIME_UNIT_FOREVER_REL.value)
plugin->address_update_task
= GNUNET_SCHEDULER_add_delayed (plugin->env.sched,
- GNUNET_NO,
- GNUNET_SCHEDULER_PRIORITY_IDLE,
- GNUNET_SCHEDULER_NO_TASK,
min_remaining,
&expire_address_task, plugin);
pos = pos->next;
}
GNUNET_SCHEDULER_add_delayed (sched,
- GNUNET_NO,
- GNUNET_SCHEDULER_PRIORITY_IDLE,
- GNUNET_SCHEDULER_NO_TASK,
GNUNET_TIME_absolute_get_remaining (first),
&cleanup_validation, NULL);
}
GNUNET_i2s (peer));
#endif
pos->timeout.value = 0;
- GNUNET_SCHEDULER_add_delayed (sched,
- GNUNET_NO,
- GNUNET_SCHEDULER_PRIORITY_IDLE,
- GNUNET_SCHEDULER_NO_TASK,
- GNUNET_TIME_UNIT_ZERO,
- &cleanup_validation, NULL);
+ GNUNET_SCHEDULER_add_with_priority (sched,
+ GNUNET_SCHEDULER_PRIORITY_IDLE,
+ &cleanup_validation, NULL);
}
else
{
va = va->next;
}
GNUNET_SCHEDULER_add_delayed (sched,
- GNUNET_NO,
- GNUNET_SCHEDULER_PRIORITY_IDLE,
- GNUNET_SCHEDULER_NO_TASK,
GNUNET_TIME_absolute_get_remaining (chvc->e->timeout),
&cleanup_validation, NULL);
GNUNET_free (chvc);
n->quota_in = (GNUNET_CONSTANTS_DEFAULT_BPM_IN_OUT + 59999) / (60 * 1000);
add_plugins (n);
n->timeout_task = GNUNET_SCHEDULER_add_delayed (sched,
- GNUNET_NO,
- GNUNET_SCHEDULER_PRIORITY_IDLE,
- GNUNET_SCHEDULER_NO_TASK,
GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
&neighbour_timeout_task, n);
transmit_to_peer (NULL, 0,
n->peer_timeout =
GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
n->timeout_task =
- GNUNET_SCHEDULER_add_delayed (sched, GNUNET_NO,
- GNUNET_SCHEDULER_PRIORITY_IDLE,
- GNUNET_SCHEDULER_NO_TASK,
+ GNUNET_SCHEDULER_add_delayed (sched,
GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
&neighbour_timeout_task, n);
update_quota (n);
GNUNET_free (plugs);
}
GNUNET_SCHEDULER_add_delayed (sched,
- GNUNET_YES,
- GNUNET_SCHEDULER_PRIORITY_IDLE,
- GNUNET_SCHEDULER_NO_TASK,
GNUNET_TIME_UNIT_FOREVER_REL,
&unload_plugins, NULL);
if (no_transports)
GNUNET_SERVICE_run (argc,
argv,
"transport",
- &run, NULL, NULL, NULL)) ? 0 : 1;
+ &run, NULL)) ? 0 : 1;
}
/* end of gnunet-service-transport.c */
GNUNET_SERVER_receive_done (client, GNUNET_OK);
else
GNUNET_SCHEDULER_add_delayed (session->plugin->env->sched,
- GNUNET_NO,
- GNUNET_SCHEDULER_PRIORITY_HIGH,
- GNUNET_SCHEDULER_NO_TASK,
delay, &delayed_done, session);
}
here will end the process. */
ok = 0; /* if the last test succeeded, report success */
GNUNET_SCHEDULER_add_continuation (sched,
- GNUNET_NO,
&unload_task,
(void*) cfg,
GNUNET_SCHEDULER_REASON_PREREQ_DONE);
/* add job to catch failure (timeout) */
validation_timeout_task =
GNUNET_SCHEDULER_add_delayed (sched,
- GNUNET_NO,
- GNUNET_SCHEDULER_PRIORITY_KEEP,
- GNUNET_SCHEDULER_NO_TASK,
TIMEOUT,
&validation_failed,
NULL);
th->notify_size = size;
th->notify_delay_task
= GNUNET_SCHEDULER_add_delayed (h->sched,
- GNUNET_NO,
- GNUNET_SCHEDULER_PRIORITY_KEEP,
- GNUNET_SCHEDULER_NO_TASK,
timeout,
&peer_transmit_timeout, th);
if (at_head)
if (buf == NULL)
{
GNUNET_SCHEDULER_add_continuation (sqc->handle->sched,
- GNUNET_NO,
sqc->cont,
sqc->cont_cls,
GNUNET_SCHEDULER_REASON_TIMEOUT);
memcpy (&msg->peer, &sqc->target, sizeof (struct GNUNET_PeerIdentity));
if (sqc->cont != NULL)
GNUNET_SCHEDULER_add_continuation (sqc->handle->sched,
- GNUNET_NO,
sqc->cont,
sqc->cont_cls,
GNUNET_SCHEDULER_REASON_PREREQ_DONE);
GNUNET_TIME_absolute_get_remaining (hwl->timeout).value);
#endif
hwl->task = GNUNET_SCHEDULER_add_delayed (hwl->handle->sched,
- GNUNET_YES,
- GNUNET_SCHEDULER_PRIORITY_KEEP,
- GNUNET_SCHEDULER_NO_TASK,
GNUNET_TIME_absolute_get_remaining (hwl->timeout),
&hello_wait_timeout, hwl);
return;
hwl->rec_cls = rec_cls;
hwl->timeout = GNUNET_TIME_relative_to_absolute (timeout);
hwl->task = GNUNET_SCHEDULER_add_delayed (handle->sched,
- GNUNET_YES,
- GNUNET_SCHEDULER_PRIORITY_KEEP,
- GNUNET_SCHEDULER_NO_TASK,
timeout,
&hello_wait_timeout, hwl);
return;
memcpy (&tcm->peer, &th->target, sizeof (struct GNUNET_PeerIdentity));
th->notify_delay_task
= GNUNET_SCHEDULER_add_delayed (h->sched,
- GNUNET_NO,
- GNUNET_SCHEDULER_PRIORITY_KEEP,
- GNUNET_SCHEDULER_NO_TASK,
GNUNET_TIME_absolute_get_remaining
(th->timeout),
&peer_transmit_timeout, th);
GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == th->notify_delay_task);
th->notify_delay_task
= GNUNET_SCHEDULER_add_delayed (h->sched,
- GNUNET_NO,
- GNUNET_SCHEDULER_PRIORITY_KEEP,
- GNUNET_SCHEDULER_NO_TASK,
CONNECT_RETRY_TIMEOUT,
&try_connect_task,
th);
GNUNET_assert (h->reconnect_task == GNUNET_SCHEDULER_NO_TASK);
h->reconnect_task
= GNUNET_SCHEDULER_add_delayed (h->sched,
- GNUNET_NO,
- GNUNET_SCHEDULER_PRIORITY_DEFAULT,
- GNUNET_SCHEDULER_NO_TASK,
h->reconnect_delay, &reconnect, h);
h->reconnect_delay = GNUNET_TIME_UNIT_SECONDS;
}
#endif
th->notify_delay_task
= GNUNET_SCHEDULER_add_delayed (h->sched,
- GNUNET_NO,
- GNUNET_SCHEDULER_PRIORITY_KEEP,
- GNUNET_SCHEDULER_NO_TASK,
duration, &transmit_ready, th);
return;
}
#endif
th->notify_delay_task
= GNUNET_SCHEDULER_add_delayed (h->sched,
- GNUNET_NO,
- GNUNET_SCHEDULER_PRIORITY_KEEP,
- GNUNET_SCHEDULER_NO_TASK,
GNUNET_TIME_absolute_get_remaining
(th->timeout), &peer_transmit_timeout, th);
return;
GNUNET_assert (th->notify_delay_task == GNUNET_SCHEDULER_NO_TASK);
th->notify_delay_task
= GNUNET_SCHEDULER_add_delayed (h->sched,
- GNUNET_NO,
- GNUNET_SCHEDULER_PRIORITY_KEEP,
- GNUNET_SCHEDULER_NO_TASK,
GNUNET_TIME_absolute_get_remaining(th->timeout),
&peer_transmit_timeout,
th);
#endif
th->notify_delay_task
= GNUNET_SCHEDULER_add_delayed (handle->sched,
- GNUNET_NO,
- GNUNET_SCHEDULER_PRIORITY_KEEP,
- GNUNET_SCHEDULER_NO_TASK,
timeout, &peer_transmit_timeout, th);
return th;
}
sock->in_receive = GNUNET_SYSERR;
else
GNUNET_SCHEDULER_add_after (sock->sched,
- GNUNET_YES,
- GNUNET_SCHEDULER_PRIORITY_KEEP,
GNUNET_SCHEDULER_NO_TASK,
&finish_cleanup, sock);
}
GNUNET_assert (conn->msg_complete == GNUNET_NO);
if (GNUNET_SYSERR == conn->in_receive)
GNUNET_SCHEDULER_add_after (conn->sched,
- GNUNET_YES,
- GNUNET_SCHEDULER_PRIORITY_KEEP,
GNUNET_SCHEDULER_NO_TASK,
&finish_cleanup, conn);
conn->in_receive = GNUNET_NO;
if (GNUNET_SYSERR == sock->in_receive)
GNUNET_SCHEDULER_add_after (sock->sched,
- GNUNET_YES,
- GNUNET_SCHEDULER_PRIORITY_KEEP,
GNUNET_SCHEDULER_NO_TASK,
&finish_cleanup, sock);
sock->in_receive = GNUNET_NO;
sock->in_receive = GNUNET_YES;
if (GNUNET_YES == sock->msg_complete)
GNUNET_SCHEDULER_add_after (sock->sched,
- GNUNET_YES,
- GNUNET_SCHEDULER_PRIORITY_KEEP,
GNUNET_SCHEDULER_NO_TASK,
&receive_task, sock);
else
GNUNET_SCHEDULER_Task task, void *task_cls)
{
GNUNET_SCHEDULER_add_continuation (s,
- GNUNET_YES,
task,
task_cls,
GNUNET_SCHEDULER_REASON_TIMEOUT);
"Received confirmation that service is running.\n");
#endif
GNUNET_SCHEDULER_add_continuation (conn->sched,
- GNUNET_YES,
conn->test_cb,
conn->test_cb_cls,
GNUNET_SCHEDULER_REASON_PREREQ_DONE);
GNUNET_assert (NULL != th->sock->sock);
delay = GNUNET_TIME_relative_min (delay, GNUNET_TIME_UNIT_SECONDS);
th->task = GNUNET_SCHEDULER_add_delayed (th->sock->sched,
- GNUNET_NO,
- GNUNET_SCHEDULER_PRIORITY_KEEP,
- GNUNET_SCHEDULER_NO_TASK,
delay,
&client_delayed_retry, th);
th->sock->th = th;
"Destroy waits for write_task to be done (%p)\n", sock);
#endif
GNUNET_SCHEDULER_add_after (sock->sched,
- GNUNET_YES,
- GNUNET_SCHEDULER_PRIORITY_KEEP,
sock->write_task,
&destroy_continuation, sock);
return;
if (sock->read_task != GNUNET_SCHEDULER_NO_TASK)
{
GNUNET_SCHEDULER_add_after (sock->sched,
- GNUNET_YES,
- GNUNET_SCHEDULER_PRIORITY_KEEP,
sock->read_task,
&destroy_continuation, sock);
return;
#endif
h->ccs -= COCO_RECEIVE_AGAIN;
h->read_task = GNUNET_SCHEDULER_add_after (h->sched,
- GNUNET_NO,
- GNUNET_SCHEDULER_PRIORITY_KEEP,
GNUNET_SCHEDULER_NO_TASK,
&receive_again, h);
}
h->nth.timeout_task = GNUNET_SCHEDULER_NO_TASK;
h->ccs -= COCO_TRANSMIT_READY;
h->write_task = GNUNET_SCHEDULER_add_after (h->sched,
- GNUNET_NO,
- GNUNET_SCHEDULER_PRIORITY_KEEP,
GNUNET_SCHEDULER_NO_TASK,
&transmit_ready, h);
}
#endif
h->ccs -= COCO_DESTROY_CONTINUATION;
GNUNET_SCHEDULER_add_continuation (h->sched,
- GNUNET_NO,
&destroy_continuation,
h, GNUNET_SCHEDULER_REASON_TIMEOUT);
}
#endif
h->ccs -= COCO_RECEIVE_AGAIN;
h->read_task = GNUNET_SCHEDULER_add_after (h->sched,
- GNUNET_NO,
- GNUNET_SCHEDULER_PRIORITY_KEEP,
GNUNET_SCHEDULER_NO_TASK,
&receive_again, h);
}
h->ccs -= COCO_TRANSMIT_READY;
h->write_task =
GNUNET_SCHEDULER_add_write_net (h->sched,
- GNUNET_NO,
- GNUNET_SCHEDULER_PRIORITY_KEEP,
- GNUNET_SCHEDULER_NO_TASK,
GNUNET_TIME_absolute_get_remaining
(h->nth.transmit_timeout), h->sock,
&transmit_ready, h);
#endif
h->ccs -= COCO_DESTROY_CONTINUATION;
GNUNET_SCHEDULER_add_continuation (h->sched,
- GNUNET_NO,
&destroy_continuation,
h,
GNUNET_SCHEDULER_REASON_PREREQ_DONE);
GNUNET_TIME_absolute_get_remaining (h->
receive_timeout));
ap->task =
- GNUNET_SCHEDULER_add_write_net (h->sched, GNUNET_NO,
- GNUNET_SCHEDULER_PRIORITY_KEEP,
- GNUNET_SCHEDULER_NO_TASK, delay, ap->sock,
+ GNUNET_SCHEDULER_add_write_net (h->sched,
+ delay, ap->sock,
&connect_probe_continuation, ap);
}
}
GNUNET_assert (sock->sched != NULL);
GNUNET_SCHEDULER_add_after (sock->sched,
- GNUNET_YES,
- GNUNET_SCHEDULER_PRIORITY_KEEP,
GNUNET_SCHEDULER_NO_TASK,
&destroy_continuation, sock);
}
GNUNET_assert (sh->sock != NULL);
/* connect succeeded, wait for data! */
sh->read_task = GNUNET_SCHEDULER_add_read_net (tc->sched,
- GNUNET_YES,
- GNUNET_SCHEDULER_PRIORITY_KEEP,
- GNUNET_SCHEDULER_NO_TASK,
GNUNET_TIME_absolute_get_remaining
(sh->receive_timeout),
sh->sock,
if (sock->write_task == GNUNET_SCHEDULER_NO_TASK)
sock->write_task =
GNUNET_SCHEDULER_add_write_net (tc->sched,
- GNUNET_NO,
- GNUNET_SCHEDULER_PRIORITY_KEEP,
- GNUNET_SCHEDULER_NO_TASK,
GNUNET_TIME_absolute_get_remaining
(sock->nth.transmit_timeout),
sock->sock, &transmit_ready, sock);
(sock->ap_head == NULL) && (sock->dns_active == NULL))
{
sock->write_task = GNUNET_SCHEDULER_add_delayed (sock->sched,
- GNUNET_NO,
- GNUNET_SCHEDULER_PRIORITY_KEEP,
- GNUNET_SCHEDULER_NO_TASK,
GNUNET_TIME_UNIT_ZERO,
&connect_error, sock);
return &sock->nth;
"Scheduling transmit_ready (%p).\n", sock);
#endif
sock->write_task = GNUNET_SCHEDULER_add_write_net (sock->sched,
- GNUNET_NO,
- GNUNET_SCHEDULER_PRIORITY_KEEP,
- GNUNET_SCHEDULER_NO_TASK,
GNUNET_TIME_absolute_get_remaining
(sock->nth.
transmit_timeout),
#endif
sock->ccs |= COCO_TRANSMIT_READY;
sock->nth.timeout_task = GNUNET_SCHEDULER_add_delayed (sock->sched,
- GNUNET_NO,
- GNUNET_SCHEDULER_PRIORITY_KEEP,
- GNUNET_SCHEDULER_NO_TASK,
timeout,
&transmit_timeout,
sock);
*/
uint64_t offset;
- /**
- * Run on shutdown?
- */
- int run_on_shutdown;
-
/**
* File descriptor.
*/
return;
}
GNUNET_SCHEDULER_add_after (tc->sched,
- fhc->run_on_shutdown,
- GNUNET_SCHEDULER_PRIORITY_KEEP,
GNUNET_SCHEDULER_NO_TASK, &file_hash_task, fhc);
}
*
* @param sched scheduler to use
* @param priority scheduling priority to use
- * @param run_on_shutdown should we complete even on shutdown?
* @param filename name of file to hash
* @param blocksize number of bytes to process in one task
* @param callback function to call upon completion
void
GNUNET_CRYPTO_hash_file (struct GNUNET_SCHEDULER_Handle *sched,
enum GNUNET_SCHEDULER_Priority priority,
- int run_on_shutdown,
const char *filename,
size_t blocksize,
GNUNET_CRYPTO_HashCompletedCallback callback,
file_hash_finish (fhc, NULL);
return;
}
- fhc->run_on_shutdown = run_on_shutdown;
fhc->fh = GNUNET_DISK_file_open (filename,
GNUNET_DISK_OPEN_READ,
GNUNET_DISK_PERM_NONE);
file_hash_finish (fhc, NULL);
return;
}
- GNUNET_SCHEDULER_add_after (sched,
- run_on_shutdown,
- priority,
- GNUNET_SCHEDULER_NO_TASK, &file_hash_task, fhc);
+ GNUNET_SCHEDULER_add_with_priority (sched, priority, &file_hash_task, fhc);
}
GNUNET_DISK_directory_iterator_next (iter, GNUNET_YES);
return GNUNET_NO;
}
- GNUNET_SCHEDULER_add_after (iter->sched,
- GNUNET_YES,
- iter->priority,
- GNUNET_SCHEDULER_NO_TASK,
- &directory_iterator_task, iter);
+ GNUNET_SCHEDULER_add_with_priority (iter->sched,
+ iter->priority,
+ &directory_iterator_task, iter);
return GNUNET_YES;
}
ret = (GNUNET_OK ==
GNUNET_SERVICE_run (argc,
argv,
- "resolver", &run, NULL, NULL, NULL)) ? 0 : 1;
+ "resolver", &run, NULL)) ? 0 : 1;
while (head != NULL)
{
((domain == AF_INET6) || (domain == AF_UNSPEC))))
{
rh->task = GNUNET_SCHEDULER_add_delayed (sched,
- GNUNET_NO,
- GNUNET_SCHEDULER_PRIORITY_KEEP,
- GNUNET_SCHEDULER_NO_TASK,
GNUNET_TIME_UNIT_ZERO,
&numeric_resolution, rh);
return rh;
if (0 == strcasecmp (loopback[i++], hostname))
{
rh->task = GNUNET_SCHEDULER_add_delayed (sched,
- GNUNET_NO,
- GNUNET_SCHEDULER_PRIORITY_KEEP,
- GNUNET_SCHEDULER_NO_TASK,
GNUNET_TIME_UNIT_ZERO,
&loopback_resolution, rh);
return rh;
if (GNUNET_NO == do_resolve)
{
rh->task = GNUNET_SCHEDULER_add_delayed (sched,
- GNUNET_NO,
- GNUNET_SCHEDULER_PRIORITY_KEEP,
- GNUNET_SCHEDULER_NO_TASK,
GNUNET_TIME_UNIT_ZERO,
&numeric_reverse, rh);
return rh;
*/
enum GNUNET_SCHEDULER_Priority priority;
- /**
- * Should this task be run on shutdown?
- */
- int run_on_shutdown;
-
};
*/
GNUNET_SCHEDULER_TaskIdentifier lowest_pending_id;
- /**
- * GNUNET_NO if we are running normally,
- * GNUNET_YES if we are in shutdown mode.
- */
- int shutdown;
-
/**
* Number of tasks on the ready list.
*/
GNUNET_NETWORK_fdset_add (rs, pos->read_set);
if (pos->write_set != NULL)
GNUNET_NETWORK_fdset_add (ws, pos->write_set);
+ if (pos->reason != 0)
+ *timeout = GNUNET_TIME_UNIT_ZERO;
pos = pos->next;
}
}
const struct GNUNET_NETWORK_FDSet *rs,
const struct GNUNET_NETWORK_FDSet *ws)
{
- if ((GNUNET_NO == task->run_on_shutdown) && (GNUNET_YES == sched->shutdown))
- return GNUNET_NO;
- if ((GNUNET_YES == task->run_on_shutdown) &&
- (GNUNET_YES == sched->shutdown))
- task->reason |= GNUNET_SCHEDULER_REASON_SHUTDOWN;
- if (now.value >= task->timeout.value)
+ if (now.value >= task->timeout.value)
task->reason |= GNUNET_SCHEDULER_REASON_TIMEOUT;
if ((0 == (task->reason & GNUNET_SCHEDULER_REASON_READ_READY)) &&
(rs != NULL) && (set_overlaps (rs, task->read_set)))
}
+/**
+ * Request the shutdown of a scheduler. Marks all currently
+ * pending tasks as ready because of shutdown. This will
+ * cause all tasks to run (as soon as possible, respecting
+ * priorities and prerequisite tasks). Note that tasks
+ * scheduled AFTER this call may still be delayed arbitrarily.
+ *
+ * @param sched the scheduler
+ */
+void
+GNUNET_SCHEDULER_shutdown (struct GNUNET_SCHEDULER_Handle *sched)
+{
+ struct Task *pos;
+
+ pos = sched->pending;
+ while (pos != NULL)
+ {
+ pos->reason |= GNUNET_SCHEDULER_REASON_SHUTDOWN;
+ /* we don't move the task into the ready queue yet; check_ready
+ will do that later, possibly adding additional
+ readyness-factors */
+ pos = pos->next;
+ }
+}
+
+
/**
* Destroy a task (release associated resources)
*
* empty. Keep running tasks until we are either no longer running
* "URGENT" tasks or until we have at least one "pending" task (which
* may become ready, hence we should select on it). Naturally, if
- * there are no more ready tasks, we also return.
+ * there are no more ready tasks, we also return.
*
* @param sched the scheduler
*/
while ((sched->pending == NULL) || (p == GNUNET_SCHEDULER_PRIORITY_URGENT));
}
-
+#ifndef MINGW
/**
* Pipe used to communicate shutdown via signal.
*/
(sigpipe, GNUNET_DISK_PIPE_END_WRITE), &c,
sizeof (c));
}
+#endif
/**
- * Initialize a scheduler using this thread. This function will
- * return when either a shutdown was initiated (via signal) and all
- * tasks marked to "run_on_shutdown" have been completed or when all
- * tasks in general have been completed.
+ * Initialize and run scheduler. This function will return when all
+ * tasks have completed. On systems with signals, receiving a SIGTERM
+ * (and other similar signals) will cause "GNUNET_SCHEDULER_shutdown"
+ * to be run after the active task is complete. As a result, SIGTERM
+ * causes all active tasks to be scheduled with reason
+ * "GNUNET_SCHEDULER_REASON_SHUTDOWN". (However, tasks added
+ * afterwards will execute normally!). Note that any particular signal
+ * will only shut down one scheduler; applications should always only
+ * create a single scheduler.
*
* @param task task to run immediately
- * @param cls closure of task
+ * @param task_cls closure of task
*/
void
-GNUNET_SCHEDULER_run (GNUNET_SCHEDULER_Task task, void *cls)
+GNUNET_SCHEDULER_run (GNUNET_SCHEDULER_Task task, void *task_cls)
{
struct GNUNET_SCHEDULER_Handle sched;
struct GNUNET_NETWORK_FDSet *rs;
struct GNUNET_SIGNAL_Context *shc_term;
struct GNUNET_SIGNAL_Context *shc_quit;
struct GNUNET_SIGNAL_Context *shc_hup;
- struct Task *tpos;
unsigned long long last_tr;
unsigned int busy_wait_warning;
#ifndef MINGW
const struct GNUNET_DISK_FileHandle *pr;
#endif
+ char c;
rs = GNUNET_NETWORK_fdset_create ();
ws = GNUNET_NETWORK_fdset_create ();
GNUNET_assert (sigpipe != NULL);
pr = GNUNET_DISK_pipe_handle (sigpipe, GNUNET_DISK_PIPE_END_READ);
GNUNET_assert (pr != NULL);
- shc_int = GNUNET_SIGNAL_handler_install (SIGINT, &sighandler_shutdown);
+ shc_int = GNUNET_SIGNAL_handler_install (SIGINT, &sighandler_shutdown);
shc_term = GNUNET_SIGNAL_handler_install (SIGTERM, &sighandler_shutdown);
shc_quit = GNUNET_SIGNAL_handler_install (SIGQUIT, &sighandler_shutdown);
- shc_hup = GNUNET_SIGNAL_handler_install (SIGHUP, &sighandler_shutdown);
+ shc_hup = GNUNET_SIGNAL_handler_install (SIGHUP, &sighandler_shutdown);
#endif
memset (&sched, 0, sizeof (sched));
sched.current_priority = GNUNET_SCHEDULER_PRIORITY_DEFAULT;
GNUNET_SCHEDULER_add_continuation (&sched,
- GNUNET_YES,
task,
- cls, GNUNET_SCHEDULER_REASON_STARTUP);
+ task_cls,
+ GNUNET_SCHEDULER_REASON_STARTUP);
last_tr = 0;
busy_wait_warning = 0;
- while ((GNUNET_NO == sched.shutdown) &&
- ((sched.pending != NULL) || (sched.ready_count > 0)))
+ while ( (sched.pending != NULL) || (sched.ready_count > 0) )
{
GNUNET_NETWORK_fdset_zero (rs);
GNUNET_NETWORK_fdset_zero (ws);
- timeout = GNUNET_TIME_relative_get_forever ();
+ timeout = GNUNET_TIME_UNIT_FOREVER_REL;
update_sets (&sched, rs, ws, &timeout);
-#ifndef MINGW
GNUNET_NETWORK_fdset_handle_set (rs, pr);
-#endif
if (sched.ready_count > 0)
{
/* no blocking, more work already ready! */
- timeout = GNUNET_TIME_relative_get_zero ();
+ timeout = GNUNET_TIME_UNIT_ZERO;
}
ret = GNUNET_NETWORK_socket_select (rs, ws, NULL, timeout);
#ifndef MINGW
if (GNUNET_NETWORK_fdset_handle_isset (rs, pr))
- break;
+ {
+ /* consume the signal */
+ GNUNET_DISK_file_read (pr, &c, sizeof(c));
+ /* mark all active tasks as ready due to shutdown */
+ GNUNET_SCHEDULER_shutdown (&sched);
+ }
#endif
if (last_tr == sched.tasks_run)
{
check_ready (&sched, rs, ws);
run_ready (&sched);
}
- sched.shutdown = GNUNET_YES;
#ifndef MINGW
GNUNET_SIGNAL_handler_uninstall (shc_int);
GNUNET_SIGNAL_handler_uninstall (shc_term);
GNUNET_DISK_pipe_close (sigpipe);
sigpipe = NULL;
#endif
- do
- {
- run_ready (&sched);
- check_ready (&sched, NULL, NULL);
- }
- while (sched.ready_count > 0);
- while (NULL != (tpos = sched.pending))
- {
- sched.pending = tpos->next;
- GNUNET_free (tpos);
- }
GNUNET_NETWORK_fdset_destroy (rs);
GNUNET_NETWORK_fdset_destroy (ws);
}
-/**
- * Request the shutdown of a scheduler. This function can be used to
- * stop a scheduling thread when created with the
- * "GNUNET_SCHEDULER_init_thread" function or from within the signal
- * handler for signals causing shutdowns.
- *
- * @param sched the scheduler
- */
-void
-GNUNET_SCHEDULER_shutdown (struct GNUNET_SCHEDULER_Handle *sched)
-{
- sched->shutdown = GNUNET_YES;
-}
-
/**
* Get information about the current load of this scheduler. Use this
* and the reason code can be specified.
*
* @param sched scheduler to use
- * @param run_on_shutdown should this task be run if we are shutting down?
- * @param main main function of the task
- * @param cls closure for 'main'
+ * @param task main function of the task
+ * @param task_cls closure for 'main'
* @param reason reason for task invocation
*/
void
GNUNET_SCHEDULER_add_continuation (struct GNUNET_SCHEDULER_Handle *sched,
- int run_on_shutdown,
- GNUNET_SCHEDULER_Task main,
- void *cls,
+ GNUNET_SCHEDULER_Task task,
+ void *task_cls,
enum GNUNET_SCHEDULER_Reason reason)
{
- struct Task *task;
-
- task = GNUNET_malloc (sizeof (struct Task));
- task->callback = main;
- task->callback_cls = cls;
- task->id = ++sched->last_id;
- task->reason = reason;
- task->priority = sched->current_priority;
- task->run_on_shutdown = run_on_shutdown;
+ struct Task *t;
+
+ t = GNUNET_malloc (sizeof (struct Task));
+ t->callback = task;
+ t->callback_cls = task_cls;
+ t->id = ++sched->last_id;
+ t->reason = reason;
+ t->priority = sched->current_priority;
#if DEBUG_TASKS
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Adding continuation task: %llu / %p\n",
- task->id, task->callback_cls);
+ t->id, t->callback_cls);
#endif
- queue_ready_task (sched, task);
+ queue_ready_task (sched, t);
}
+
/**
- * Schedule a new task to be run after the specified
- * prerequisite task has completed.
+ * Schedule a new task to be run after the specified prerequisite task
+ * has completed. It will be run with the priority of the calling
+ * task.
*
* @param sched scheduler to use
- * @param run_on_shutdown run on shutdown?
- * @param prio how important is this task?
* @param prerequisite_task run this task after the task with the given
* task identifier completes (and any of our other
* conditions, such as delay, read or write-readyness
* are satisfied). Use GNUNET_SCHEDULER_NO_TASK to not have any dependency
- * on completion of other tasks.
- * @param main main function of the task
- * @param cls closure for 'main'
+ * on completion of other tasks (this will cause the task to run as
+ * soon as possible).
+ * @param task main function of the task
+ * @param task_cls closure of task
* @return unique task identifier for the job
- * only valid until "main" is started!
+ * only valid until "task" is started!
*/
GNUNET_SCHEDULER_TaskIdentifier
GNUNET_SCHEDULER_add_after (struct GNUNET_SCHEDULER_Handle *sched,
- int run_on_shutdown,
- enum GNUNET_SCHEDULER_Priority prio,
GNUNET_SCHEDULER_TaskIdentifier prerequisite_task,
- GNUNET_SCHEDULER_Task main, void *cls)
+ GNUNET_SCHEDULER_Task task,
+ void *task_cls)
{
- return GNUNET_SCHEDULER_add_select (sched, run_on_shutdown, prio,
+ return GNUNET_SCHEDULER_add_select (sched,
+ GNUNET_SCHEDULER_PRIORITY_KEEP,
prerequisite_task,
GNUNET_TIME_UNIT_ZERO,
- NULL, NULL, main, cls);
+ NULL, NULL, task, task_cls);
}
+/**
+ * Schedule a new task to be run with a specified priority.
+ *
+ * @param sched scheduler to use
+ * @param prio how important is the new task?
+ * @param task main function of the task
+ * @param task_cls closure of task
+ * @return unique task identifier for the job
+ * only valid until "task" is started!
+ */
+GNUNET_SCHEDULER_TaskIdentifier
+GNUNET_SCHEDULER_add_with_priority (struct GNUNET_SCHEDULER_Handle *sched,
+ enum GNUNET_SCHEDULER_Priority prio,
+ GNUNET_SCHEDULER_Task task,
+ void *task_cls)
+{
+ return GNUNET_SCHEDULER_add_select (sched,
+ prio,
+ GNUNET_SCHEDULER_NO_TASK,
+ GNUNET_TIME_UNIT_ZERO,
+ NULL, NULL, task, task_cls);
+}
+
+
+
/**
* Schedule a new task to be run with a specified delay. The task
- * will be scheduled for execution once the delay has expired and the
- * prerequisite task has completed.
+ * will be scheduled for execution once the delay has expired. It
+ * will be run with the priority of the calling task.
*
* @param sched scheduler to use
- * @param run_on_shutdown run on shutdown? You can use this
- * argument to run a function only during shutdown
- * by setting delay to -1. Set this
- * argument to GNUNET_NO to skip this task if
- * the user requested process termination.
- * @param prio how important is this task?
- * @param prerequisite_task run this task after the task with the given
- * task identifier completes (and any of our other
- * conditions, such as delay, read or write-readyness
- * are satisfied). Use GNUNET_SCHEDULER_NO_TASK to not have any dependency
- * on completion of other tasks.
- * @param delay how long should we wait? Use GNUNET_TIME_UNIT_FOREVER_REL for "forever"
- * @param main main function of the task
- * @param cls closure of task
+ * @param delay when should this operation time out? Use
+ * GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown"
+ * @param task main function of the task
+ * @param task_cls closure of task
* @return unique task identifier for the job
- * only valid until "main" is started!
+ * only valid until "task" is started!
*/
GNUNET_SCHEDULER_TaskIdentifier
-GNUNET_SCHEDULER_add_delayed (struct GNUNET_SCHEDULER_Handle * sched,
- int run_on_shutdown,
- enum GNUNET_SCHEDULER_Priority prio,
- GNUNET_SCHEDULER_TaskIdentifier
- prerequisite_task,
+GNUNET_SCHEDULER_add_delayed (struct GNUNET_SCHEDULER_Handle *sched,
struct GNUNET_TIME_Relative delay,
- GNUNET_SCHEDULER_Task main, void *cls)
+ GNUNET_SCHEDULER_Task task,
+ void *task_cls)
{
- return GNUNET_SCHEDULER_add_select (sched, run_on_shutdown, prio,
- prerequisite_task, delay,
- NULL, NULL, main, cls);
+ return GNUNET_SCHEDULER_add_select (sched,
+ GNUNET_SCHEDULER_PRIORITY_KEEP,
+ GNUNET_SCHEDULER_NO_TASK, delay,
+ NULL, NULL, task, task_cls);
}
* specified file descriptor is ready for reading. The delay can be
* used as a timeout on the socket being ready. The task will be
* scheduled for execution once either the delay has expired or the
- * socket operation is ready.
+ * socket operation is ready. It will be run with the priority of
+ * the calling task.
*
* @param sched scheduler to use
- * @param run_on_shutdown run on shutdown? Set this
- * argument to GNUNET_NO to skip this task if
- * the user requested process termination.
- * @param prio how important is this task?
- * @param prerequisite_task run this task after the task with the given
- * task identifier completes (and any of our other
- * conditions, such as delay, read or write-readyness
- * are satisfied). Use GNUNET_SCHEDULER_NO_TASK to not have any dependency
- * on completion of other tasks.
- * @param delay how long should we wait? Use GNUNET_TIME_UNIT_FOREVER_REL for "forever"
+ * @param delay when should this operation time out? Use
+ * GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown"
* @param rfd read file-descriptor
- * @param main main function of the task
- * @param cls closure of task
+ * @param task main function of the task
+ * @param task_cls closure of task
* @return unique task identifier for the job
- * only valid until "main" is started!
+ * only valid until "task" is started!
*/
GNUNET_SCHEDULER_TaskIdentifier
-GNUNET_SCHEDULER_add_read_net (struct GNUNET_SCHEDULER_Handle * sched,
- int run_on_shutdown,
- enum GNUNET_SCHEDULER_Priority prio,
- GNUNET_SCHEDULER_TaskIdentifier
- prerequisite_task,
- struct GNUNET_TIME_Relative delay,
- struct GNUNET_NETWORK_Handle * rfd,
- GNUNET_SCHEDULER_Task main, void *cls)
+GNUNET_SCHEDULER_add_read_net (struct GNUNET_SCHEDULER_Handle *sched,
+ struct GNUNET_TIME_Relative delay,
+ struct GNUNET_NETWORK_Handle *rfd,
+ GNUNET_SCHEDULER_Task task,
+ void *task_cls)
{
struct GNUNET_NETWORK_FDSet *rs;
GNUNET_SCHEDULER_TaskIdentifier ret;
GNUNET_assert (rfd != NULL);
rs = GNUNET_NETWORK_fdset_create ();
GNUNET_NETWORK_fdset_set (rs, rfd);
- ret = GNUNET_SCHEDULER_add_select (sched, run_on_shutdown, prio,
- prerequisite_task, delay,
- rs, NULL, main, cls);
+ ret = GNUNET_SCHEDULER_add_select (sched,
+ GNUNET_SCHEDULER_PRIORITY_KEEP,
+ GNUNET_SCHEDULER_NO_TASK,
+ delay,
+ rs, NULL, task, task_cls);
GNUNET_NETWORK_fdset_destroy (rs);
return ret;
}
* specified file descriptor is ready for writing. The delay can be
* used as a timeout on the socket being ready. The task will be
* scheduled for execution once either the delay has expired or the
- * socket operation is ready.
+ * socket operation is ready. It will be run with the priority of
+ * the calling task.
*
* @param sched scheduler to use
- * @param run_on_shutdown run on shutdown? Set this
- * argument to GNUNET_NO to skip this task if
- * the user requested process termination.
- * @param prio how important is this task?
- * @param prerequisite_task run this task after the task with the given
- * task identifier completes (and any of our other
- * conditions, such as delay, read or write-readyness
- * are satisfied). Use GNUNET_SCHEDULER_NO_TASK to not have any dependency
- * on completion of other tasks.
- * @param delay how long should we wait? Use GNUNET_TIME_UNIT_FOREVER_REL for "forever"
+ * @param delay when should this operation time out? Use
+ * GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown"
* @param wfd write file-descriptor
- * @param main main function of the task
- * @param cls closure of task
+ * @param task main function of the task
+ * @param task_cls closure of task
* @return unique task identifier for the job
- * only valid until "main" is started!
+ * only valid until "task" is started!
*/
GNUNET_SCHEDULER_TaskIdentifier
-GNUNET_SCHEDULER_add_write_net (struct GNUNET_SCHEDULER_Handle * sched,
- int run_on_shutdown,
- enum GNUNET_SCHEDULER_Priority prio,
- GNUNET_SCHEDULER_TaskIdentifier
- prerequisite_task,
- struct GNUNET_TIME_Relative delay,
- struct GNUNET_NETWORK_Handle * wfd,
- GNUNET_SCHEDULER_Task main, void *cls)
+GNUNET_SCHEDULER_add_write_net (struct GNUNET_SCHEDULER_Handle *sched,
+ struct GNUNET_TIME_Relative delay,
+ struct GNUNET_NETWORK_Handle *wfd,
+ GNUNET_SCHEDULER_Task task,
+ void *task_cls)
{
struct GNUNET_NETWORK_FDSet *ws;
GNUNET_SCHEDULER_TaskIdentifier ret;
GNUNET_assert (wfd != NULL);
ws = GNUNET_NETWORK_fdset_create ();
GNUNET_NETWORK_fdset_set (ws, wfd);
- ret = GNUNET_SCHEDULER_add_select (sched, run_on_shutdown, prio,
- prerequisite_task, delay,
- NULL, ws, main, cls);
+ ret = GNUNET_SCHEDULER_add_select (sched,
+ GNUNET_SCHEDULER_PRIORITY_KEEP,
+ GNUNET_SCHEDULER_NO_TASK, delay,
+ NULL, ws, task, task_cls);
+ GNUNET_NETWORK_fdset_destroy (ws);
+ return ret;
+}
+
+
+/**
+ * Schedule a new task to be run with a specified delay or when the
+ * specified file descriptor is ready for reading. The delay can be
+ * used as a timeout on the socket being ready. The task will be
+ * scheduled for execution once either the delay has expired or the
+ * socket operation is ready. It will be run with the priority of
+ * the calling task.
+ *
+ * @param sched scheduler to use
+ * @param delay when should this operation time out? Use
+ * GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown"
+ * @param rfd read file-descriptor
+ * @param task main function of the task
+ * @param task_cls closure of task
+ * @return unique task identifier for the job
+ * only valid until "task" is started!
+ */
+GNUNET_SCHEDULER_TaskIdentifier
+GNUNET_SCHEDULER_add_read_file (struct GNUNET_SCHEDULER_Handle *sched,
+ struct GNUNET_TIME_Relative delay,
+ const struct GNUNET_DISK_FileHandle *rfd,
+ GNUNET_SCHEDULER_Task task,
+ void *task_cls)
+{
+ struct GNUNET_NETWORK_FDSet *rs;
+ GNUNET_SCHEDULER_TaskIdentifier ret;
+
+ GNUNET_assert (rfd != NULL);
+ rs = GNUNET_NETWORK_fdset_create ();
+ GNUNET_NETWORK_fdset_handle_set (rs, rfd);
+ ret = GNUNET_SCHEDULER_add_select (sched,
+ GNUNET_SCHEDULER_PRIORITY_KEEP,
+ GNUNET_SCHEDULER_NO_TASK, delay,
+ rs, NULL, task, task_cls);
+ GNUNET_NETWORK_fdset_destroy (rs);
+ return ret;
+}
+
+
+/**
+ * Schedule a new task to be run with a specified delay or when the
+ * specified file descriptor is ready for writing. The delay can be
+ * used as a timeout on the socket being ready. The task will be
+ * scheduled for execution once either the delay has expired or the
+ * socket operation is ready. It will be run with the priority of
+ * the calling task.
+ *
+ * @param sched scheduler to use
+ * @param delay when should this operation time out? Use
+ * GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown"
+ * @param wfd write file-descriptor
+ * @param task main function of the task
+ * @param task_cls closure of task
+ * @return unique task identifier for the job
+ * only valid until "task" is started!
+ */
+GNUNET_SCHEDULER_TaskIdentifier
+GNUNET_SCHEDULER_add_write_file (struct GNUNET_SCHEDULER_Handle *sched,
+ struct GNUNET_TIME_Relative delay,
+ const struct GNUNET_DISK_FileHandle *wfd,
+ GNUNET_SCHEDULER_Task task,
+ void *task_cls)
+{
+ struct GNUNET_NETWORK_FDSet *ws;
+ GNUNET_SCHEDULER_TaskIdentifier ret;
+
+ GNUNET_assert (wfd != NULL);
+ ws = GNUNET_NETWORK_fdset_create ();
+ GNUNET_NETWORK_fdset_handle_set (ws, wfd);
+ ret = GNUNET_SCHEDULER_add_select (sched,
+ GNUNET_SCHEDULER_PRIORITY_KEEP,
+ GNUNET_SCHEDULER_NO_TASK,
+ delay,
+ NULL, ws, task, task_cls);
GNUNET_NETWORK_fdset_destroy (ws);
return ret;
}
+
/**
* Schedule a new task to be run with a specified delay or when any of
* the specified file descriptor sets is ready. The delay can be used
* </code>
*
* @param sched scheduler to use
- * @param run_on_shutdown run on shutdown? Set this
- * argument to GNUNET_NO to skip this task if
- * the user requested process termination.
* @param prio how important is this task?
* @param prerequisite_task run this task after the task with the given
* task identifier completes (and any of our other
* conditions, such as delay, read or write-readyness
* are satisfied). Use GNUNET_SCHEDULER_NO_TASK to not have any dependency
* on completion of other tasks.
- * @param delay how long should we wait? Use GNUNET_TIME_UNIT_FOREVER_REL for "forever"
+ * @param delay how long should we wait? Use GNUNET_TIME_UNIT_FOREVER_REL for "forever",
+ * which means that the task will only be run after we receive SIGTERM
* @param rs set of file descriptors we want to read (can be NULL)
* @param ws set of file descriptors we want to write (can be NULL)
- * @param main main function of the task
- * @param cls closure of task
+ * @param task main function of the task
+ * @param task_cls closure of task
* @return unique task identifier for the job
- * only valid until "main" is started!
+ * only valid until "task" is started!
*/
GNUNET_SCHEDULER_TaskIdentifier
-GNUNET_SCHEDULER_add_select (struct GNUNET_SCHEDULER_Handle * sched,
- int run_on_shutdown,
+GNUNET_SCHEDULER_add_select (struct GNUNET_SCHEDULER_Handle *sched,
enum GNUNET_SCHEDULER_Priority prio,
GNUNET_SCHEDULER_TaskIdentifier
prerequisite_task,
struct GNUNET_TIME_Relative delay,
const struct GNUNET_NETWORK_FDSet * rs,
- const struct GNUNET_NETWORK_FDSet * ws,
- GNUNET_SCHEDULER_Task main, void *cls)
+ const struct GNUNET_NETWORK_FDSet * ws,
+ GNUNET_SCHEDULER_Task task,
+ void *task_cls)
{
- struct Task *task;
+ struct Task *t;
- task = GNUNET_malloc (sizeof (struct Task));
- task->callback = main;
- task->callback_cls = cls;
+ t = GNUNET_malloc (sizeof (struct Task));
+ t->callback = task;
+ t->callback_cls = task_cls;
if (rs != NULL)
{
- task->read_set = GNUNET_NETWORK_fdset_create ();
- GNUNET_NETWORK_fdset_copy (task->read_set, rs);
+ t->read_set = GNUNET_NETWORK_fdset_create ();
+ GNUNET_NETWORK_fdset_copy (t->read_set, rs);
}
if (ws != NULL)
{
- task->write_set = GNUNET_NETWORK_fdset_create ();
- GNUNET_NETWORK_fdset_copy (task->write_set, ws);
+ t->write_set = GNUNET_NETWORK_fdset_create ();
+ GNUNET_NETWORK_fdset_copy (t->write_set, ws);
}
- task->id = ++sched->last_id;
- task->prereq_id = prerequisite_task;
- task->timeout = GNUNET_TIME_relative_to_absolute (delay);
- task->priority =
+ t->id = ++sched->last_id;
+ t->prereq_id = prerequisite_task;
+ t->timeout = GNUNET_TIME_relative_to_absolute (delay);
+ t->priority =
check_priority ((prio ==
GNUNET_SCHEDULER_PRIORITY_KEEP) ? sched->current_priority
: prio);
- task->run_on_shutdown = run_on_shutdown;
- task->next = sched->pending;
- sched->pending = task;
+ t->next = sched->pending;
+ sched->pending = t;
#if DEBUG_TASKS
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Adding task: %llu / %p\n", task->id, task->callback_cls);
+ "Adding task: %llu / %p\n", t->id, t->callback_cls);
#endif
- return task->id;
+ return t->id;
}
-/**
- * Schedule a new task to be run with a specified delay or when the
- * specified file descriptor is ready for reading. The delay can be
- * used as a timeout on the socket being ready. The task will be
- * scheduled for execution once either the delay has expired or the
- * socket operation is ready.
- *
- * @param sched scheduler to use
- * @param run_on_shutdown run on shutdown? Set this
- * argument to GNUNET_NO to skip this task if
- * the user requested process termination.
- * @param prio how important is this task?
- * @param prerequisite_task run this task after the task with the given
- * task identifier completes (and any of our other
- * conditions, such as delay, read or write-readyness
- * are satisfied). Use GNUNET_SCHEDULER_NO_TASK to not have any dependency
- * on completion of other tasks.
- * @param delay how long should we wait? Use GNUNET_TIME_UNIT_FOREVER_REL for "forever"
- * @param rfd read file-descriptor
- * @param main main function of the task
- * @param cls closure of task
- * @return unique task identifier for the job
- * only valid until "main" is started!
- */
-GNUNET_SCHEDULER_TaskIdentifier
-GNUNET_SCHEDULER_add_read_file (struct GNUNET_SCHEDULER_Handle * sched,
- int run_on_shutdown,
- enum GNUNET_SCHEDULER_Priority prio,
- GNUNET_SCHEDULER_TaskIdentifier
- prerequisite_task,
- struct GNUNET_TIME_Relative delay,
- const struct GNUNET_DISK_FileHandle * rfd,
- GNUNET_SCHEDULER_Task main, void *cls)
-{
- struct GNUNET_NETWORK_FDSet *rs;
- GNUNET_SCHEDULER_TaskIdentifier ret;
-
- GNUNET_assert (rfd != NULL);
- rs = GNUNET_NETWORK_fdset_create ();
- GNUNET_NETWORK_fdset_handle_set (rs, rfd);
- ret = GNUNET_SCHEDULER_add_select (sched, run_on_shutdown, prio,
- prerequisite_task, delay,
- rs, NULL, main, cls);
- GNUNET_NETWORK_fdset_destroy (rs);
- return ret;
-}
-
-
-/**
- * Schedule a new task to be run with a specified delay or when the
- * specified file descriptor is ready for writing. The delay can be
- * used as a timeout on the socket being ready. The task will be
- * scheduled for execution once either the delay has expired or the
- * socket operation is ready.
- *
- * @param sched scheduler to use
- * @param run_on_shutdown run on shutdown? Set this
- * argument to GNUNET_NO to skip this task if
- * the user requested process termination.
- * @param prio how important is this task?
- * @param prerequisite_task run this task after the task with the given
- * task identifier completes (and any of our other
- * conditions, such as delay, read or write-readyness
- * are satisfied). Use GNUNET_SCHEDULER_NO_TASK to not have any dependency
- * on completion of other tasks.
- * @param delay how long should we wait? Use GNUNET_TIME_UNIT_FOREVER_REL for "forever"
- * @param wfd write file-descriptor
- * @param main main function of the task
- * @param cls closure of task
- * @return unique task identifier for the job
- * only valid until "main" is started!
- */
-GNUNET_SCHEDULER_TaskIdentifier
-GNUNET_SCHEDULER_add_write_file (struct GNUNET_SCHEDULER_Handle * sched,
- int run_on_shutdown,
- enum GNUNET_SCHEDULER_Priority prio,
- GNUNET_SCHEDULER_TaskIdentifier
- prerequisite_task,
- struct GNUNET_TIME_Relative delay,
- const struct GNUNET_DISK_FileHandle * wfd,
- GNUNET_SCHEDULER_Task main, void *cls)
-{
- struct GNUNET_NETWORK_FDSet *ws;
- GNUNET_SCHEDULER_TaskIdentifier ret;
-
- GNUNET_assert (wfd != NULL);
- ws = GNUNET_NETWORK_fdset_create ();
- GNUNET_NETWORK_fdset_handle_set (ws, wfd);
- ret = GNUNET_SCHEDULER_add_select (sched, run_on_shutdown, prio,
- prerequisite_task, delay,
- NULL, ws, main, cls);
- GNUNET_NETWORK_fdset_destroy (ws);
- return ret;
-}
-
-
/* end of scheduler.c */
GNUNET_NETWORK_fdset_set (r, server->listen_socket);
GNUNET_NETWORK_fdset_handle_set (r, shutpipe);
GNUNET_SCHEDULER_add_select (server->sched,
- GNUNET_YES,
GNUNET_SCHEDULER_PRIORITY_HIGH,
GNUNET_SCHEDULER_NO_TASK,
GNUNET_TIME_UNIT_FOREVER_REL,
GNUNET_NETWORK_fdset_handle_set (r,
GNUNET_DISK_pipe_handle (ret->shutpipe,
GNUNET_DISK_PIPE_END_READ));
- GNUNET_SCHEDULER_add_select (sched, GNUNET_YES,
+ GNUNET_SCHEDULER_add_select (sched,
GNUNET_SCHEDULER_PRIORITY_HIGH,
GNUNET_SCHEDULER_NO_TASK,
GNUNET_TIME_UNIT_FOREVER_REL, r, NULL,
if (GNUNET_YES != client->shutdown_now)
{
GNUNET_SCHEDULER_add_continuation (client->server->sched,
- GNUNET_NO,
&restart_processing,
client,
GNUNET_SCHEDULER_REASON_PREREQ_DONE);
}
+/**
+ * Task run during shutdown.
+ *
+ * @param cls unused
+ * @param tc unused
+ */
+static void
+shutdown_task (void *cls,
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ struct GNUNET_SERVER_Handle *server = cls;
+
+ GNUNET_SERVER_destroy (server);
+}
+
+
/**
* Initial task for the service.
*/
sctx->ret = GNUNET_SYSERR;
return;
}
+ GNUNET_SCHEDULER_add_delayed (tc->sched,
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ &shutdown_task,
+ sctx->server);
sctx->my_handlers = GNUNET_malloc (sizeof (defhandlers));
memcpy (sctx->my_handlers, defhandlers, sizeof (defhandlers));
i = 0;
GNUNET_free (pif);
}
+
/**
* Run a standard GNUnet service startup sequence (initialize loggers
* and configuration, parse options).
* @param serviceName our service name
* @param task main task of the service
* @param task_cls closure for task
- * @param term termination task of the service
- * @param term_cls closure for term
* @return GNUNET_SYSERR on error, GNUNET_OK
* if we shutdown nicely
*/
char *const *argv,
const char *serviceName,
GNUNET_SERVICE_Main task,
- void *task_cls, GNUNET_SERVICE_Term term, void *term_cls)
+ void *task_cls)
{
char *cfg_fn;
char *loglev;
}
/* shutdown */
- if (term != NULL)
- term (term_cls, sctx.cfg);
if ((do_daemonize == 1) && (sctx.server != NULL))
pid_file_delete (&sctx);
- if (sctx.server != NULL)
- GNUNET_SERVER_destroy (sctx.server);
GNUNET_free_non_null (sctx.my_handlers);
GNUNET_CONFIGURATION_destroy (cfg);
GNUNET_free_non_null (sctx.addr);
while ((sctx->my_handlers[i].callback != NULL))
sctx->my_handlers[i++].callback_cls = sctx;
GNUNET_SERVER_add_handlers (sctx->server, sctx->my_handlers);
-
-
return sctx;
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test prepares to accept\n");
#endif
GNUNET_SCHEDULER_add_read_net (tc->sched,
- GNUNET_NO,
- GNUNET_SCHEDULER_PRIORITY_HIGH,
- GNUNET_SCHEDULER_NO_TASK,
GNUNET_TIME_UNIT_FOREVER_REL,
ls, &run_accept, cls);
}
&make_hello, NULL));
GNUNET_CONNECTION_destroy (csock);
GNUNET_SCHEDULER_add_read_net (tc->sched,
- GNUNET_NO,
- GNUNET_SCHEDULER_PRIORITY_HIGH,
- GNUNET_SCHEDULER_NO_TASK,
GNUNET_TIME_UNIT_FOREVER_REL,
ls, &run_accept, cls);
}
"localhost", PORT, 1024);
GNUNET_assert (csock != NULL);
GNUNET_SCHEDULER_add_read_net (tc->sched,
- GNUNET_NO,
- GNUNET_SCHEDULER_PRIORITY_HIGH,
- GNUNET_SCHEDULER_NO_TASK,
GNUNET_TIME_UNIT_FOREVER_REL,
ls, &run_accept_cancel, cls);
GNUNET_SCHEDULER_add_delayed (tc->sched,
- GNUNET_NO,
- GNUNET_SCHEDULER_PRIORITY_KEEP,
- GNUNET_SCHEDULER_NO_TASK,
GNUNET_TIME_UNIT_SECONDS,
&receive_cancel_task, cls);
}
{
GNUNET_CRYPTO_hash_file (tc->sched,
GNUNET_SCHEDULER_PRIORITY_DEFAULT,
- GNUNET_NO, FILENAME, 1024, &finished_task, cls);
+ FILENAME, 1024, &finished_task, cls);
}
#define VERBOSE GNUNET_NO
-static void
-task2 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
- int *ok = cls;
- GNUNET_assert (2 == *ok);
- (*ok) = 3;
-}
-
static void
task3 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
(*ok) = 4;
}
+
+static void
+task2 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ int *ok = cls;
+ GNUNET_assert (2 == *ok);
+ (*ok) = 3;
+ /* t3 will go before t4: higher priority */
+ GNUNET_SCHEDULER_add_with_priority (tc->sched,
+ GNUNET_SCHEDULER_PRIORITY_UI,
+ &task3, cls);
+}
+
static void
task4 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
GNUNET_assert (GNUNET_NETWORK_fdset_handle_isset (tc->read_ready, fds[0]));
GNUNET_assert (1 == GNUNET_DISK_file_read (fds[0], &c, 1));
(*ok) = 8;
- GNUNET_SCHEDULER_add_after (tc->sched,
- GNUNET_NO,
- GNUNET_SCHEDULER_PRIORITY_UI,
- 0, &taskNeverRun, NULL);
- GNUNET_SCHEDULER_add_after (tc->sched,
- GNUNET_YES,
- GNUNET_SCHEDULER_PRIORITY_IDLE,
- 0, &taskLast, cls);
+ GNUNET_SCHEDULER_add_with_priority (tc->sched,
+ GNUNET_SCHEDULER_PRIORITY_IDLE,
+ &taskLast, cls);
GNUNET_SCHEDULER_shutdown (tc->sched);
}
fds[0] = GNUNET_DISK_pipe_handle (p, GNUNET_DISK_PIPE_END_READ);
fds[1] = GNUNET_DISK_pipe_handle (p, GNUNET_DISK_PIPE_END_WRITE);
GNUNET_SCHEDULER_add_read_file (tc->sched,
- GNUNET_NO,
- GNUNET_SCHEDULER_PRIORITY_DEFAULT,
- GNUNET_SCHEDULER_NO_TASK,
GNUNET_TIME_UNIT_FOREVER_REL,
fds[0], &taskRd, cls);
GNUNET_SCHEDULER_add_write_file (tc->sched,
- GNUNET_NO,
- GNUNET_SCHEDULER_PRIORITY_DEFAULT,
- GNUNET_SCHEDULER_NO_TASK,
GNUNET_TIME_UNIT_FOREVER_REL,
fds[1], &taskWrt, cls);
}
(*ok) = 2;
/* t2 will go first -- prereq for all */
t2 = GNUNET_SCHEDULER_add_after (tc->sched,
- GNUNET_NO,
- GNUNET_SCHEDULER_PRIORITY_IDLE,
GNUNET_SCHEDULER_NO_TASK, &task2, cls);
- /* t3 will go before t4: higher priority */
+ /* t4 will go after t2 ('add after') and after t3 (priority) */
t4 = GNUNET_SCHEDULER_add_after (tc->sched,
- GNUNET_NO,
- GNUNET_SCHEDULER_PRIORITY_IDLE,
t2, &task4, cls);
- GNUNET_SCHEDULER_add_delayed (tc->sched,
- GNUNET_NO,
- GNUNET_SCHEDULER_PRIORITY_DEFAULT,
- t2,
- GNUNET_TIME_relative_get_zero (),
- &task3, cls);
- /* t4 will go first: lower prio, but prereq! */
+ /* t5 will go last (after p4) */
GNUNET_SCHEDULER_add_after (tc->sched,
- GNUNET_NO,
- GNUNET_SCHEDULER_PRIORITY_UI, t4, &task5, cls);
+ t4, &task5, cls);
}
}
+static void
+taskShutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ int *ok = cls;
+ GNUNET_assert (1 == *ok);
+ *ok = 8;
+ GNUNET_SCHEDULER_add_delayed (tc->sched,
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ &taskLast, cls);
+ GNUNET_SCHEDULER_shutdown (tc->sched);
+}
+
+
+/**
+ * Main method, starts scheduler with task1,
+ * checks that "ok" is correct at the end.
+ */
+static int
+checkShutdown ()
+{
+ int ok;
+
+ ok = 1;
+ GNUNET_SCHEDULER_run (&taskShutdown, &ok);
+ return ok;
+}
+
+
static void
taskSig (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
int *ok = cls;
GNUNET_assert (1 == *ok);
*ok = 8;
- GNUNET_SCHEDULER_add_after (tc->sched,
- GNUNET_NO,
- GNUNET_SCHEDULER_PRIORITY_UI,
- 0, &taskNeverRun, NULL);
- GNUNET_SCHEDULER_add_after (tc->sched,
- GNUNET_YES,
- GNUNET_SCHEDULER_PRIORITY_UI,
- 0, &taskLast, cls);
+ GNUNET_SCHEDULER_add_delayed (tc->sched,
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ &taskLast, cls);
+#ifndef MINGW
GNUNET_break (0 == PLIBC_KILL (getpid (), SIGTERM));
+#else
+ GNUNET_SCHEDULER_shutdown (tc->sched);
+#endif
}
}
-
-
static void
taskCancel (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
*ok = 0;
GNUNET_SCHEDULER_cancel (tc->sched,
GNUNET_SCHEDULER_add_after (tc->sched,
- GNUNET_NO,
- GNUNET_SCHEDULER_PRIORITY_UI,
- 0,
+ GNUNET_SCHEDULER_NO_TASK,
&taskNeverRun, NULL));
}
GNUNET_log_setup ("test_scheduler", "WARNING", NULL);
ret += check ();
ret += checkSignal ();
+ ret += checkShutdown ();
ret += checkCancel ();
GNUNET_DISK_pipe_close (p);
return;
}
GNUNET_SCHEDULER_add_delayed (tc->sched,
- GNUNET_NO,
- GNUNET_SCHEDULER_PRIORITY_DEFAULT,
- GNUNET_SCHEDULER_NO_TASK,
GNUNET_TIME_relative_multiply
(GNUNET_TIME_UNIT_MILLISECONDS, i),
&test_task, NULL);
stctx->cb = receiver;
stctx->cb_cls = receiver_cls;
ret = GNUNET_SCHEDULER_add_delayed (sched,
- GNUNET_NO,
- GNUNET_SCHEDULER_PRIORITY_KEEP,
- GNUNET_SCHEDULER_NO_TASK,
timeout, &signal_timeout, stctx);
break;
default:
case 2:
ok++;
GNUNET_SCHEDULER_add_delayed (sched,
- GNUNET_YES,
- GNUNET_SCHEDULER_PRIORITY_KEEP,
- GNUNET_SCHEDULER_NO_TASK,
GNUNET_TIME_relative_multiply
(GNUNET_TIME_UNIT_MILLISECONDS, 50),
&send_done, argclient);
case 4:
ok++;
GNUNET_SCHEDULER_add_delayed (sched,
- GNUNET_YES,
- GNUNET_SCHEDULER_PRIORITY_KEEP,
- GNUNET_SCHEDULER_NO_TASK,
GNUNET_TIME_relative_multiply
(GNUNET_TIME_UNIT_MILLISECONDS, 50),
&server_disconnect, argclient);
case 2:
ok++;
GNUNET_SCHEDULER_add_delayed (sched,
- GNUNET_YES,
- GNUNET_SCHEDULER_PRIORITY_KEEP,
- GNUNET_SCHEDULER_NO_TASK,
GNUNET_TIME_relative_multiply
(GNUNET_TIME_UNIT_MILLISECONDS, 50),
&send_done, argclient);
#include "gnunet_scheduler_lib.h"
#include "gnunet_time_lib.h"
+
#define VERBOSE GNUNET_NO
#define PORT 12435
static struct GNUNET_SERVICE_Context *sctx;
+static int ok = 1;
+
+
static void
end_it (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down service\n");
GNUNET_CLIENT_service_shutdown (client);
- if (sctx != NULL)
+ if (sctx != NULL)
GNUNET_SERVICE_stop (sctx);
+ else
+ GNUNET_SCHEDULER_shutdown (sched);
+ ok = 0;
}
msg->type = htons (MY_TYPE);
msg->size = htons (sizeof (struct GNUNET_MessageHeader));
GNUNET_SCHEDULER_add_continuation (sched,
- GNUNET_YES,
&end_it,
client,
GNUNET_SCHEDULER_REASON_PREREQ_DONE);
{NULL, NULL, 0, 0}
};
+
+
+
static void
runner (void *cls,
struct GNUNET_SCHEDULER_Handle *sched,
(void *) cfg);
}
-static void
-term (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
-{
- int *ok = cls;
- *ok = 0;
-}
/**
* Main method, starts scheduler with task1,
static int
check ()
{
- int ok = 1;
+ ok = 1;
char *const argv[] = {
"test_service",
"-c",
GNUNET_SERVICE_run (5,
argv,
"test_service",
- &runner, &ok, &term, &ok));
+ &runner, &ok));
GNUNET_assert (0 == ok);
return ok;
}
-static void
+static void
ready6 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
const struct GNUNET_CONFIGURATION_Handle *cfg = cls;
static int
check6 ()
{
- int ok = 1;
char *const argv[] = {
"test_service6",
"-c",
GNUNET_SERVICE_run (5,
argv,
"test_service6",
- &runner6, &ok, &term, &ok));
+ &runner6, &ok));
GNUNET_assert (0 == ok);
return ok;
}
static int
check6d ()
{
- int ok = 1;
+ ok = 1;
char *const argv[] = {
"test_service6",
"-c",
GNUNET_SERVICE_run (6,
argv,
"test_service6",
- &runner6, &ok, &term, &ok));
+ &runner6, &ok));
GNUNET_break (0 == ok);
return ok;
}