diff options
Diffstat (limited to 'src/util')
27 files changed, 893 insertions, 642 deletions
diff --git a/src/util/bandwidth.c b/src/util/bandwidth.c index 2df2a9449..364c46977 100644 --- a/src/util/bandwidth.c +++ b/src/util/bandwidth.c | |||
@@ -149,7 +149,6 @@ excess_trigger (void *cls) | |||
149 | struct GNUNET_BANDWIDTH_Tracker *av = cls; | 149 | struct GNUNET_BANDWIDTH_Tracker *av = cls; |
150 | 150 | ||
151 | av->excess_task = NULL; | 151 | av->excess_task = NULL; |
152 | |||
153 | if (NULL != av->excess_cb) | 152 | if (NULL != av->excess_cb) |
154 | av->excess_cb (av->excess_cb_cls); | 153 | av->excess_cb (av->excess_cb_cls); |
155 | } | 154 | } |
diff --git a/src/util/client.c b/src/util/client.c index f93fd1d10..d00e8bbd0 100644 --- a/src/util/client.c +++ b/src/util/client.c | |||
@@ -578,7 +578,7 @@ receive_helper (void *cls, | |||
578 | /** | 578 | /** |
579 | * Continuation to call the receive callback. | 579 | * Continuation to call the receive callback. |
580 | * | 580 | * |
581 | * @param cls our handle to the client connection | 581 | * @param cls our handle to the client connection |
582 | */ | 582 | */ |
583 | static void | 583 | static void |
584 | receive_task (void *cls) | 584 | receive_task (void *cls) |
@@ -611,7 +611,8 @@ receive_task (void *cls) | |||
611 | GNUNET_assert (GNUNET_YES == client->msg_complete); | 611 | GNUNET_assert (GNUNET_YES == client->msg_complete); |
612 | GNUNET_assert (client->received_pos >= msize); | 612 | GNUNET_assert (client->received_pos >= msize); |
613 | memcpy (msg, cmsg, msize); | 613 | memcpy (msg, cmsg, msize); |
614 | memmove (client->received_buf, &client->received_buf[msize], | 614 | memmove (client->received_buf, |
615 | &client->received_buf[msize], | ||
615 | client->received_pos - msize); | 616 | client->received_pos - msize); |
616 | client->received_pos -= msize; | 617 | client->received_pos -= msize; |
617 | client->msg_complete = GNUNET_NO; | 618 | client->msg_complete = GNUNET_NO; |
@@ -655,7 +656,8 @@ GNUNET_CLIENT_receive (struct GNUNET_CLIENT_Connection *client, | |||
655 | (GNUNET_SYSERR == client->in_receive) ) | 656 | (GNUNET_SYSERR == client->in_receive) ) |
656 | { | 657 | { |
657 | GNUNET_assert (NULL == client->receive_task); | 658 | GNUNET_assert (NULL == client->receive_task); |
658 | client->receive_task = GNUNET_SCHEDULER_add_now (&receive_task, client); | 659 | client->receive_task = GNUNET_SCHEDULER_add_now (&receive_task, |
660 | client); | ||
659 | return; | 661 | return; |
660 | } | 662 | } |
661 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 663 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
@@ -703,7 +705,7 @@ struct GNUNET_CLIENT_TestHandle | |||
703 | /** | 705 | /** |
704 | * ID of task used for asynchronous operations. | 706 | * ID of task used for asynchronous operations. |
705 | */ | 707 | */ |
706 | struct GNUNET_SCHEDULER_Task * task; | 708 | struct GNUNET_SCHEDULER_Task *task; |
707 | 709 | ||
708 | /** | 710 | /** |
709 | * Final result to report back (once known). | 711 | * Final result to report back (once known). |
@@ -1081,19 +1083,9 @@ static void | |||
1081 | client_delayed_retry (void *cls) | 1083 | client_delayed_retry (void *cls) |
1082 | { | 1084 | { |
1083 | struct GNUNET_CLIENT_TransmitHandle *th = cls; | 1085 | struct GNUNET_CLIENT_TransmitHandle *th = cls; |
1084 | const struct GNUNET_SCHEDULER_TaskContext *tc; | ||
1085 | struct GNUNET_TIME_Relative delay; | 1086 | struct GNUNET_TIME_Relative delay; |
1086 | 1087 | ||
1087 | th->reconnect_task = NULL; | 1088 | th->reconnect_task = NULL; |
1088 | tc = GNUNET_SCHEDULER_get_task_context (); | ||
1089 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | ||
1090 | { | ||
1091 | /* give up, was shutdown */ | ||
1092 | th->client->th = NULL; | ||
1093 | th->notify (th->notify_cls, 0, NULL); | ||
1094 | GNUNET_free (th); | ||
1095 | return; | ||
1096 | } | ||
1097 | th->client->connection = | 1089 | th->client->connection = |
1098 | do_connect (th->client->service_name, | 1090 | do_connect (th->client->service_name, |
1099 | th->client->cfg, | 1091 | th->client->cfg, |
@@ -1112,13 +1104,16 @@ client_delayed_retry (void *cls) | |||
1112 | GNUNET_assert (NULL == th->th); | 1104 | GNUNET_assert (NULL == th->th); |
1113 | GNUNET_assert (NULL == th->reconnect_task); | 1105 | GNUNET_assert (NULL == th->reconnect_task); |
1114 | th->reconnect_task = | 1106 | th->reconnect_task = |
1115 | GNUNET_SCHEDULER_add_delayed (delay, &client_delayed_retry, th); | 1107 | GNUNET_SCHEDULER_add_delayed (delay, |
1108 | &client_delayed_retry, | ||
1109 | th); | ||
1116 | return; | 1110 | return; |
1117 | } | 1111 | } |
1118 | th->th = | 1112 | th->th = |
1119 | GNUNET_CONNECTION_notify_transmit_ready (th->client->connection, th->size, | 1113 | GNUNET_CONNECTION_notify_transmit_ready (th->client->connection, th->size, |
1120 | GNUNET_TIME_absolute_get_remaining | 1114 | GNUNET_TIME_absolute_get_remaining |
1121 | (th->timeout), &client_notify, | 1115 | (th->timeout), |
1116 | &client_notify, | ||
1122 | th); | 1117 | th); |
1123 | if (NULL == th->th) | 1118 | if (NULL == th->th) |
1124 | { | 1119 | { |
@@ -1149,22 +1144,18 @@ client_notify (void *cls, | |||
1149 | struct GNUNET_CLIENT_Connection *client = th->client; | 1144 | struct GNUNET_CLIENT_Connection *client = th->client; |
1150 | size_t ret; | 1145 | size_t ret; |
1151 | struct GNUNET_TIME_Relative delay; | 1146 | struct GNUNET_TIME_Relative delay; |
1152 | const struct GNUNET_SCHEDULER_TaskContext *tc; | ||
1153 | |||
1154 | 1147 | ||
1155 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1148 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1156 | "client_notify is running\n"); | 1149 | "client_notify is running\n"); |
1157 | th->th = NULL; | 1150 | th->th = NULL; |
1158 | client->th = NULL; | 1151 | client->th = NULL; |
1159 | tc = GNUNET_SCHEDULER_get_task_context (); | ||
1160 | if (NULL == buf) | 1152 | if (NULL == buf) |
1161 | { | 1153 | { |
1162 | delay = GNUNET_TIME_absolute_get_remaining (th->timeout); | 1154 | delay = GNUNET_TIME_absolute_get_remaining (th->timeout); |
1163 | delay.rel_value_us /= 2; | 1155 | delay.rel_value_us /= 2; |
1164 | if ( (GNUNET_YES != th->auto_retry) || | 1156 | if ( (GNUNET_YES != th->auto_retry) || |
1165 | (0 == --th->attempts_left) || | 1157 | (0 == --th->attempts_left) || |
1166 | (delay.rel_value_us < 1)|| | 1158 | (delay.rel_value_us < 1) ) |
1167 | (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))) | ||
1168 | { | 1159 | { |
1169 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1160 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1170 | "Transmission failed %u times, giving up.\n", | 1161 | "Transmission failed %u times, giving up.\n", |
@@ -1198,7 +1189,9 @@ client_notify (void *cls, | |||
1198 | GNUNET_assert (NULL == th->reconnect_task); | 1189 | GNUNET_assert (NULL == th->reconnect_task); |
1199 | GNUNET_assert (NULL == th->th); | 1190 | GNUNET_assert (NULL == th->th); |
1200 | th->reconnect_task = | 1191 | th->reconnect_task = |
1201 | GNUNET_SCHEDULER_add_delayed (delay, &client_delayed_retry, th); | 1192 | GNUNET_SCHEDULER_add_delayed (delay, |
1193 | &client_delayed_retry, | ||
1194 | th); | ||
1202 | return 0; | 1195 | return 0; |
1203 | } | 1196 | } |
1204 | GNUNET_assert (size >= th->size); | 1197 | GNUNET_assert (size >= th->size); |
diff --git a/src/util/client_manager.c b/src/util/client_manager.c index f334bb5b6..026837841 100644 --- a/src/util/client_manager.c +++ b/src/util/client_manager.c | |||
@@ -243,8 +243,10 @@ static void | |||
243 | schedule_disconnect (void *cls) | 243 | schedule_disconnect (void *cls) |
244 | { | 244 | { |
245 | struct GNUNET_CLIENT_MANAGER_Connection *mgr = cls; | 245 | struct GNUNET_CLIENT_MANAGER_Connection *mgr = cls; |
246 | |||
246 | GNUNET_CLIENT_MANAGER_disconnect (mgr, GNUNET_NO, | 247 | GNUNET_CLIENT_MANAGER_disconnect (mgr, GNUNET_NO, |
247 | mgr->disconnect_cb, mgr->disconnect_cls); | 248 | mgr->disconnect_cb, |
249 | mgr->disconnect_cls); | ||
248 | } | 250 | } |
249 | 251 | ||
250 | 252 | ||
@@ -263,9 +265,10 @@ schedule_disconnect (void *cls) | |||
263 | static size_t | 265 | static size_t |
264 | send_next_message (void *cls, size_t buf_size, void *buf) | 266 | send_next_message (void *cls, size_t buf_size, void *buf) |
265 | { | 267 | { |
266 | LOG (GNUNET_ERROR_TYPE_DEBUG, "send_next_message()\n"); | ||
267 | struct GNUNET_CLIENT_MANAGER_Connection *mgr = cls; | 268 | struct GNUNET_CLIENT_MANAGER_Connection *mgr = cls; |
268 | 269 | ||
270 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
271 | "send_next_message()\n"); | ||
269 | if (NULL == buf) | 272 | if (NULL == buf) |
270 | { | 273 | { |
271 | /* disconnected */ | 274 | /* disconnected */ |
@@ -282,7 +285,9 @@ send_next_message (void *cls, size_t buf_size, void *buf) | |||
282 | GNUNET_assert (size <= buf_size); | 285 | GNUNET_assert (size <= buf_size); |
283 | memcpy (buf, mqi->msg, size); | 286 | memcpy (buf, mqi->msg, size); |
284 | 287 | ||
285 | GNUNET_CONTAINER_DLL_remove (mgr->tmit_head, mgr->tmit_tail, mqi); | 288 | GNUNET_CONTAINER_DLL_remove (mgr->tmit_head, |
289 | mgr->tmit_tail, | ||
290 | mqi); | ||
286 | GNUNET_free (mqi->msg); | 291 | GNUNET_free (mqi->msg); |
287 | GNUNET_free (mqi); | 292 | GNUNET_free (mqi); |
288 | 293 | ||
@@ -292,7 +297,7 @@ send_next_message (void *cls, size_t buf_size, void *buf) | |||
292 | } | 297 | } |
293 | else if (GNUNET_YES == mgr->is_disconnecting) | 298 | else if (GNUNET_YES == mgr->is_disconnecting) |
294 | { | 299 | { |
295 | GNUNET_SCHEDULER_add_now (&schedule_disconnect, mgr); | 300 | (void) GNUNET_SCHEDULER_add_now (&schedule_disconnect, mgr); |
296 | return size; | 301 | return size; |
297 | } | 302 | } |
298 | 303 | ||
@@ -322,7 +327,8 @@ transmit_next (struct GNUNET_CLIENT_MANAGER_Connection *mgr) | |||
322 | { | 327 | { |
323 | if (GNUNET_YES == mgr->is_disconnecting) | 328 | if (GNUNET_YES == mgr->is_disconnecting) |
324 | GNUNET_CLIENT_MANAGER_disconnect (mgr, GNUNET_NO, | 329 | GNUNET_CLIENT_MANAGER_disconnect (mgr, GNUNET_NO, |
325 | mgr->disconnect_cb, mgr->disconnect_cls); | 330 | mgr->disconnect_cb, |
331 | mgr->disconnect_cls); | ||
326 | return; | 332 | return; |
327 | } | 333 | } |
328 | 334 | ||
@@ -346,14 +352,15 @@ static void | |||
346 | schedule_reconnect (void *cls) | 352 | schedule_reconnect (void *cls) |
347 | { | 353 | { |
348 | struct GNUNET_CLIENT_MANAGER_Connection *mgr = cls; | 354 | struct GNUNET_CLIENT_MANAGER_Connection *mgr = cls; |
349 | mgr->reconnect_task = NULL; | ||
350 | 355 | ||
356 | mgr->reconnect_task = NULL; | ||
351 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 357 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
352 | "Connecting to %s service.\n", mgr->service_name); | 358 | "Connecting to %s service.\n", |
359 | mgr->service_name); | ||
353 | GNUNET_assert (NULL == mgr->client); | 360 | GNUNET_assert (NULL == mgr->client); |
354 | mgr->client = GNUNET_CLIENT_connect (mgr->service_name, mgr->cfg); | 361 | mgr->client = GNUNET_CLIENT_connect (mgr->service_name, |
362 | mgr->cfg); | ||
355 | GNUNET_assert (NULL != mgr->client); | 363 | GNUNET_assert (NULL != mgr->client); |
356 | |||
357 | transmit_next (mgr); | 364 | transmit_next (mgr); |
358 | } | 365 | } |
359 | 366 | ||
@@ -373,16 +380,17 @@ schedule_reconnect (void *cls) | |||
373 | struct GNUNET_CLIENT_MANAGER_Connection * | 380 | struct GNUNET_CLIENT_MANAGER_Connection * |
374 | GNUNET_CLIENT_MANAGER_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, | 381 | GNUNET_CLIENT_MANAGER_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, |
375 | const char *service_name, | 382 | const char *service_name, |
376 | const struct | 383 | const struct GNUNET_CLIENT_MANAGER_MessageHandler *handlers) |
377 | GNUNET_CLIENT_MANAGER_MessageHandler *handlers) | ||
378 | { | 384 | { |
379 | struct GNUNET_CLIENT_MANAGER_Connection * | 385 | struct GNUNET_CLIENT_MANAGER_Connection *mgr; |
380 | mgr = GNUNET_malloc (sizeof (*mgr)); | 386 | |
387 | mgr = GNUNET_new (struct GNUNET_CLIENT_MANAGER_Connection); | ||
381 | mgr->cfg = cfg; | 388 | mgr->cfg = cfg; |
382 | mgr->service_name = service_name; | 389 | mgr->service_name = service_name; |
383 | mgr->handlers = handlers; | 390 | mgr->handlers = handlers; |
384 | mgr->reconnect_delay = GNUNET_TIME_UNIT_ZERO; | 391 | mgr->reconnect_delay = GNUNET_TIME_UNIT_ZERO; |
385 | mgr->reconnect_task = GNUNET_SCHEDULER_add_now (&schedule_reconnect, mgr); | 392 | mgr->reconnect_task = GNUNET_SCHEDULER_add_now (&schedule_reconnect, |
393 | mgr); | ||
386 | return mgr; | 394 | return mgr; |
387 | } | 395 | } |
388 | 396 | ||
@@ -405,7 +413,9 @@ GNUNET_CLIENT_MANAGER_disconnect (struct GNUNET_CLIENT_MANAGER_Connection *mgr, | |||
405 | GNUNET_ContinuationCallback disconnect_cb, | 413 | GNUNET_ContinuationCallback disconnect_cb, |
406 | void *cls) | 414 | void *cls) |
407 | { | 415 | { |
408 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting (%d)\n", transmit_queue); | 416 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
417 | "Disconnecting (%d)\n", | ||
418 | transmit_queue); | ||
409 | mgr->disconnect_cb = disconnect_cb; | 419 | mgr->disconnect_cb = disconnect_cb; |
410 | mgr->disconnect_cls = cls; | 420 | mgr->disconnect_cls = cls; |
411 | if (NULL != mgr->tmit_head) | 421 | if (NULL != mgr->tmit_head) |
@@ -424,7 +434,7 @@ GNUNET_CLIENT_MANAGER_disconnect (struct GNUNET_CLIENT_MANAGER_Connection *mgr, | |||
424 | GNUNET_CLIENT_MANAGER_drop_queue (mgr); | 434 | GNUNET_CLIENT_MANAGER_drop_queue (mgr); |
425 | } | 435 | } |
426 | } | 436 | } |
427 | if (mgr->reconnect_task != NULL) | 437 | if (NULL != mgr->reconnect_task) |
428 | { | 438 | { |
429 | GNUNET_SCHEDULER_cancel (mgr->reconnect_task); | 439 | GNUNET_SCHEDULER_cancel (mgr->reconnect_task); |
430 | mgr->reconnect_task = NULL; | 440 | mgr->reconnect_task = NULL; |
@@ -473,7 +483,9 @@ GNUNET_CLIENT_MANAGER_reconnect (struct GNUNET_CLIENT_MANAGER_Connection *mgr) | |||
473 | "Scheduling task to reconnect to service in %s.\n", | 483 | "Scheduling task to reconnect to service in %s.\n", |
474 | GNUNET_STRINGS_relative_time_to_string (mgr->reconnect_delay, GNUNET_YES)); | 484 | GNUNET_STRINGS_relative_time_to_string (mgr->reconnect_delay, GNUNET_YES)); |
475 | mgr->reconnect_task = | 485 | mgr->reconnect_task = |
476 | GNUNET_SCHEDULER_add_delayed (mgr->reconnect_delay, &schedule_reconnect, mgr); | 486 | GNUNET_SCHEDULER_add_delayed (mgr->reconnect_delay, |
487 | &schedule_reconnect, | ||
488 | mgr); | ||
477 | mgr->reconnect_delay = GNUNET_TIME_STD_BACKOFF (mgr->reconnect_delay); | 489 | mgr->reconnect_delay = GNUNET_TIME_STD_BACKOFF (mgr->reconnect_delay); |
478 | } | 490 | } |
479 | 491 | ||
@@ -491,9 +503,13 @@ void | |||
491 | GNUNET_CLIENT_MANAGER_transmit (struct GNUNET_CLIENT_MANAGER_Connection *mgr, | 503 | GNUNET_CLIENT_MANAGER_transmit (struct GNUNET_CLIENT_MANAGER_Connection *mgr, |
492 | struct GNUNET_MessageHeader *msg) | 504 | struct GNUNET_MessageHeader *msg) |
493 | { | 505 | { |
494 | struct MessageQueueItem *mqi = GNUNET_malloc (sizeof (*mqi)); | 506 | struct MessageQueueItem *mqi; |
507 | |||
508 | mqi = GNUNET_new (struct MessageQueueItem); | ||
495 | mqi->msg = GNUNET_copy_message (msg); | 509 | mqi->msg = GNUNET_copy_message (msg); |
496 | GNUNET_CONTAINER_DLL_insert_tail (mgr->tmit_head, mgr->tmit_tail, mqi); | 510 | GNUNET_CONTAINER_DLL_insert_tail (mgr->tmit_head, |
511 | mgr->tmit_tail, | ||
512 | mqi); | ||
497 | transmit_next (mgr); | 513 | transmit_next (mgr); |
498 | } | 514 | } |
499 | 515 | ||
@@ -511,9 +527,13 @@ void | |||
511 | GNUNET_CLIENT_MANAGER_transmit_now (struct GNUNET_CLIENT_MANAGER_Connection *mgr, | 527 | GNUNET_CLIENT_MANAGER_transmit_now (struct GNUNET_CLIENT_MANAGER_Connection *mgr, |
512 | struct GNUNET_MessageHeader *msg) | 528 | struct GNUNET_MessageHeader *msg) |
513 | { | 529 | { |
514 | struct MessageQueueItem *mqi = GNUNET_malloc (sizeof (*mqi)); | 530 | struct MessageQueueItem *mqi; |
531 | |||
532 | mqi = GNUNET_new (struct MessageQueueItem); | ||
515 | mqi->msg = GNUNET_copy_message (msg); | 533 | mqi->msg = GNUNET_copy_message (msg); |
516 | GNUNET_CONTAINER_DLL_insert (mgr->tmit_head, mgr->tmit_tail, mqi); | 534 | GNUNET_CONTAINER_DLL_insert (mgr->tmit_head, |
535 | mgr->tmit_tail, | ||
536 | mqi); | ||
517 | transmit_next (mgr); | 537 | transmit_next (mgr); |
518 | } | 538 | } |
519 | 539 | ||
@@ -527,7 +547,10 @@ GNUNET_CLIENT_MANAGER_transmit_now (struct GNUNET_CLIENT_MANAGER_Connection *mgr | |||
527 | void | 547 | void |
528 | GNUNET_CLIENT_MANAGER_drop_queue (struct GNUNET_CLIENT_MANAGER_Connection *mgr) | 548 | GNUNET_CLIENT_MANAGER_drop_queue (struct GNUNET_CLIENT_MANAGER_Connection *mgr) |
529 | { | 549 | { |
530 | struct MessageQueueItem *cur, *next = mgr->tmit_head; | 550 | struct MessageQueueItem *cur; |
551 | struct MessageQueueItem *next; | ||
552 | |||
553 | next = mgr->tmit_head; | ||
531 | while (NULL != next) | 554 | while (NULL != next) |
532 | { | 555 | { |
533 | cur = next; | 556 | cur = next; |
@@ -629,15 +652,14 @@ GNUNET_CLIENT_MANAGER_op_get_next_id (struct GNUNET_CLIENT_MANAGER_Connection *m | |||
629 | * @return Operation, or NULL if not found. | 652 | * @return Operation, or NULL if not found. |
630 | */ | 653 | */ |
631 | static struct OperationListItem * | 654 | static struct OperationListItem * |
632 | op_find (struct GNUNET_CLIENT_MANAGER_Connection *mgr, uint64_t op_id) | 655 | op_find (struct GNUNET_CLIENT_MANAGER_Connection *mgr, |
656 | uint64_t op_id) | ||
633 | { | 657 | { |
634 | struct OperationListItem *op = mgr->op_head; | 658 | struct OperationListItem *op; |
635 | while (NULL != op) | 659 | |
636 | { | 660 | for (op = mgr->op_head; NULL != op; op = op->next) |
637 | if (op->op_id == op_id) | 661 | if (op->op_id == op_id) |
638 | return op; | 662 | return op; |
639 | op = op->next; | ||
640 | } | ||
641 | return NULL; | 663 | return NULL; |
642 | } | 664 | } |
643 | 665 | ||
@@ -691,17 +713,21 @@ GNUNET_CLIENT_MANAGER_op_add (struct GNUNET_CLIENT_MANAGER_Connection *mgr, | |||
691 | GNUNET_ResultCallback result_cb, | 713 | GNUNET_ResultCallback result_cb, |
692 | void *cls) | 714 | void *cls) |
693 | { | 715 | { |
716 | struct OperationListItem *op; | ||
717 | |||
694 | if (NULL == result_cb) | 718 | if (NULL == result_cb) |
695 | return 0; | 719 | return 0; |
696 | 720 | op = GNUNET_new (struct OperationListItem); | |
697 | struct OperationListItem *op = GNUNET_malloc (sizeof (*op)); | ||
698 | op->op_id = GNUNET_CLIENT_MANAGER_op_get_next_id (mgr); | 721 | op->op_id = GNUNET_CLIENT_MANAGER_op_get_next_id (mgr); |
699 | op->result_cb = result_cb; | 722 | op->result_cb = result_cb; |
700 | op->cls = cls; | 723 | op->cls = cls; |
701 | GNUNET_CONTAINER_DLL_insert_tail (mgr->op_head, mgr->op_tail, op); | 724 | GNUNET_CONTAINER_DLL_insert_tail (mgr->op_head, |
702 | 725 | mgr->op_tail, | |
726 | op); | ||
703 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 727 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
704 | "%p Added operation #%" PRIu64 "\n", mgr, op->op_id); | 728 | "%p Added operation #%" PRIu64 "\n", |
729 | mgr, | ||
730 | op->op_id); | ||
705 | return op->op_id; | 731 | return op->op_id; |
706 | } | 732 | } |
707 | 733 | ||
@@ -730,8 +756,11 @@ GNUNET_CLIENT_MANAGER_op_add (struct GNUNET_CLIENT_MANAGER_Connection *mgr, | |||
730 | */ | 756 | */ |
731 | static int | 757 | static int |
732 | op_result (struct GNUNET_CLIENT_MANAGER_Connection *mgr, | 758 | op_result (struct GNUNET_CLIENT_MANAGER_Connection *mgr, |
733 | uint64_t op_id, int64_t result_code, | 759 | uint64_t op_id, |
734 | const void *data, uint16_t data_size, uint8_t cancel) | 760 | int64_t result_code, |
761 | const void *data, | ||
762 | uint16_t data_size, | ||
763 | uint8_t cancel) | ||
735 | { | 764 | { |
736 | if (0 == op_id) | 765 | if (0 == op_id) |
737 | return GNUNET_NO; | 766 | return GNUNET_NO; |
@@ -744,11 +773,15 @@ op_result (struct GNUNET_CLIENT_MANAGER_Connection *mgr, | |||
744 | return GNUNET_NO; | 773 | return GNUNET_NO; |
745 | } | 774 | } |
746 | 775 | ||
747 | GNUNET_CONTAINER_DLL_remove (mgr->op_head, mgr->op_tail, op); | 776 | GNUNET_CONTAINER_DLL_remove (mgr->op_head, |
748 | 777 | mgr->op_tail, | |
749 | if (GNUNET_YES != cancel && NULL != op->result_cb) | 778 | op); |
750 | op->result_cb (op->cls, result_code, data, data_size); | ||
751 | 779 | ||
780 | if ( (GNUNET_YES != cancel) && | ||
781 | (NULL != op->result_cb) ) | ||
782 | op->result_cb (op->cls, | ||
783 | result_code, data, | ||
784 | data_size); | ||
752 | GNUNET_free (op); | 785 | GNUNET_free (op); |
753 | return GNUNET_YES; | 786 | return GNUNET_YES; |
754 | } | 787 | } |
@@ -773,8 +806,10 @@ op_result (struct GNUNET_CLIENT_MANAGER_Connection *mgr, | |||
773 | */ | 806 | */ |
774 | int | 807 | int |
775 | GNUNET_CLIENT_MANAGER_op_result (struct GNUNET_CLIENT_MANAGER_Connection *mgr, | 808 | GNUNET_CLIENT_MANAGER_op_result (struct GNUNET_CLIENT_MANAGER_Connection *mgr, |
776 | uint64_t op_id, int64_t result_code, | 809 | uint64_t op_id, |
777 | const void *data, uint16_t data_size) | 810 | int64_t result_code, |
811 | const void *data, | ||
812 | uint16_t data_size) | ||
778 | { | 813 | { |
779 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 814 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
780 | "%p Received result for operation #%" PRIu64 ": %" PRId64 " (size: %u)\n", | 815 | "%p Received result for operation #%" PRIu64 ": %" PRId64 " (size: %u)\n", |
@@ -799,6 +834,8 @@ GNUNET_CLIENT_MANAGER_op_cancel (struct GNUNET_CLIENT_MANAGER_Connection *mgr, | |||
799 | uint64_t op_id) | 834 | uint64_t op_id) |
800 | { | 835 | { |
801 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 836 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
802 | "%p Cancelling operation #%" PRIu64 "\n", mgr, op_id); | 837 | "%p Cancelling operation #%" PRIu64 "\n", |
838 | mgr, | ||
839 | op_id); | ||
803 | return op_result (mgr, op_id, 0, NULL, 0, GNUNET_YES); | 840 | return op_result (mgr, op_id, 0, NULL, 0, GNUNET_YES); |
804 | } | 841 | } |
diff --git a/src/util/connection.c b/src/util/connection.c index b3ea3b5af..95fbb13f8 100644 --- a/src/util/connection.c +++ b/src/util/connection.c | |||
@@ -217,7 +217,7 @@ struct GNUNET_CONNECTION_Handle | |||
217 | struct GNUNET_RESOLVER_RequestHandle *dns_active; | 217 | struct GNUNET_RESOLVER_RequestHandle *dns_active; |
218 | 218 | ||
219 | /** | 219 | /** |
220 | * The handle we return for GNUNET_CONNECTION_notify_transmit_ready. | 220 | * The handle we return for #GNUNET_CONNECTION_notify_transmit_ready(). |
221 | */ | 221 | */ |
222 | struct GNUNET_CONNECTION_TransmitHandle nth; | 222 | struct GNUNET_CONNECTION_TransmitHandle nth; |
223 | 223 | ||
@@ -344,7 +344,9 @@ GNUNET_CONNECTION_create_from_accept (GNUNET_CONNECTION_AccessCheck access_cb, | |||
344 | 344 | ||
345 | addrlen = sizeof (addr); | 345 | addrlen = sizeof (addr); |
346 | sock = | 346 | sock = |
347 | GNUNET_NETWORK_socket_accept (lsock, (struct sockaddr *) &addr, &addrlen); | 347 | GNUNET_NETWORK_socket_accept (lsock, |
348 | (struct sockaddr *) &addr, | ||
349 | &addrlen); | ||
348 | if (NULL == sock) | 350 | if (NULL == sock) |
349 | { | 351 | { |
350 | if (EAGAIN != errno) | 352 | if (EAGAIN != errno) |
@@ -360,7 +362,8 @@ GNUNET_CONNECTION_create_from_accept (GNUNET_CONNECTION_AccessCheck access_cb, | |||
360 | 362 | ||
361 | sa = (struct sockaddr *) addr; | 363 | sa = (struct sockaddr *) addr; |
362 | v6 = (struct sockaddr_in6 *) addr; | 364 | v6 = (struct sockaddr_in6 *) addr; |
363 | if ((AF_INET6 == sa->sa_family) && (IN6_IS_ADDR_V4MAPPED (&v6->sin6_addr))) | 365 | if ( (AF_INET6 == sa->sa_family) && |
366 | (IN6_IS_ADDR_V4MAPPED (&v6->sin6_addr)) ) | ||
364 | { | 367 | { |
365 | /* convert to V4 address */ | 368 | /* convert to V4 address */ |
366 | v4 = GNUNET_new (struct sockaddr_in); | 369 | v4 = GNUNET_new (struct sockaddr_in); |
@@ -389,15 +392,21 @@ GNUNET_CONNECTION_create_from_accept (GNUNET_CONNECTION_AccessCheck access_cb, | |||
389 | { | 392 | { |
390 | #if HAVE_GETPEEREID | 393 | #if HAVE_GETPEEREID |
391 | /* most BSDs */ | 394 | /* most BSDs */ |
392 | if (0 == getpeereid (GNUNET_NETWORK_get_fd (sock), &gc.uid, &gc.gid)) | 395 | if (0 == getpeereid (GNUNET_NETWORK_get_fd (sock), |
396 | &gc.uid, | ||
397 | &gc.gid)) | ||
393 | gcp = &gc; | 398 | gcp = &gc; |
394 | #else | 399 | #else |
395 | #ifdef SO_PEERCRED | 400 | #ifdef SO_PEERCRED |
396 | /* largely traditional GNU/Linux */ | 401 | /* largely traditional GNU/Linux */ |
397 | olen = sizeof (uc); | 402 | olen = sizeof (uc); |
398 | if ((0 == | 403 | if ( (0 == |
399 | getsockopt (GNUNET_NETWORK_get_fd (sock), SOL_SOCKET, SO_PEERCRED, &uc, | 404 | getsockopt (GNUNET_NETWORK_get_fd (sock), |
400 | &olen)) && (olen == sizeof (uc))) | 405 | SOL_SOCKET, |
406 | SO_PEERCRED, | ||
407 | &uc, | ||
408 | &olen)) && | ||
409 | (olen == sizeof (uc)) ) | ||
401 | { | 410 | { |
402 | gc.uid = uc.uid; | 411 | gc.uid = uc.uid; |
403 | gc.gid = uc.gid; | 412 | gc.gid = uc.gid; |
@@ -421,8 +430,11 @@ GNUNET_CONNECTION_create_from_accept (GNUNET_CONNECTION_AccessCheck access_cb, | |||
421 | #endif | 430 | #endif |
422 | } | 431 | } |
423 | 432 | ||
424 | if ((NULL != access_cb) && | 433 | if ( (NULL != access_cb) && |
425 | (GNUNET_YES != (aret = access_cb (access_cb_cls, gcp, uaddr, addrlen)))) | 434 | (GNUNET_YES != (aret = access_cb (access_cb_cls, |
435 | gcp, | ||
436 | uaddr, | ||
437 | addrlen))) ) | ||
426 | { | 438 | { |
427 | if (GNUNET_NO == aret) | 439 | if (GNUNET_NO == aret) |
428 | LOG (GNUNET_ERROR_TYPE_INFO, | 440 | LOG (GNUNET_ERROR_TYPE_INFO, |
@@ -444,7 +456,9 @@ GNUNET_CONNECTION_create_from_accept (GNUNET_CONNECTION_AccessCheck access_cb, | |||
444 | connection->sock = sock; | 456 | connection->sock = sock; |
445 | LOG (GNUNET_ERROR_TYPE_INFO, | 457 | LOG (GNUNET_ERROR_TYPE_INFO, |
446 | _("Accepting connection from `%s': %p\n"), | 458 | _("Accepting connection from `%s': %p\n"), |
447 | GNUNET_a2s (uaddr, addrlen), connection); | 459 | GNUNET_a2s (uaddr, |
460 | addrlen), | ||
461 | connection); | ||
448 | return connection; | 462 | return connection; |
449 | } | 463 | } |
450 | 464 | ||
@@ -554,7 +568,9 @@ signal_transmit_error (struct GNUNET_CONNECTION_Handle *connection, | |||
554 | return; /* nobody to tell about it */ | 568 | return; /* nobody to tell about it */ |
555 | notify = connection->nth.notify_ready; | 569 | notify = connection->nth.notify_ready; |
556 | connection->nth.notify_ready = NULL; | 570 | connection->nth.notify_ready = NULL; |
557 | notify (connection->nth.notify_ready_cls, 0, NULL); | 571 | notify (connection->nth.notify_ready_cls, |
572 | 0, | ||
573 | NULL); | ||
558 | } | 574 | } |
559 | 575 | ||
560 | 576 | ||
@@ -631,7 +647,8 @@ connect_success_continuation (struct GNUNET_CONNECTION_Handle *connection) | |||
631 | { | 647 | { |
632 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 648 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
633 | "Connection to `%s' succeeded! (%p)\n", | 649 | "Connection to `%s' succeeded! (%p)\n", |
634 | GNUNET_a2s (connection->addr, connection->addrlen), | 650 | GNUNET_a2s (connection->addr, |
651 | connection->addrlen), | ||
635 | connection); | 652 | connection); |
636 | /* trigger jobs that waited for the connection */ | 653 | /* trigger jobs that waited for the connection */ |
637 | if (NULL != connection->receiver) | 654 | if (NULL != connection->receiver) |
@@ -642,7 +659,8 @@ connect_success_continuation (struct GNUNET_CONNECTION_Handle *connection) | |||
642 | GNUNET_assert (NULL == connection->read_task); | 659 | GNUNET_assert (NULL == connection->read_task); |
643 | connection->read_task = | 660 | connection->read_task = |
644 | GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_absolute_get_remaining | 661 | GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_absolute_get_remaining |
645 | (connection->receive_timeout), connection->sock, | 662 | (connection->receive_timeout), |
663 | connection->sock, | ||
646 | &receive_ready, connection); | 664 | &receive_ready, connection); |
647 | } | 665 | } |
648 | if (NULL != connection->nth.notify_ready) | 666 | if (NULL != connection->nth.notify_ready) |
@@ -679,21 +697,28 @@ connect_probe_continuation (void *cls) | |||
679 | socklen_t len; | 697 | socklen_t len; |
680 | 698 | ||
681 | GNUNET_assert (NULL != ap->sock); | 699 | GNUNET_assert (NULL != ap->sock); |
682 | GNUNET_CONTAINER_DLL_remove (connection->ap_head, connection->ap_tail, ap); | 700 | GNUNET_CONTAINER_DLL_remove (connection->ap_head, |
701 | connection->ap_tail, | ||
702 | ap); | ||
683 | len = sizeof (error); | 703 | len = sizeof (error); |
684 | errno = 0; | 704 | errno = 0; |
685 | error = 0; | 705 | error = 0; |
686 | tc = GNUNET_SCHEDULER_get_task_context (); | 706 | tc = GNUNET_SCHEDULER_get_task_context (); |
687 | if ((0 == (tc->reason & GNUNET_SCHEDULER_REASON_WRITE_READY)) || | 707 | if ( (0 == (tc->reason & GNUNET_SCHEDULER_REASON_WRITE_READY)) || |
688 | (GNUNET_OK != | 708 | (GNUNET_OK != |
689 | GNUNET_NETWORK_socket_getsockopt (ap->sock, SOL_SOCKET, SO_ERROR, &error, | 709 | GNUNET_NETWORK_socket_getsockopt (ap->sock, |
690 | &len)) || (0 != error)) | 710 | SOL_SOCKET, |
711 | SO_ERROR, | ||
712 | &error, | ||
713 | &len)) || | ||
714 | (0 != error) ) | ||
691 | { | 715 | { |
692 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (ap->sock)); | 716 | GNUNET_break (GNUNET_OK == |
717 | GNUNET_NETWORK_socket_close (ap->sock)); | ||
693 | GNUNET_free (ap); | 718 | GNUNET_free (ap); |
694 | if ((NULL == connection->ap_head) && | 719 | if ( (NULL == connection->ap_head) && |
695 | (GNUNET_NO == connection->dns_active) && | 720 | (GNUNET_NO == connection->dns_active) && |
696 | (NULL == connection->proxy_handshake)) | 721 | (NULL == connection->proxy_handshake) ) |
697 | connect_fail_continuation (connection); | 722 | connect_fail_continuation (connection); |
698 | return; | 723 | return; |
699 | } | 724 | } |
@@ -709,7 +734,9 @@ connect_probe_continuation (void *cls) | |||
709 | { | 734 | { |
710 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (pos->sock)); | 735 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (pos->sock)); |
711 | GNUNET_SCHEDULER_cancel (pos->task); | 736 | GNUNET_SCHEDULER_cancel (pos->task); |
712 | GNUNET_CONTAINER_DLL_remove (connection->ap_head, connection->ap_tail, pos); | 737 | GNUNET_CONTAINER_DLL_remove (connection->ap_head, |
738 | connection->ap_tail, | ||
739 | pos); | ||
713 | GNUNET_free (pos); | 740 | GNUNET_free (pos); |
714 | } | 741 | } |
715 | connect_success_continuation (connection); | 742 | connect_success_continuation (connection); |
@@ -771,7 +798,8 @@ try_connect_using_address (void *cls, | |||
771 | GNUNET_free (ap); | 798 | GNUNET_free (ap); |
772 | return; /* not supported by us */ | 799 | return; /* not supported by us */ |
773 | } | 800 | } |
774 | ap->sock = GNUNET_NETWORK_socket_create (ap->addr->sa_family, SOCK_STREAM, 0); | 801 | ap->sock = GNUNET_NETWORK_socket_create (ap->addr->sa_family, |
802 | SOCK_STREAM, 0); | ||
775 | if (NULL == ap->sock) | 803 | if (NULL == ap->sock) |
776 | { | 804 | { |
777 | GNUNET_free (ap); | 805 | GNUNET_free (ap); |
@@ -782,7 +810,9 @@ try_connect_using_address (void *cls, | |||
782 | GNUNET_a2s (ap->addr, ap->addrlen), | 810 | GNUNET_a2s (ap->addr, ap->addrlen), |
783 | connection); | 811 | connection); |
784 | if ((GNUNET_OK != | 812 | if ((GNUNET_OK != |
785 | GNUNET_NETWORK_socket_connect (ap->sock, ap->addr, ap->addrlen)) && | 813 | GNUNET_NETWORK_socket_connect (ap->sock, |
814 | ap->addr, | ||
815 | ap->addrlen)) && | ||
786 | (EINPROGRESS != errno)) | 816 | (EINPROGRESS != errno)) |
787 | { | 817 | { |
788 | /* maybe refused / unsupported address, try next */ | 818 | /* maybe refused / unsupported address, try next */ |
@@ -794,17 +824,15 @@ try_connect_using_address (void *cls, | |||
794 | GNUNET_CONTAINER_DLL_insert (connection->ap_head, connection->ap_tail, ap); | 824 | GNUNET_CONTAINER_DLL_insert (connection->ap_head, connection->ap_tail, ap); |
795 | delay = GNUNET_CONNECTION_CONNECT_RETRY_TIMEOUT; | 825 | delay = GNUNET_CONNECTION_CONNECT_RETRY_TIMEOUT; |
796 | if (NULL != connection->nth.notify_ready) | 826 | if (NULL != connection->nth.notify_ready) |
797 | delay = | 827 | delay = GNUNET_TIME_relative_min (delay, |
798 | GNUNET_TIME_relative_min (delay, | 828 | GNUNET_TIME_absolute_get_remaining (connection->nth.transmit_timeout)); |
799 | GNUNET_TIME_absolute_get_remaining (connection->nth.transmit_timeout)); | ||
800 | if (NULL != connection->receiver) | 829 | if (NULL != connection->receiver) |
801 | delay = | 830 | delay = GNUNET_TIME_relative_min (delay, |
802 | GNUNET_TIME_relative_min (delay, | 831 | GNUNET_TIME_absolute_get_remaining (connection->receive_timeout)); |
803 | GNUNET_TIME_absolute_get_remaining | 832 | ap->task = GNUNET_SCHEDULER_add_write_net (delay, |
804 | (connection->receive_timeout)); | 833 | ap->sock, |
805 | ap->task = | 834 | &connect_probe_continuation, |
806 | GNUNET_SCHEDULER_add_write_net (delay, ap->sock, | 835 | ap); |
807 | &connect_probe_continuation, ap); | ||
808 | } | 836 | } |
809 | 837 | ||
810 | 838 | ||
@@ -833,9 +861,11 @@ GNUNET_CONNECTION_create_from_connect (const struct GNUNET_CONFIGURATION_Handle | |||
833 | connection->port = port; | 861 | connection->port = port; |
834 | connection->hostname = GNUNET_strdup (hostname); | 862 | connection->hostname = GNUNET_strdup (hostname); |
835 | connection->dns_active = | 863 | connection->dns_active = |
836 | GNUNET_RESOLVER_ip_get (connection->hostname, AF_UNSPEC, | 864 | GNUNET_RESOLVER_ip_get (connection->hostname, |
865 | AF_UNSPEC, | ||
837 | GNUNET_CONNECTION_CONNECT_RETRY_TIMEOUT, | 866 | GNUNET_CONNECTION_CONNECT_RETRY_TIMEOUT, |
838 | &try_connect_using_address, connection); | 867 | &try_connect_using_address, |
868 | connection); | ||
839 | return connection; | 869 | return connection; |
840 | } | 870 | } |
841 | 871 | ||
@@ -865,7 +895,8 @@ GNUNET_CONNECTION_create_from_connect_to_unixpath (const struct GNUNET_CONFIGURA | |||
865 | { | 895 | { |
866 | int abstract; | 896 | int abstract; |
867 | 897 | ||
868 | abstract = GNUNET_CONFIGURATION_get_value_yesno (cfg, "TESTING", | 898 | abstract = GNUNET_CONFIGURATION_get_value_yesno (cfg, |
899 | "TESTING", | ||
869 | "USE_ABSTRACT_SOCKETS"); | 900 | "USE_ABSTRACT_SOCKETS"); |
870 | if (GNUNET_YES == abstract) | 901 | if (GNUNET_YES == abstract) |
871 | un->sun_path[0] = '\0'; | 902 | un->sun_path[0] = '\0'; |
@@ -882,7 +913,9 @@ GNUNET_CONNECTION_create_from_connect_to_unixpath (const struct GNUNET_CONFIGURA | |||
882 | connection->hostname = NULL; | 913 | connection->hostname = NULL; |
883 | connection->addr = (struct sockaddr *) un; | 914 | connection->addr = (struct sockaddr *) un; |
884 | connection->addrlen = sizeof (struct sockaddr_un); | 915 | connection->addrlen = sizeof (struct sockaddr_un); |
885 | connection->sock = GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_STREAM, 0); | 916 | connection->sock = GNUNET_NETWORK_socket_create (AF_UNIX, |
917 | SOCK_STREAM, | ||
918 | 0); | ||
886 | if (NULL == connection->sock) | 919 | if (NULL == connection->sock) |
887 | { | 920 | { |
888 | GNUNET_free (connection->addr); | 921 | GNUNET_free (connection->addr); |
@@ -891,11 +924,14 @@ GNUNET_CONNECTION_create_from_connect_to_unixpath (const struct GNUNET_CONFIGURA | |||
891 | return NULL; | 924 | return NULL; |
892 | } | 925 | } |
893 | if ( (GNUNET_OK != | 926 | if ( (GNUNET_OK != |
894 | GNUNET_NETWORK_socket_connect (connection->sock, connection->addr, connection->addrlen)) && | 927 | GNUNET_NETWORK_socket_connect (connection->sock, |
928 | connection->addr, | ||
929 | connection->addrlen)) && | ||
895 | (EINPROGRESS != errno) ) | 930 | (EINPROGRESS != errno) ) |
896 | { | 931 | { |
897 | /* Just return; we expect everything to work eventually so don't fail HARD */ | 932 | /* Just return; we expect everything to work eventually so don't fail HARD */ |
898 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (connection->sock)); | 933 | GNUNET_break (GNUNET_OK == |
934 | GNUNET_NETWORK_socket_close (connection->sock)); | ||
899 | connection->sock = NULL; | 935 | connection->sock = NULL; |
900 | return connection; | 936 | return connection; |
901 | } | 937 | } |
@@ -971,10 +1007,13 @@ GNUNET_CONNECTION_create_from_sockaddr (int af_family, | |||
971 | s = GNUNET_NETWORK_socket_create (af_family, SOCK_STREAM, 0); | 1007 | s = GNUNET_NETWORK_socket_create (af_family, SOCK_STREAM, 0); |
972 | if (NULL == s) | 1008 | if (NULL == s) |
973 | { | 1009 | { |
974 | LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, "socket"); | 1010 | LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, |
1011 | "socket"); | ||
975 | return NULL; | 1012 | return NULL; |
976 | } | 1013 | } |
977 | return GNUNET_CONNECTION_connect_socket (s, serv_addr, addrlen); | 1014 | return GNUNET_CONNECTION_connect_socket (s, |
1015 | serv_addr, | ||
1016 | addrlen); | ||
978 | } | 1017 | } |
979 | 1018 | ||
980 | 1019 | ||
@@ -1054,7 +1093,9 @@ GNUNET_CONNECTION_destroy (struct GNUNET_CONNECTION_Handle *connection) | |||
1054 | { | 1093 | { |
1055 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (pos->sock)); | 1094 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (pos->sock)); |
1056 | GNUNET_SCHEDULER_cancel (pos->task); | 1095 | GNUNET_SCHEDULER_cancel (pos->task); |
1057 | GNUNET_CONTAINER_DLL_remove (connection->ap_head, connection->ap_tail, pos); | 1096 | GNUNET_CONTAINER_DLL_remove (connection->ap_head, |
1097 | connection->ap_tail, | ||
1098 | pos); | ||
1058 | GNUNET_free (pos); | 1099 | GNUNET_free (pos); |
1059 | } | 1100 | } |
1060 | if ( (NULL != connection->sock) && | 1101 | if ( (NULL != connection->sock) && |
@@ -1105,21 +1146,14 @@ receive_ready (void *cls) | |||
1105 | 1146 | ||
1106 | connection->read_task = NULL; | 1147 | connection->read_task = NULL; |
1107 | tc = GNUNET_SCHEDULER_get_task_context (); | 1148 | tc = GNUNET_SCHEDULER_get_task_context (); |
1108 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | ||
1109 | { | ||
1110 | /* ignore shutdown request, go again immediately */ | ||
1111 | connection->read_task = | ||
1112 | GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_absolute_get_remaining | ||
1113 | (connection->receive_timeout), connection->sock, | ||
1114 | &receive_ready, connection); | ||
1115 | return; | ||
1116 | } | ||
1117 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT)) | 1149 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT)) |
1118 | { | 1150 | { |
1119 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1151 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1120 | "Receive from `%s' encounters error: timeout (%s, %p)\n", | 1152 | "Receive from `%s' encounters error: timeout (%s, %p)\n", |
1121 | GNUNET_a2s (connection->addr, connection->addrlen), | 1153 | GNUNET_a2s (connection->addr, |
1122 | GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (connection->receive_timeout), GNUNET_YES), | 1154 | connection->addrlen), |
1155 | GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (connection->receive_timeout), | ||
1156 | GNUNET_YES), | ||
1123 | connection); | 1157 | connection); |
1124 | signal_receive_timeout (connection); | 1158 | signal_receive_timeout (connection); |
1125 | return; | 1159 | return; |
@@ -1130,7 +1164,8 @@ receive_ready (void *cls) | |||
1130 | signal_receive_error (connection, ECONNREFUSED); | 1164 | signal_receive_error (connection, ECONNREFUSED); |
1131 | return; | 1165 | return; |
1132 | } | 1166 | } |
1133 | GNUNET_assert (GNUNET_NETWORK_fdset_isset (tc->read_ready, connection->sock)); | 1167 | GNUNET_assert (GNUNET_NETWORK_fdset_isset (tc->read_ready, |
1168 | connection->sock)); | ||
1134 | RETRY: | 1169 | RETRY: |
1135 | ret = GNUNET_NETWORK_socket_recv (connection->sock, | 1170 | ret = GNUNET_NETWORK_socket_recv (connection->sock, |
1136 | buffer, | 1171 | buffer, |
@@ -1161,8 +1196,8 @@ RETRY: | |||
1161 | 1196 | ||
1162 | 1197 | ||
1163 | /** | 1198 | /** |
1164 | * Receive data from the given connection. Note that this function will | 1199 | * Receive data from the given connection. Note that this function |
1165 | * call @a receiver asynchronously using the scheduler. It will | 1200 | * will call @a receiver asynchronously using the scheduler. It will |
1166 | * "immediately" return. Note that there MUST only be one active | 1201 | * "immediately" return. Note that there MUST only be one active |
1167 | * receive call per connection at any given point in time (so do not | 1202 | * receive call per connection at any given point in time (so do not |
1168 | * call receive again until the receiver callback has been invoked). | 1203 | * call receive again until the receiver callback has been invoked). |
@@ -1202,7 +1237,10 @@ GNUNET_CONNECTION_receive (struct GNUNET_CONNECTION_Handle *connection, | |||
1202 | (NULL == connection->proxy_handshake)) | 1237 | (NULL == connection->proxy_handshake)) |
1203 | { | 1238 | { |
1204 | connection->receiver = NULL; | 1239 | connection->receiver = NULL; |
1205 | receiver (receiver_cls, NULL, 0, NULL, 0, ETIMEDOUT); | 1240 | receiver (receiver_cls, |
1241 | NULL, 0, | ||
1242 | NULL, 0, | ||
1243 | ETIMEDOUT); | ||
1206 | return; | 1244 | return; |
1207 | } | 1245 | } |
1208 | } | 1246 | } |
@@ -1312,7 +1350,9 @@ transmit_timeout (void *cls) | |||
1312 | notify = connection->nth.notify_ready; | 1350 | notify = connection->nth.notify_ready; |
1313 | GNUNET_assert (NULL != notify); | 1351 | GNUNET_assert (NULL != notify); |
1314 | connection->nth.notify_ready = NULL; | 1352 | connection->nth.notify_ready = NULL; |
1315 | notify (connection->nth.notify_ready_cls, 0, NULL); | 1353 | notify (connection->nth.notify_ready_cls, |
1354 | 0, | ||
1355 | NULL); | ||
1316 | } | 1356 | } |
1317 | 1357 | ||
1318 | 1358 | ||
@@ -1339,7 +1379,9 @@ connect_error (void *cls) | |||
1339 | connection->write_task = NULL; | 1379 | connection->write_task = NULL; |
1340 | notify = connection->nth.notify_ready; | 1380 | notify = connection->nth.notify_ready; |
1341 | connection->nth.notify_ready = NULL; | 1381 | connection->nth.notify_ready = NULL; |
1342 | notify (connection->nth.notify_ready_cls, 0, NULL); | 1382 | notify (connection->nth.notify_ready_cls, |
1383 | 0, | ||
1384 | NULL); | ||
1343 | } | 1385 | } |
1344 | 1386 | ||
1345 | 1387 | ||
@@ -1364,21 +1406,6 @@ transmit_ready (void *cls) | |||
1364 | connection->write_task = NULL; | 1406 | connection->write_task = NULL; |
1365 | GNUNET_assert (NULL == connection->nth.timeout_task); | 1407 | GNUNET_assert (NULL == connection->nth.timeout_task); |
1366 | tc = GNUNET_SCHEDULER_get_task_context (); | 1408 | tc = GNUNET_SCHEDULER_get_task_context (); |
1367 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | ||
1368 | { | ||
1369 | if (NULL != connection->sock) | ||
1370 | goto SCHEDULE_WRITE; /* ignore shutdown, go again immediately */ | ||
1371 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1372 | "Transmit to `%s' fails, shutdown happened (%p).\n", | ||
1373 | GNUNET_a2s (connection->addr, connection->addrlen), connection); | ||
1374 | notify = connection->nth.notify_ready; | ||
1375 | if (NULL != notify) | ||
1376 | { | ||
1377 | connection->nth.notify_ready = NULL; | ||
1378 | notify (connection->nth.notify_ready_cls, 0, NULL); | ||
1379 | } | ||
1380 | return; | ||
1381 | } | ||
1382 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT)) | 1409 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT)) |
1383 | { | 1410 | { |
1384 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1411 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
@@ -1400,7 +1427,8 @@ transmit_ready (void *cls) | |||
1400 | * Hence retry. */ | 1427 | * Hence retry. */ |
1401 | goto SCHEDULE_WRITE; | 1428 | goto SCHEDULE_WRITE; |
1402 | } | 1429 | } |
1403 | if (!GNUNET_NETWORK_fdset_isset (tc->write_ready, connection->sock)) | 1430 | if (! GNUNET_NETWORK_fdset_isset (tc->write_ready, |
1431 | connection->sock)) | ||
1404 | { | 1432 | { |
1405 | GNUNET_assert (NULL == connection->write_task); | 1433 | GNUNET_assert (NULL == connection->write_task); |
1406 | /* special circumstances (in particular, shutdown): not yet ready | 1434 | /* special circumstances (in particular, shutdown): not yet ready |
@@ -1444,7 +1472,11 @@ RETRY: | |||
1444 | } | 1472 | } |
1445 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1473 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1446 | "Connection transmitted %u/%u bytes to `%s' (%p)\n", | 1474 | "Connection transmitted %u/%u bytes to `%s' (%p)\n", |
1447 | (unsigned int) ret, have, GNUNET_a2s (connection->addr, connection->addrlen), connection); | 1475 | (unsigned int) ret, |
1476 | have, | ||
1477 | GNUNET_a2s (connection->addr, | ||
1478 | connection->addrlen), | ||
1479 | connection); | ||
1448 | connection->write_buffer_pos += ret; | 1480 | connection->write_buffer_pos += ret; |
1449 | if (connection->write_buffer_pos == connection->write_buffer_off) | 1481 | if (connection->write_buffer_pos == connection->write_buffer_off) |
1450 | { | 1482 | { |
@@ -1452,21 +1484,25 @@ RETRY: | |||
1452 | connection->write_buffer_pos = 0; | 1484 | connection->write_buffer_pos = 0; |
1453 | connection->write_buffer_off = 0; | 1485 | connection->write_buffer_off = 0; |
1454 | } | 1486 | } |
1455 | if ((0 == connection->write_buffer_off) && (NULL == connection->nth.notify_ready)) | 1487 | if ( (0 == connection->write_buffer_off) && |
1488 | (NULL == connection->nth.notify_ready) ) | ||
1456 | return; /* all data sent! */ | 1489 | return; /* all data sent! */ |
1457 | /* not done writing, schedule more */ | 1490 | /* not done writing, schedule more */ |
1458 | SCHEDULE_WRITE: | 1491 | SCHEDULE_WRITE: |
1459 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1492 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1460 | "Re-scheduling transmit_ready (more to do) (%p).\n", connection); | 1493 | "Re-scheduling transmit_ready (more to do) (%p).\n", |
1494 | connection); | ||
1461 | have = connection->write_buffer_off - connection->write_buffer_pos; | 1495 | have = connection->write_buffer_off - connection->write_buffer_pos; |
1462 | GNUNET_assert ((NULL != connection->nth.notify_ready) || (have > 0)); | 1496 | GNUNET_assert ( (NULL != connection->nth.notify_ready) || |
1497 | (have > 0) ); | ||
1463 | if (NULL == connection->write_task) | 1498 | if (NULL == connection->write_task) |
1464 | connection->write_task = | 1499 | connection->write_task = |
1465 | GNUNET_SCHEDULER_add_write_net ((connection->nth.notify_ready == | 1500 | GNUNET_SCHEDULER_add_write_net ((connection->nth.notify_ready == |
1466 | NULL) ? GNUNET_TIME_UNIT_FOREVER_REL : | 1501 | NULL) ? GNUNET_TIME_UNIT_FOREVER_REL : |
1467 | GNUNET_TIME_absolute_get_remaining | 1502 | GNUNET_TIME_absolute_get_remaining |
1468 | (connection->nth.transmit_timeout), | 1503 | (connection->nth.transmit_timeout), |
1469 | connection->sock, &transmit_ready, connection); | 1504 | connection->sock, |
1505 | &transmit_ready, connection); | ||
1470 | } | 1506 | } |
1471 | 1507 | ||
1472 | 1508 | ||
@@ -1488,8 +1524,8 @@ struct GNUNET_CONNECTION_TransmitHandle * | |||
1488 | GNUNET_CONNECTION_notify_transmit_ready (struct GNUNET_CONNECTION_Handle *connection, | 1524 | GNUNET_CONNECTION_notify_transmit_ready (struct GNUNET_CONNECTION_Handle *connection, |
1489 | size_t size, | 1525 | size_t size, |
1490 | struct GNUNET_TIME_Relative timeout, | 1526 | struct GNUNET_TIME_Relative timeout, |
1491 | GNUNET_CONNECTION_TransmitReadyNotify | 1527 | GNUNET_CONNECTION_TransmitReadyNotify notify, |
1492 | notify, void *notify_cls) | 1528 | void *notify_cls) |
1493 | { | 1529 | { |
1494 | if (NULL != connection->nth.notify_ready) | 1530 | if (NULL != connection->nth.notify_ready) |
1495 | { | 1531 | { |
@@ -1529,7 +1565,8 @@ GNUNET_CONNECTION_notify_transmit_ready (struct GNUNET_CONNECTION_Handle *connec | |||
1529 | connection->write_task = | 1565 | connection->write_task = |
1530 | GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_absolute_get_remaining | 1566 | GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_absolute_get_remaining |
1531 | (connection->nth.transmit_timeout), | 1567 | (connection->nth.transmit_timeout), |
1532 | connection->sock, &transmit_ready, connection); | 1568 | connection->sock, |
1569 | &transmit_ready, connection); | ||
1533 | return &connection->nth; | 1570 | return &connection->nth; |
1534 | } | 1571 | } |
1535 | /* not yet connected, wait for connection */ | 1572 | /* not yet connected, wait for connection */ |
@@ -1538,7 +1575,8 @@ GNUNET_CONNECTION_notify_transmit_ready (struct GNUNET_CONNECTION_Handle *connec | |||
1538 | connection); | 1575 | connection); |
1539 | connection->nth.timeout_task = | 1576 | connection->nth.timeout_task = |
1540 | GNUNET_SCHEDULER_add_delayed (timeout, | 1577 | GNUNET_SCHEDULER_add_delayed (timeout, |
1541 | &transmit_timeout, connection); | 1578 | &transmit_timeout, |
1579 | connection); | ||
1542 | return &connection->nth; | 1580 | return &connection->nth; |
1543 | } | 1581 | } |
1544 | 1582 | ||
@@ -1575,7 +1613,8 @@ GNUNET_CONNECTION_notify_transmit_ready_cancel (struct GNUNET_CONNECTION_Transmi | |||
1575 | struct GNUNET_CONNECTION_Handle * | 1613 | struct GNUNET_CONNECTION_Handle * |
1576 | GNUNET_CONNECTION_create_proxied_from_handshake (struct GNUNET_CONNECTION_Handle *cph) | 1614 | GNUNET_CONNECTION_create_proxied_from_handshake (struct GNUNET_CONNECTION_Handle *cph) |
1577 | { | 1615 | { |
1578 | struct GNUNET_CONNECTION_Handle * proxied = GNUNET_CONNECTION_create_from_existing(NULL); | 1616 | struct GNUNET_CONNECTION_Handle *proxied = GNUNET_CONNECTION_create_from_existing (NULL); |
1617 | |||
1579 | proxied->proxy_handshake = cph; | 1618 | proxied->proxy_handshake = cph; |
1580 | return proxied; | 1619 | return proxied; |
1581 | } | 1620 | } |
@@ -1592,11 +1631,12 @@ void | |||
1592 | GNUNET_CONNECTION_acivate_proxied (struct GNUNET_CONNECTION_Handle *proxied) | 1631 | GNUNET_CONNECTION_acivate_proxied (struct GNUNET_CONNECTION_Handle *proxied) |
1593 | { | 1632 | { |
1594 | struct GNUNET_CONNECTION_Handle *cph = proxied->proxy_handshake; | 1633 | struct GNUNET_CONNECTION_Handle *cph = proxied->proxy_handshake; |
1634 | |||
1595 | GNUNET_assert (NULL != cph); | 1635 | GNUNET_assert (NULL != cph); |
1596 | GNUNET_assert (NULL == proxied->sock); | 1636 | GNUNET_assert (NULL == proxied->sock); |
1597 | GNUNET_assert (NULL != cph->sock); | 1637 | GNUNET_assert (NULL != cph->sock); |
1598 | proxied->sock=cph->sock; | 1638 | proxied->sock = cph->sock; |
1599 | cph->sock=NULL; | 1639 | cph->sock = NULL; |
1600 | GNUNET_CONNECTION_destroy (cph); | 1640 | GNUNET_CONNECTION_destroy (cph); |
1601 | connect_success_continuation (proxied); | 1641 | connect_success_continuation (proxied); |
1602 | } | 1642 | } |
diff --git a/src/util/crypto_hash_file.c b/src/util/crypto_hash_file.c index f2d49d164..ace5212c9 100644 --- a/src/util/crypto_hash_file.c +++ b/src/util/crypto_hash_file.c | |||
@@ -130,9 +130,13 @@ file_hash_task (void *cls) | |||
130 | delta = fhc->bsize; | 130 | delta = fhc->bsize; |
131 | if (fhc->fsize - fhc->offset < delta) | 131 | if (fhc->fsize - fhc->offset < delta) |
132 | delta = fhc->fsize - fhc->offset; | 132 | delta = fhc->fsize - fhc->offset; |
133 | if (delta != GNUNET_DISK_file_read (fhc->fh, fhc->buffer, delta)) | 133 | if (delta != GNUNET_DISK_file_read (fhc->fh, |
134 | fhc->buffer, | ||
135 | delta)) | ||
134 | { | 136 | { |
135 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "read", fhc->filename); | 137 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, |
138 | "read", | ||
139 | fhc->filename); | ||
136 | file_hash_finish (fhc, NULL); | 140 | file_hash_finish (fhc, NULL); |
137 | return; | 141 | return; |
138 | } | 142 | } |
@@ -140,12 +144,14 @@ file_hash_task (void *cls) | |||
140 | fhc->offset += delta; | 144 | fhc->offset += delta; |
141 | if (fhc->offset == fhc->fsize) | 145 | if (fhc->offset == fhc->fsize) |
142 | { | 146 | { |
143 | res = (struct GNUNET_HashCode *) gcry_md_read (fhc->md, GCRY_MD_SHA512); | 147 | res = (struct GNUNET_HashCode *) gcry_md_read (fhc->md, |
148 | GCRY_MD_SHA512); | ||
144 | file_hash_finish (fhc, res); | 149 | file_hash_finish (fhc, res); |
145 | return; | 150 | return; |
146 | } | 151 | } |
147 | fhc->task = GNUNET_SCHEDULER_add_with_priority (fhc->priority, | 152 | fhc->task = GNUNET_SCHEDULER_add_with_priority (fhc->priority, |
148 | &file_hash_task, fhc); | 153 | &file_hash_task, |
154 | fhc); | ||
149 | } | 155 | } |
150 | 156 | ||
151 | 157 | ||
@@ -156,12 +162,13 @@ file_hash_task (void *cls) | |||
156 | * @param filename name of file to hash | 162 | * @param filename name of file to hash |
157 | * @param blocksize number of bytes to process in one task | 163 | * @param blocksize number of bytes to process in one task |
158 | * @param callback function to call upon completion | 164 | * @param callback function to call upon completion |
159 | * @param callback_cls closure for callback | 165 | * @param callback_cls closure for @a callback |
160 | * @return NULL on (immediate) errror | 166 | * @return NULL on (immediate) errror |
161 | */ | 167 | */ |
162 | struct GNUNET_CRYPTO_FileHashContext * | 168 | struct GNUNET_CRYPTO_FileHashContext * |
163 | GNUNET_CRYPTO_hash_file (enum GNUNET_SCHEDULER_Priority priority, | 169 | GNUNET_CRYPTO_hash_file (enum GNUNET_SCHEDULER_Priority priority, |
164 | const char *filename, size_t blocksize, | 170 | const char *filename, |
171 | size_t blocksize, | ||
165 | GNUNET_CRYPTO_HashCompletedCallback callback, | 172 | GNUNET_CRYPTO_HashCompletedCallback callback, |
166 | void *callback_cls) | 173 | void *callback_cls) |
167 | { | 174 | { |
@@ -181,24 +188,29 @@ GNUNET_CRYPTO_hash_file (enum GNUNET_SCHEDULER_Priority priority, | |||
181 | return NULL; | 188 | return NULL; |
182 | } | 189 | } |
183 | fhc->bsize = blocksize; | 190 | fhc->bsize = blocksize; |
184 | if (GNUNET_OK != GNUNET_DISK_file_size (filename, &fhc->fsize, GNUNET_NO, GNUNET_YES)) | 191 | if (GNUNET_OK != |
192 | GNUNET_DISK_file_size (filename, | ||
193 | &fhc->fsize, | ||
194 | GNUNET_NO, | ||
195 | GNUNET_YES)) | ||
185 | { | 196 | { |
186 | GNUNET_free (fhc->filename); | 197 | GNUNET_free (fhc->filename); |
187 | GNUNET_free (fhc); | 198 | GNUNET_free (fhc); |
188 | return NULL; | 199 | return NULL; |
189 | } | 200 | } |
190 | fhc->fh = | 201 | fhc->fh = GNUNET_DISK_file_open (filename, |
191 | GNUNET_DISK_file_open (filename, GNUNET_DISK_OPEN_READ, | 202 | GNUNET_DISK_OPEN_READ, |
192 | GNUNET_DISK_PERM_NONE); | 203 | GNUNET_DISK_PERM_NONE); |
193 | if (!fhc->fh) | 204 | if (! fhc->fh) |
194 | { | 205 | { |
195 | GNUNET_free (fhc->filename); | 206 | GNUNET_free (fhc->filename); |
196 | GNUNET_free (fhc); | 207 | GNUNET_free (fhc); |
197 | return NULL; | 208 | return NULL; |
198 | } | 209 | } |
199 | fhc->priority = priority; | 210 | fhc->priority = priority; |
200 | fhc->task = | 211 | fhc->task = GNUNET_SCHEDULER_add_with_priority (priority, |
201 | GNUNET_SCHEDULER_add_with_priority (priority, &file_hash_task, fhc); | 212 | &file_hash_task, |
213 | fhc); | ||
202 | return fhc; | 214 | return fhc; |
203 | } | 215 | } |
204 | 216 | ||
@@ -213,7 +225,8 @@ GNUNET_CRYPTO_hash_file_cancel (struct GNUNET_CRYPTO_FileHashContext *fhc) | |||
213 | { | 225 | { |
214 | GNUNET_SCHEDULER_cancel (fhc->task); | 226 | GNUNET_SCHEDULER_cancel (fhc->task); |
215 | GNUNET_free (fhc->filename); | 227 | GNUNET_free (fhc->filename); |
216 | GNUNET_break (GNUNET_OK == GNUNET_DISK_file_close (fhc->fh)); | 228 | GNUNET_break (GNUNET_OK == |
229 | GNUNET_DISK_file_close (fhc->fh)); | ||
217 | GNUNET_free (fhc); | 230 | GNUNET_free (fhc); |
218 | } | 231 | } |
219 | 232 | ||
diff --git a/src/util/gnunet-scrypt.c b/src/util/gnunet-scrypt.c index 7449d8042..6fd871cbe 100644 --- a/src/util/gnunet-scrypt.c +++ b/src/util/gnunet-scrypt.c | |||
@@ -40,7 +40,7 @@ static struct GNUNET_CRYPTO_EddsaPublicKey pub; | |||
40 | 40 | ||
41 | static uint64_t proof; | 41 | static uint64_t proof; |
42 | 42 | ||
43 | static struct GNUNET_SCHEDULER_Task * proof_task; | 43 | static struct GNUNET_SCHEDULER_Task *proof_task; |
44 | 44 | ||
45 | static const struct GNUNET_CONFIGURATION_Handle *cfg; | 45 | static const struct GNUNET_CONFIGURATION_Handle *cfg; |
46 | 46 | ||
@@ -51,15 +51,21 @@ static char *pwfn; | |||
51 | 51 | ||
52 | /** | 52 | /** |
53 | * Write our current proof to disk. | 53 | * Write our current proof to disk. |
54 | * | ||
55 | * @param cls closure | ||
54 | */ | 56 | */ |
55 | static void | 57 | static void |
56 | write_proof () | 58 | shutdown_task (void *cls) |
57 | { | 59 | { |
58 | if (sizeof (proof) != | 60 | if (sizeof (proof) != |
59 | GNUNET_DISK_fn_write (pwfn, &proof, sizeof (proof), | 61 | GNUNET_DISK_fn_write (pwfn, |
62 | &proof, | ||
63 | sizeof (proof), | ||
60 | GNUNET_DISK_PERM_USER_READ | | 64 | GNUNET_DISK_PERM_USER_READ | |
61 | GNUNET_DISK_PERM_USER_WRITE)) | 65 | GNUNET_DISK_PERM_USER_WRITE)) |
62 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "write", proof); | 66 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, |
67 | "write", | ||
68 | proof); | ||
63 | } | 69 | } |
64 | 70 | ||
65 | 71 | ||
@@ -120,15 +126,10 @@ find_proof (void *cls) | |||
120 | unsigned int i; | 126 | unsigned int i; |
121 | struct GNUNET_TIME_Absolute timestamp; | 127 | struct GNUNET_TIME_Absolute timestamp; |
122 | struct GNUNET_TIME_Relative elapsed; | 128 | struct GNUNET_TIME_Relative elapsed; |
123 | const struct GNUNET_SCHEDULER_TaskContext *tc; | ||
124 | 129 | ||
125 | tc = GNUNET_SCHEDULER_get_task_context (); | 130 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
126 | if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason)) | 131 | "Got Proof of Work %llu\n", |
127 | { | 132 | proof); |
128 | write_proof (); | ||
129 | return; | ||
130 | } | ||
131 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got Proof of Work %llu\n", proof); | ||
132 | proof_task = NULL; | 133 | proof_task = NULL; |
133 | memcpy (&buf[sizeof (uint64_t)], &pub, | 134 | memcpy (&buf[sizeof (uint64_t)], &pub, |
134 | sizeof (struct GNUNET_CRYPTO_EddsaPublicKey)); | 135 | sizeof (struct GNUNET_CRYPTO_EddsaPublicKey)); |
@@ -144,7 +145,7 @@ find_proof (void *cls) | |||
144 | proof = counter; | 145 | proof = counter; |
145 | FPRINTF (stdout, "Proof of work found: %llu!\n", | 146 | FPRINTF (stdout, "Proof of work found: %llu!\n", |
146 | (unsigned long long) proof); | 147 | (unsigned long long) proof); |
147 | write_proof (); | 148 | GNUNET_SCHEDULER_shutdown (); |
148 | return; | 149 | return; |
149 | } | 150 | } |
150 | counter++; | 151 | counter++; |
@@ -162,16 +163,16 @@ find_proof (void *cls) | |||
162 | (unsigned long long) counter); | 163 | (unsigned long long) counter); |
163 | /* remember progress every 100 rounds */ | 164 | /* remember progress every 100 rounds */ |
164 | proof = counter; | 165 | proof = counter; |
165 | write_proof (); | 166 | shutdown_task (NULL); |
166 | } | 167 | } |
167 | else | 168 | else |
168 | { | 169 | { |
169 | proof = counter; | 170 | proof = counter; |
170 | } | 171 | } |
171 | proof_task = | 172 | proof_task = |
172 | GNUNET_SCHEDULER_add_delayed_with_priority (proof_find_delay, | 173 | GNUNET_SCHEDULER_add_delayed_with_priority (proof_find_delay, |
173 | GNUNET_SCHEDULER_PRIORITY_IDLE, | 174 | GNUNET_SCHEDULER_PRIORITY_IDLE, |
174 | &find_proof, NULL); | 175 | &find_proof, NULL); |
175 | } | 176 | } |
176 | 177 | ||
177 | 178 | ||
@@ -193,17 +194,18 @@ run (void *cls, | |||
193 | char *pids; | 194 | char *pids; |
194 | 195 | ||
195 | cfg = config; | 196 | cfg = config; |
196 | |||
197 | /* load proof of work */ | 197 | /* load proof of work */ |
198 | if (NULL == pwfn) | 198 | if (NULL == pwfn) |
199 | { | 199 | { |
200 | if (GNUNET_OK != | 200 | if (GNUNET_OK != |
201 | GNUNET_CONFIGURATION_get_value_filename (cfg, "NSE", | 201 | GNUNET_CONFIGURATION_get_value_filename (cfg, |
202 | "NSE", | ||
202 | "PROOFFILE", | 203 | "PROOFFILE", |
203 | &pwfn)) | 204 | &pwfn)) |
204 | { | 205 | { |
205 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, | 206 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, |
206 | "NSE", "PROOFFILE"); | 207 | "NSE", |
208 | "PROOFFILE"); | ||
207 | GNUNET_SCHEDULER_shutdown (); | 209 | GNUNET_SCHEDULER_shutdown (); |
208 | return; | 210 | return; |
209 | } | 211 | } |
@@ -219,19 +221,26 @@ run (void *cls, | |||
219 | /* load private key */ | 221 | /* load private key */ |
220 | if (NULL == pkfn) | 222 | if (NULL == pkfn) |
221 | { | 223 | { |
222 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, "PEER", | 224 | if (GNUNET_OK != |
223 | "PRIVATE_KEY", | 225 | GNUNET_CONFIGURATION_get_value_filename (cfg, |
224 | &pkfn)) | 226 | "PEER", |
227 | "PRIVATE_KEY", | ||
228 | &pkfn)) | ||
225 | { | 229 | { |
226 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, | 230 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, |
227 | "PEER", "PRIVATE_KEY"); | 231 | "PEER", |
232 | "PRIVATE_KEY"); | ||
228 | return; | 233 | return; |
229 | } | 234 | } |
230 | } | 235 | } |
231 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Private Key file: %s\n", pkfn); | 236 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
237 | "Private Key file: %s\n", | ||
238 | pkfn); | ||
232 | if (NULL == (pk = GNUNET_CRYPTO_eddsa_key_create_from_file (pkfn))) | 239 | if (NULL == (pk = GNUNET_CRYPTO_eddsa_key_create_from_file (pkfn))) |
233 | { | 240 | { |
234 | FPRINTF (stderr, _("Loading hostkey from `%s' failed.\n"), pkfn); | 241 | FPRINTF (stderr, |
242 | _("Loading hostkey from `%s' failed.\n"), | ||
243 | pkfn); | ||
235 | GNUNET_free (pkfn); | 244 | GNUNET_free (pkfn); |
236 | return; | 245 | return; |
237 | } | 246 | } |
@@ -248,22 +257,28 @@ run (void *cls, | |||
248 | if (0 == nse_work_required) | 257 | if (0 == nse_work_required) |
249 | { | 258 | { |
250 | if (GNUNET_OK != | 259 | if (GNUNET_OK != |
251 | GNUNET_CONFIGURATION_get_value_number (cfg, "NSE", "WORKBITS", | 260 | GNUNET_CONFIGURATION_get_value_number (cfg, |
261 | "NSE", | ||
262 | "WORKBITS", | ||
252 | &nse_work_required)) | 263 | &nse_work_required)) |
253 | { | 264 | { |
254 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "NSE", "WORKBITS"); | 265 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, |
266 | "NSE", | ||
267 | "WORKBITS"); | ||
255 | GNUNET_SCHEDULER_shutdown (); | 268 | GNUNET_SCHEDULER_shutdown (); |
256 | return; | 269 | return; |
257 | } | 270 | } |
258 | if (nse_work_required >= sizeof (struct GNUNET_HashCode) * 8) | 271 | if (nse_work_required >= sizeof (struct GNUNET_HashCode) * 8) |
259 | { | 272 | { |
260 | GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR, "NSE", "WORKBITS", | 273 | GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR, |
274 | "NSE", | ||
275 | "WORKBITS", | ||
261 | _("Value is too large.\n")); | 276 | _("Value is too large.\n")); |
262 | GNUNET_SCHEDULER_shutdown (); | 277 | GNUNET_SCHEDULER_shutdown (); |
263 | return; | 278 | return; |
264 | } else if (0 == nse_work_required) | 279 | } |
280 | else if (0 == nse_work_required) | ||
265 | { | 281 | { |
266 | write_proof (); | ||
267 | GNUNET_SCHEDULER_shutdown (); | 282 | GNUNET_SCHEDULER_shutdown (); |
268 | return; | 283 | return; |
269 | } | 284 | } |
@@ -275,8 +290,12 @@ run (void *cls, | |||
275 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 290 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
276 | "Delay between tries: %s\n", | 291 | "Delay between tries: %s\n", |
277 | GNUNET_STRINGS_relative_time_to_string (proof_find_delay, 1)); | 292 | GNUNET_STRINGS_relative_time_to_string (proof_find_delay, 1)); |
278 | GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE, | 293 | proof_task = |
279 | &find_proof, NULL); | 294 | GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE, |
295 | &find_proof, | ||
296 | NULL); | ||
297 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, | ||
298 | NULL); | ||
280 | } | 299 | } |
281 | 300 | ||
282 | 301 | ||
@@ -307,7 +326,8 @@ main (int argc, char *const *argv) | |||
307 | }; | 326 | }; |
308 | int ret; | 327 | int ret; |
309 | 328 | ||
310 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) | 329 | if (GNUNET_OK != |
330 | GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) | ||
311 | return 2; | 331 | return 2; |
312 | 332 | ||
313 | ret = (GNUNET_OK == | 333 | ret = (GNUNET_OK == |
diff --git a/src/util/gnunet-uri.c b/src/util/gnunet-uri.c index 75e70d2b7..f69508f67 100644 --- a/src/util/gnunet-uri.c +++ b/src/util/gnunet-uri.c | |||
@@ -52,6 +52,7 @@ static void | |||
52 | maint_child_death (void *cls) | 52 | maint_child_death (void *cls) |
53 | { | 53 | { |
54 | enum GNUNET_OS_ProcessStatusType type; | 54 | enum GNUNET_OS_ProcessStatusType type; |
55 | |||
55 | if ( (GNUNET_OK != | 56 | if ( (GNUNET_OK != |
56 | GNUNET_OS_process_status (p, &type, &exit_code)) || | 57 | GNUNET_OS_process_status (p, &type, &exit_code)) || |
57 | (type != GNUNET_OS_PROCESS_EXITED) ) | 58 | (type != GNUNET_OS_PROCESS_EXITED) ) |
@@ -80,12 +81,14 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
80 | 81 | ||
81 | if (NULL == (uri = args[0])) | 82 | if (NULL == (uri = args[0])) |
82 | { | 83 | { |
83 | fprintf (stderr, _("No URI specified on command line\n")); | 84 | fprintf (stderr, |
85 | _("No URI specified on command line\n")); | ||
84 | return; | 86 | return; |
85 | } | 87 | } |
86 | if (0 != strncasecmp ("gnunet://", uri, strlen ("gnunet://"))) | 88 | if (0 != strncasecmp ("gnunet://", uri, strlen ("gnunet://"))) |
87 | { | 89 | { |
88 | fprintf (stderr, _("Invalid URI: does not start with `%s'\n"), | 90 | fprintf (stderr, |
91 | _("Invalid URI: does not start with `%s'\n"), | ||
89 | "gnunet://"); | 92 | "gnunet://"); |
90 | return; | 93 | return; |
91 | } | 94 | } |
diff --git a/src/util/helper.c b/src/util/helper.c index 3ed1c7276..ecfe4ccfa 100644 --- a/src/util/helper.c +++ b/src/util/helper.c | |||
@@ -142,17 +142,17 @@ struct GNUNET_HELPER_Handle | |||
142 | /** | 142 | /** |
143 | * Task to read from the helper. | 143 | * Task to read from the helper. |
144 | */ | 144 | */ |
145 | struct GNUNET_SCHEDULER_Task * read_task; | 145 | struct GNUNET_SCHEDULER_Task *read_task; |
146 | 146 | ||
147 | /** | 147 | /** |
148 | * Task to read from the helper. | 148 | * Task to read from the helper. |
149 | */ | 149 | */ |
150 | struct GNUNET_SCHEDULER_Task * write_task; | 150 | struct GNUNET_SCHEDULER_Task *write_task; |
151 | 151 | ||
152 | /** | 152 | /** |
153 | * Restart task. | 153 | * Restart task. |
154 | */ | 154 | */ |
155 | struct GNUNET_SCHEDULER_Task * restart_task; | 155 | struct GNUNET_SCHEDULER_Task *restart_task; |
156 | 156 | ||
157 | /** | 157 | /** |
158 | * Does the helper support the use of a control pipe for signalling? | 158 | * Does the helper support the use of a control pipe for signalling? |
@@ -319,19 +319,10 @@ static void | |||
319 | helper_read (void *cls) | 319 | helper_read (void *cls) |
320 | { | 320 | { |
321 | struct GNUNET_HELPER_Handle *h = cls; | 321 | struct GNUNET_HELPER_Handle *h = cls; |
322 | const struct GNUNET_SCHEDULER_TaskContext *tc; | ||
323 | char buf[GNUNET_SERVER_MAX_MESSAGE_SIZE] GNUNET_ALIGN; | 322 | char buf[GNUNET_SERVER_MAX_MESSAGE_SIZE] GNUNET_ALIGN; |
324 | ssize_t t; | 323 | ssize_t t; |
325 | 324 | ||
326 | h->read_task = NULL; | 325 | h->read_task = NULL; |
327 | tc = GNUNET_SCHEDULER_get_task_context (); | ||
328 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | ||
329 | { | ||
330 | /* try again */ | ||
331 | h->read_task = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, | ||
332 | h->fh_from_helper, &helper_read, h); | ||
333 | return; | ||
334 | } | ||
335 | t = GNUNET_DISK_file_read (h->fh_from_helper, &buf, sizeof (buf)); | 326 | t = GNUNET_DISK_file_read (h->fh_from_helper, &buf, sizeof (buf)); |
336 | if (t < 0) | 327 | if (t < 0) |
337 | { | 328 | { |
@@ -348,9 +339,9 @@ helper_read (void *cls) | |||
348 | } | 339 | } |
349 | stop_helper (h, GNUNET_NO); | 340 | stop_helper (h, GNUNET_NO); |
350 | /* Restart the helper */ | 341 | /* Restart the helper */ |
351 | h->restart_task = GNUNET_SCHEDULER_add_delayed( | 342 | h->restart_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, |
352 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, | 343 | h->retry_back_off), |
353 | h->retry_back_off), &restart_task, h); | 344 | &restart_task, h); |
354 | return; | 345 | return; |
355 | } | 346 | } |
356 | if (0 == t) | 347 | if (0 == t) |
@@ -368,9 +359,10 @@ helper_read (void *cls) | |||
368 | } | 359 | } |
369 | stop_helper (h, GNUNET_NO); | 360 | stop_helper (h, GNUNET_NO); |
370 | /* Restart the helper */ | 361 | /* Restart the helper */ |
371 | h->restart_task = GNUNET_SCHEDULER_add_delayed( | 362 | h->restart_task |
372 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, | 363 | = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, |
373 | h->retry_back_off), &restart_task, h); | 364 | h->retry_back_off), |
365 | &restart_task, h); | ||
374 | return; | 366 | return; |
375 | } | 367 | } |
376 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 368 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -378,9 +370,13 @@ helper_read (void *cls) | |||
378 | (unsigned int) t, | 370 | (unsigned int) t, |
379 | h->binary_name); | 371 | h->binary_name); |
380 | h->read_task = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, | 372 | h->read_task = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, |
381 | h->fh_from_helper, &helper_read, h); | 373 | h->fh_from_helper, |
374 | &helper_read, h); | ||
382 | if (GNUNET_SYSERR == | 375 | if (GNUNET_SYSERR == |
383 | GNUNET_SERVER_mst_receive (h->mst, NULL, buf, t, GNUNET_NO, GNUNET_NO)) | 376 | GNUNET_SERVER_mst_receive (h->mst, |
377 | NULL, | ||
378 | buf, t, | ||
379 | GNUNET_NO, GNUNET_NO)) | ||
384 | { | 380 | { |
385 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 381 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
386 | _("Failed to parse inbound message from helper `%s'\n"), | 382 | _("Failed to parse inbound message from helper `%s'\n"), |
@@ -393,9 +389,9 @@ helper_read (void *cls) | |||
393 | } | 389 | } |
394 | stop_helper (h, GNUNET_NO); | 390 | stop_helper (h, GNUNET_NO); |
395 | /* Restart the helper */ | 391 | /* Restart the helper */ |
396 | h->restart_task = GNUNET_SCHEDULER_add_delayed( | 392 | h->restart_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, |
397 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, | 393 | h->retry_back_off), |
398 | h->retry_back_off), &restart_task, h); | 394 | &restart_task, h); |
399 | return; | 395 | return; |
400 | } | 396 | } |
401 | } | 397 | } |
@@ -416,9 +412,9 @@ start_helper (struct GNUNET_HELPER_Handle *h) | |||
416 | /* out of file descriptors? try again later... */ | 412 | /* out of file descriptors? try again later... */ |
417 | stop_helper (h, GNUNET_NO); | 413 | stop_helper (h, GNUNET_NO); |
418 | h->restart_task = | 414 | h->restart_task = |
419 | GNUNET_SCHEDULER_add_delayed( | 415 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, |
420 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, | 416 | h->retry_back_off), |
421 | h->retry_back_off), &restart_task, h); | 417 | &restart_task, h); |
422 | return; | 418 | return; |
423 | } | 419 | } |
424 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 420 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -437,9 +433,9 @@ start_helper (struct GNUNET_HELPER_Handle *h) | |||
437 | { | 433 | { |
438 | /* failed to start process? try again later... */ | 434 | /* failed to start process? try again later... */ |
439 | stop_helper (h, GNUNET_NO); | 435 | stop_helper (h, GNUNET_NO); |
440 | h->restart_task = GNUNET_SCHEDULER_add_delayed( | 436 | h->restart_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, |
441 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, | 437 | h->retry_back_off), |
442 | h->retry_back_off), &restart_task, h); | 438 | &restart_task, h); |
443 | return; | 439 | return; |
444 | } | 440 | } |
445 | GNUNET_DISK_pipe_close_end (h->helper_out, GNUNET_DISK_PIPE_END_WRITE); | 441 | GNUNET_DISK_pipe_close_end (h->helper_out, GNUNET_DISK_PIPE_END_WRITE); |
@@ -583,22 +579,11 @@ static void | |||
583 | helper_write (void *cls) | 579 | helper_write (void *cls) |
584 | { | 580 | { |
585 | struct GNUNET_HELPER_Handle *h = cls; | 581 | struct GNUNET_HELPER_Handle *h = cls; |
586 | const struct GNUNET_SCHEDULER_TaskContext *tc; | ||
587 | struct GNUNET_HELPER_SendHandle *sh; | 582 | struct GNUNET_HELPER_SendHandle *sh; |
588 | const char *buf; | 583 | const char *buf; |
589 | ssize_t t; | 584 | ssize_t t; |
590 | 585 | ||
591 | h->write_task = NULL; | 586 | h->write_task = NULL; |
592 | tc = GNUNET_SCHEDULER_get_task_context (); | ||
593 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | ||
594 | { | ||
595 | /* try again */ | ||
596 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
597 | "Helper write triggered during shutdown, retrying\n"); | ||
598 | h->write_task = GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL, | ||
599 | h->fh_to_helper, &helper_write, h); | ||
600 | return; | ||
601 | } | ||
602 | if (NULL == (sh = h->sh_head)) | 587 | if (NULL == (sh = h->sh_head)) |
603 | { | 588 | { |
604 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 589 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -626,9 +611,9 @@ helper_write (void *cls) | |||
626 | "Stopping and restarting helper task!\n"); | 611 | "Stopping and restarting helper task!\n"); |
627 | stop_helper (h, GNUNET_NO); | 612 | stop_helper (h, GNUNET_NO); |
628 | /* Restart the helper */ | 613 | /* Restart the helper */ |
629 | h->restart_task = GNUNET_SCHEDULER_add_delayed( | 614 | h->restart_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, |
630 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, | 615 | h->retry_back_off), |
631 | h->retry_back_off), &restart_task, h); | 616 | &restart_task, h); |
632 | return; | 617 | return; |
633 | } | 618 | } |
634 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 619 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
diff --git a/src/util/mq.c b/src/util/mq.c index aff9f465c..6f8c04224 100644 --- a/src/util/mq.c +++ b/src/util/mq.c | |||
@@ -302,13 +302,8 @@ static void | |||
302 | impl_send_continue (void *cls) | 302 | impl_send_continue (void *cls) |
303 | { | 303 | { |
304 | struct GNUNET_MQ_Handle *mq = cls; | 304 | struct GNUNET_MQ_Handle *mq = cls; |
305 | const struct GNUNET_SCHEDULER_TaskContext *tc; | ||
306 | struct GNUNET_MQ_Envelope *current_envelope; | 305 | struct GNUNET_MQ_Envelope *current_envelope; |
307 | 306 | ||
308 | tc = GNUNET_SCHEDULER_get_task_context (); | ||
309 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | ||
310 | return; | ||
311 | |||
312 | mq->continue_task = NULL; | 307 | mq->continue_task = NULL; |
313 | /* call is only valid if we're actually currently sending | 308 | /* call is only valid if we're actually currently sending |
314 | * a message */ | 309 | * a message */ |
@@ -325,7 +320,9 @@ impl_send_continue (void *cls) | |||
325 | GNUNET_CONTAINER_DLL_remove (mq->envelope_head, | 320 | GNUNET_CONTAINER_DLL_remove (mq->envelope_head, |
326 | mq->envelope_tail, | 321 | mq->envelope_tail, |
327 | mq->current_envelope); | 322 | mq->current_envelope); |
328 | mq->send_impl (mq, mq->current_envelope->mh, mq->impl_state); | 323 | mq->send_impl (mq, |
324 | mq->current_envelope->mh, | ||
325 | mq->impl_state); | ||
329 | } | 326 | } |
330 | if (NULL != current_envelope->sent_cb) | 327 | if (NULL != current_envelope->sent_cb) |
331 | current_envelope->sent_cb (current_envelope->sent_cls); | 328 | current_envelope->sent_cb (current_envelope->sent_cls); |
@@ -334,10 +331,9 @@ impl_send_continue (void *cls) | |||
334 | 331 | ||
335 | 332 | ||
336 | /** | 333 | /** |
337 | * Call the send implementation for the next queued message, | 334 | * Call the send implementation for the next queued message, if any. |
338 | * if any. | 335 | * Only useful for implementing message queues, results in undefined |
339 | * Only useful for implementing message queues, | 336 | * behavior if not used carefully. |
340 | * results in undefined behavior if not used carefully. | ||
341 | * | 337 | * |
342 | * @param mq message queue to send the next message with | 338 | * @param mq message queue to send the next message with |
343 | */ | 339 | */ |
@@ -471,7 +467,9 @@ GNUNET_MQ_msg_nested_mh_ (struct GNUNET_MessageHeader **mhp, | |||
471 | return NULL; | 467 | return NULL; |
472 | 468 | ||
473 | mqm = GNUNET_MQ_msg_ (mhp, size, type); | 469 | mqm = GNUNET_MQ_msg_ (mhp, size, type); |
474 | memcpy ((char *) mqm->mh + base_size, nested_mh, ntohs (nested_mh->size)); | 470 | memcpy ((char *) mqm->mh + base_size, |
471 | nested_mh, | ||
472 | ntohs (nested_mh->size)); | ||
475 | 473 | ||
476 | return mqm; | 474 | return mqm; |
477 | } | 475 | } |
@@ -481,9 +479,9 @@ GNUNET_MQ_msg_nested_mh_ (struct GNUNET_MessageHeader **mhp, | |||
481 | * Transmit a queued message to the session's client. | 479 | * Transmit a queued message to the session's client. |
482 | * | 480 | * |
483 | * @param cls consensus session | 481 | * @param cls consensus session |
484 | * @param size number of bytes available in buf | 482 | * @param size number of bytes available in @a buf |
485 | * @param buf where the callee should write the message | 483 | * @param buf where the callee should write the message |
486 | * @return number of bytes written to buf | 484 | * @return number of bytes written to @a buf |
487 | */ | 485 | */ |
488 | static size_t | 486 | static size_t |
489 | transmit_queued (void *cls, size_t size, | 487 | transmit_queued (void *cls, size_t size, |
@@ -535,10 +533,10 @@ server_client_send_impl (struct GNUNET_MQ_Handle *mq, | |||
535 | 533 | ||
536 | GNUNET_assert (NULL != mq); | 534 | GNUNET_assert (NULL != mq); |
537 | GNUNET_assert (NULL != state); | 535 | GNUNET_assert (NULL != state); |
538 | state->th = | 536 | state->th = GNUNET_SERVER_notify_transmit_ready (state->client, |
539 | GNUNET_SERVER_notify_transmit_ready (state->client, ntohs (msg->size), | 537 | ntohs (msg->size), |
540 | GNUNET_TIME_UNIT_FOREVER_REL, | 538 | GNUNET_TIME_UNIT_FOREVER_REL, |
541 | &transmit_queued, mq); | 539 | &transmit_queued, mq); |
542 | } | 540 | } |
543 | 541 | ||
544 | 542 | ||
@@ -580,10 +578,10 @@ handle_client_message (void *cls, | |||
580 | GNUNET_MQ_inject_error (mq, GNUNET_MQ_ERROR_READ); | 578 | GNUNET_MQ_inject_error (mq, GNUNET_MQ_ERROR_READ); |
581 | return; | 579 | return; |
582 | } | 580 | } |
583 | 581 | GNUNET_CLIENT_receive (state->connection, | |
584 | GNUNET_CLIENT_receive (state->connection, handle_client_message, mq, | 582 | &handle_client_message, |
583 | mq, | ||
585 | GNUNET_TIME_UNIT_FOREVER_REL); | 584 | GNUNET_TIME_UNIT_FOREVER_REL); |
586 | |||
587 | GNUNET_MQ_inject_message (mq, msg); | 585 | GNUNET_MQ_inject_message (mq, msg); |
588 | } | 586 | } |
589 | 587 | ||
@@ -652,7 +650,8 @@ connection_client_send_impl (struct GNUNET_MQ_Handle *mq, | |||
652 | GNUNET_assert (NULL != state); | 650 | GNUNET_assert (NULL != state); |
653 | GNUNET_assert (NULL == state->th); | 651 | GNUNET_assert (NULL == state->th); |
654 | state->th = | 652 | state->th = |
655 | GNUNET_CLIENT_notify_transmit_ready (state->connection, ntohs (msg->size), | 653 | GNUNET_CLIENT_notify_transmit_ready (state->connection, |
654 | ntohs (msg->size), | ||
656 | GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_NO, | 655 | GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_NO, |
657 | &connection_client_transmit_queued, mq); | 656 | &connection_client_transmit_queued, mq); |
658 | GNUNET_assert (NULL != state->th); | 657 | GNUNET_assert (NULL != state->th); |
@@ -752,8 +751,10 @@ GNUNET_MQ_assoc_remove (struct GNUNET_MQ_Handle *mq, | |||
752 | 751 | ||
753 | if (NULL == mq->assoc_map) | 752 | if (NULL == mq->assoc_map) |
754 | return NULL; | 753 | return NULL; |
755 | val = GNUNET_CONTAINER_multihashmap32_get (mq->assoc_map, request_id); | 754 | val = GNUNET_CONTAINER_multihashmap32_get (mq->assoc_map, |
756 | GNUNET_CONTAINER_multihashmap32_remove_all (mq->assoc_map, request_id); | 755 | request_id); |
756 | GNUNET_CONTAINER_multihashmap32_remove_all (mq->assoc_map, | ||
757 | request_id); | ||
757 | return val; | 758 | return val; |
758 | } | 759 | } |
759 | 760 | ||
@@ -785,10 +786,11 @@ GNUNET_MQ_destroy (struct GNUNET_MQ_Handle *mq) | |||
785 | struct GNUNET_MQ_Envelope *ev; | 786 | struct GNUNET_MQ_Envelope *ev; |
786 | ev = mq->envelope_head; | 787 | ev = mq->envelope_head; |
787 | ev->parent_queue = NULL; | 788 | ev->parent_queue = NULL; |
788 | GNUNET_CONTAINER_DLL_remove (mq->envelope_head, mq->envelope_tail, ev); | 789 | GNUNET_CONTAINER_DLL_remove (mq->envelope_head, |
790 | mq->envelope_tail, | ||
791 | ev); | ||
789 | GNUNET_MQ_discard (ev); | 792 | GNUNET_MQ_discard (ev); |
790 | } | 793 | } |
791 | |||
792 | if (NULL != mq->current_envelope) | 794 | if (NULL != mq->current_envelope) |
793 | { | 795 | { |
794 | /* we can only discard envelopes that | 796 | /* we can only discard envelopes that |
@@ -797,7 +799,6 @@ GNUNET_MQ_destroy (struct GNUNET_MQ_Handle *mq) | |||
797 | GNUNET_MQ_discard (mq->current_envelope); | 799 | GNUNET_MQ_discard (mq->current_envelope); |
798 | mq->current_envelope = NULL; | 800 | mq->current_envelope = NULL; |
799 | } | 801 | } |
800 | |||
801 | if (NULL != mq->assoc_map) | 802 | if (NULL != mq->assoc_map) |
802 | { | 803 | { |
803 | GNUNET_CONTAINER_multihashmap32_destroy (mq->assoc_map); | 804 | GNUNET_CONTAINER_multihashmap32_destroy (mq->assoc_map); |
@@ -851,10 +852,12 @@ GNUNET_MQ_send_cancel (struct GNUNET_MQ_Envelope *ev) | |||
851 | GNUNET_assert (NULL != mq); | 852 | GNUNET_assert (NULL != mq); |
852 | GNUNET_assert (NULL != mq->cancel_impl); | 853 | GNUNET_assert (NULL != mq->cancel_impl); |
853 | 854 | ||
854 | if (mq->current_envelope == ev) { | 855 | if (mq->current_envelope == ev) |
856 | { | ||
855 | // complex case, we already started with transmitting | 857 | // complex case, we already started with transmitting |
856 | // the message | 858 | // the message |
857 | mq->cancel_impl (mq, mq->impl_state); | 859 | mq->cancel_impl (mq, |
860 | mq->impl_state); | ||
858 | // continue sending the next message, if any | 861 | // continue sending the next message, if any |
859 | if (NULL == mq->envelope_head) | 862 | if (NULL == mq->envelope_head) |
860 | { | 863 | { |
@@ -866,11 +869,17 @@ GNUNET_MQ_send_cancel (struct GNUNET_MQ_Envelope *ev) | |||
866 | GNUNET_CONTAINER_DLL_remove (mq->envelope_head, | 869 | GNUNET_CONTAINER_DLL_remove (mq->envelope_head, |
867 | mq->envelope_tail, | 870 | mq->envelope_tail, |
868 | mq->current_envelope); | 871 | mq->current_envelope); |
869 | mq->send_impl (mq, mq->current_envelope->mh, mq->impl_state); | 872 | mq->send_impl (mq, |
873 | mq->current_envelope->mh, | ||
874 | mq->impl_state); | ||
870 | } | 875 | } |
871 | } else { | 876 | } |
877 | else | ||
878 | { | ||
872 | // simple case, message is still waiting in the queue | 879 | // simple case, message is still waiting in the queue |
873 | GNUNET_CONTAINER_DLL_remove (mq->envelope_head, mq->envelope_tail, ev); | 880 | GNUNET_CONTAINER_DLL_remove (mq->envelope_head, |
881 | mq->envelope_tail, | ||
882 | ev); | ||
874 | } | 883 | } |
875 | 884 | ||
876 | ev->parent_queue = NULL; | 885 | ev->parent_queue = NULL; |
diff --git a/src/util/os_installation.c b/src/util/os_installation.c index 161b0535f..a0e8647a1 100644 --- a/src/util/os_installation.c +++ b/src/util/os_installation.c | |||
@@ -62,7 +62,7 @@ static const struct GNUNET_OS_ProjectData default_pd = { | |||
62 | .bug_email = "gnunet-developers@gnu.org", | 62 | .bug_email = "gnunet-developers@gnu.org", |
63 | .homepage = "http://www.gnu.org/s/gnunet/", | 63 | .homepage = "http://www.gnu.org/s/gnunet/", |
64 | .config_file = "gnunet.conf", | 64 | .config_file = "gnunet.conf", |
65 | .user_config_file = "~/.config/gnunet.conf" | 65 | .user_config_file = "~/.config/gnunet.conf", |
66 | }; | 66 | }; |
67 | 67 | ||
68 | /** | 68 | /** |
diff --git a/src/util/os_priority.c b/src/util/os_priority.c index 8dfec6c5e..2a6ea8321 100644 --- a/src/util/os_priority.c +++ b/src/util/os_priority.c | |||
@@ -65,49 +65,68 @@ struct GNUNET_OS_Process | |||
65 | */ | 65 | */ |
66 | static struct GNUNET_OS_Process current_process; | 66 | static struct GNUNET_OS_Process current_process; |
67 | 67 | ||
68 | /** | ||
69 | * Handle for the #parent_control_handler() Task. | ||
70 | */ | ||
71 | static struct GNUNET_SCHEDULER_Task *pch; | ||
72 | |||
73 | |||
74 | /** | ||
75 | * This handler is called on shutdown to remove the #pch. | ||
76 | * | ||
77 | * @param cls the `struct GNUNET_DISK_FileHandle` of the control pipe | ||
78 | */ | ||
79 | static void | ||
80 | shutdown_pch (void *cls) | ||
81 | { | ||
82 | struct GNUNET_DISK_FileHandle *control_pipe = cls; | ||
83 | |||
84 | GNUNET_SCHEDULER_cancel (pch); | ||
85 | pch = NULL; | ||
86 | GNUNET_DISK_file_close (control_pipe); | ||
87 | control_pipe = NULL; | ||
88 | } | ||
89 | |||
68 | 90 | ||
69 | /** | 91 | /** |
70 | * This handler is called when there are control data to be read on the pipe | 92 | * This handler is called when there are control data to be read on the pipe |
71 | * | 93 | * |
72 | * @param cls the 'struct GNUNET_DISK_FileHandle' of the control pipe | 94 | * @param cls the `struct GNUNET_DISK_FileHandle` of the control pipe |
73 | */ | 95 | */ |
74 | static void | 96 | static void |
75 | parent_control_handler (void *cls) | 97 | parent_control_handler (void *cls) |
76 | { | 98 | { |
77 | struct GNUNET_DISK_FileHandle *control_pipe = cls; | 99 | struct GNUNET_DISK_FileHandle *control_pipe = cls; |
78 | const struct GNUNET_SCHEDULER_TaskContext *tc; | ||
79 | char sig; | 100 | char sig; |
80 | char *pipe_fd; | 101 | char *pipe_fd; |
81 | ssize_t ret; | 102 | ssize_t ret; |
82 | 103 | ||
83 | tc = GNUNET_SCHEDULER_get_task_context (); | 104 | pch = NULL; |
84 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 105 | ret = GNUNET_DISK_file_read (control_pipe, |
85 | "`%s' invoked because of %d\n", __FUNCTION__, | 106 | &sig, |
86 | tc->reason); | 107 | sizeof (sig)); |
87 | if (0 != (tc->reason & | ||
88 | (GNUNET_SCHEDULER_REASON_SHUTDOWN | GNUNET_SCHEDULER_REASON_TIMEOUT))) | ||
89 | { | ||
90 | GNUNET_DISK_file_close (control_pipe); | ||
91 | control_pipe = NULL; | ||
92 | return; | ||
93 | } | ||
94 | ret = GNUNET_DISK_file_read (control_pipe, &sig, sizeof (sig)); | ||
95 | if (sizeof (sig) != ret) | 108 | if (sizeof (sig) != ret) |
96 | { | 109 | { |
97 | if (-1 == ret) | 110 | if (-1 == ret) |
98 | LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "GNUNET_DISK_file_read"); | 111 | LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, |
99 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Closing control pipe\n"); | 112 | "GNUNET_DISK_file_read"); |
113 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
114 | "Closing control pipe\n"); | ||
100 | GNUNET_DISK_file_close (control_pipe); | 115 | GNUNET_DISK_file_close (control_pipe); |
101 | control_pipe = NULL; | 116 | control_pipe = NULL; |
102 | return; | 117 | return; |
103 | } | 118 | } |
104 | pipe_fd = getenv (GNUNET_OS_CONTROL_PIPE); | 119 | pipe_fd = getenv (GNUNET_OS_CONTROL_PIPE); |
105 | GNUNET_assert ( (NULL == pipe_fd) || (strlen (pipe_fd) <= 0) ); | 120 | GNUNET_assert ( (NULL == pipe_fd) || |
121 | (strlen (pipe_fd) <= 0) ); | ||
106 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 122 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
107 | "Got control code %d from parent via pipe %s\n", sig, pipe_fd); | 123 | "Got control code %d from parent via pipe %s\n", |
108 | GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, | 124 | sig, |
109 | control_pipe, &parent_control_handler, | 125 | pipe_fd); |
110 | control_pipe); | 126 | pch = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, |
127 | control_pipe, | ||
128 | &parent_control_handler, | ||
129 | control_pipe); | ||
111 | GNUNET_SIGNAL_raise ((int) sig); | 130 | GNUNET_SIGNAL_raise ((int) sig); |
112 | } | 131 | } |
113 | 132 | ||
@@ -115,7 +134,7 @@ parent_control_handler (void *cls) | |||
115 | /** | 134 | /** |
116 | * Task that connects this process to its parent via pipe; | 135 | * Task that connects this process to its parent via pipe; |
117 | * essentially, the parent control handler will read signal numbers | 136 | * essentially, the parent control handler will read signal numbers |
118 | * from the 'GNUNET_OS_CONTROL_PIPE' (as given in an environment | 137 | * from the #GNUNET_OS_CONTROL_PIPE (as given in an environment |
119 | * variable) and raise those signals. | 138 | * variable) and raise those signals. |
120 | * | 139 | * |
121 | * @param cls closure (unused) | 140 | * @param cls closure (unused) |
@@ -128,6 +147,12 @@ GNUNET_OS_install_parent_control_handler (void *cls) | |||
128 | struct GNUNET_DISK_FileHandle *control_pipe; | 147 | struct GNUNET_DISK_FileHandle *control_pipe; |
129 | uint64_t pipe_fd; | 148 | uint64_t pipe_fd; |
130 | 149 | ||
150 | if (NULL != pch) | ||
151 | { | ||
152 | /* already done, we've been called twice... */ | ||
153 | GNUNET_break (0); | ||
154 | return; | ||
155 | } | ||
131 | env_buf = getenv (GNUNET_OS_CONTROL_PIPE); | 156 | env_buf = getenv (GNUNET_OS_CONTROL_PIPE); |
132 | if ( (NULL == env_buf) || (strlen (env_buf) <= 0) ) | 157 | if ( (NULL == env_buf) || (strlen (env_buf) <= 0) ) |
133 | { | 158 | { |
@@ -141,7 +166,9 @@ GNUNET_OS_install_parent_control_handler (void *cls) | |||
141 | pipe_fd = strtoull (env_buf, &env_buf_end, 16); | 166 | pipe_fd = strtoull (env_buf, &env_buf_end, 16); |
142 | if ((0 != errno) || (env_buf == env_buf_end)) | 167 | if ((0 != errno) || (env_buf == env_buf_end)) |
143 | { | 168 | { |
144 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "strtoull", env_buf); | 169 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, |
170 | "strtoull", | ||
171 | env_buf); | ||
145 | putenv (GNUNET_OS_CONTROL_PIPE "="); | 172 | putenv (GNUNET_OS_CONTROL_PIPE "="); |
146 | return; | 173 | return; |
147 | } | 174 | } |
@@ -153,7 +180,8 @@ GNUNET_OS_install_parent_control_handler (void *cls) | |||
153 | #endif | 180 | #endif |
154 | { | 181 | { |
155 | LOG (GNUNET_ERROR_TYPE_ERROR, | 182 | LOG (GNUNET_ERROR_TYPE_ERROR, |
156 | "GNUNET_OS_CONTROL_PIPE `%s' contains garbage?\n", env_buf); | 183 | "GNUNET_OS_CONTROL_PIPE `%s' contains garbage?\n", |
184 | env_buf); | ||
157 | putenv (GNUNET_OS_CONTROL_PIPE "="); | 185 | putenv (GNUNET_OS_CONTROL_PIPE "="); |
158 | return; | 186 | return; |
159 | } | 187 | } |
@@ -164,14 +192,21 @@ GNUNET_OS_install_parent_control_handler (void *cls) | |||
164 | #endif | 192 | #endif |
165 | if (NULL == control_pipe) | 193 | if (NULL == control_pipe) |
166 | { | 194 | { |
167 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "open", env_buf); | 195 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, |
196 | "open", | ||
197 | env_buf); | ||
168 | putenv (GNUNET_OS_CONTROL_PIPE "="); | 198 | putenv (GNUNET_OS_CONTROL_PIPE "="); |
169 | return; | 199 | return; |
170 | } | 200 | } |
171 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 201 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
172 | "Adding parent control handler pipe `%s' to the scheduler\n", env_buf); | 202 | "Adding parent control handler pipe `%s' to the scheduler\n", |
173 | GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, control_pipe, | 203 | env_buf); |
174 | &parent_control_handler, control_pipe); | 204 | pch = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, |
205 | control_pipe, | ||
206 | &parent_control_handler, | ||
207 | control_pipe); | ||
208 | GNUNET_SCHEDULER_add_shutdown (&shutdown_pch, | ||
209 | control_pipe); | ||
175 | putenv (GNUNET_OS_CONTROL_PIPE "="); | 210 | putenv (GNUNET_OS_CONTROL_PIPE "="); |
176 | } | 211 | } |
177 | 212 | ||
@@ -179,8 +214,8 @@ GNUNET_OS_install_parent_control_handler (void *cls) | |||
179 | /** | 214 | /** |
180 | * Get process structure for current process | 215 | * Get process structure for current process |
181 | * | 216 | * |
182 | * The pointer it returns points to static memory location and must not be | 217 | * The pointer it returns points to static memory location and must |
183 | * deallocated/closed | 218 | * not be deallocated/closed. |
184 | * | 219 | * |
185 | * @return pointer to the process sturcutre for this process | 220 | * @return pointer to the process sturcutre for this process |
186 | */ | 221 | */ |
@@ -205,7 +240,8 @@ GNUNET_OS_process_current () | |||
205 | * @return 0 on success, -1 on error | 240 | * @return 0 on success, -1 on error |
206 | */ | 241 | */ |
207 | int | 242 | int |
208 | GNUNET_OS_process_kill (struct GNUNET_OS_Process *proc, int sig) | 243 | GNUNET_OS_process_kill (struct GNUNET_OS_Process *proc, |
244 | int sig) | ||
209 | { | 245 | { |
210 | int ret; | 246 | int ret; |
211 | char csig; | 247 | char csig; |
@@ -213,8 +249,13 @@ GNUNET_OS_process_kill (struct GNUNET_OS_Process *proc, int sig) | |||
213 | csig = (char) sig; | 249 | csig = (char) sig; |
214 | if (NULL != proc->control_pipe) | 250 | if (NULL != proc->control_pipe) |
215 | { | 251 | { |
216 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Sending signal %d to pid: %u via pipe\n", sig, proc->pid); | 252 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
217 | ret = GNUNET_DISK_file_write (proc->control_pipe, &csig, sizeof (csig)); | 253 | "Sending signal %d to pid: %u via pipe\n", |
254 | sig, | ||
255 | proc->pid); | ||
256 | ret = GNUNET_DISK_file_write (proc->control_pipe, | ||
257 | &csig, | ||
258 | sizeof (csig)); | ||
218 | if (sizeof (csig) == ret) | 259 | if (sizeof (csig) == ret) |
219 | return 0; | 260 | return 0; |
220 | } | 261 | } |
@@ -237,14 +278,17 @@ GNUNET_OS_process_kill (struct GNUNET_OS_Process *proc, int sig) | |||
237 | if (0 != GetExitCodeProcess (proc->handle, &exitcode)) | 278 | if (0 != GetExitCodeProcess (proc->handle, &exitcode)) |
238 | must_kill = (exitcode == STILL_ACTIVE) ? GNUNET_YES : GNUNET_NO; | 279 | must_kill = (exitcode == STILL_ACTIVE) ? GNUNET_YES : GNUNET_NO; |
239 | if (GNUNET_YES == must_kill) | 280 | if (GNUNET_YES == must_kill) |
281 | { | ||
240 | if (0 == SafeTerminateProcess (proc->handle, 0, 0)) | 282 | if (0 == SafeTerminateProcess (proc->handle, 0, 0)) |
241 | { | 283 | { |
242 | DWORD error_code = GetLastError (); | 284 | DWORD error_code = GetLastError (); |
243 | if ((error_code != WAIT_TIMEOUT) && (error_code != ERROR_PROCESS_ABORTED)) | 285 | if ( (error_code != WAIT_TIMEOUT) && |
286 | (error_code != ERROR_PROCESS_ABORTED) ) | ||
244 | { | 287 | { |
245 | LOG ((error_code == ERROR_ACCESS_DENIED) ? | 288 | LOG ((error_code == ERROR_ACCESS_DENIED) ? |
246 | GNUNET_ERROR_TYPE_INFO : GNUNET_ERROR_TYPE_WARNING, | 289 | GNUNET_ERROR_TYPE_INFO : GNUNET_ERROR_TYPE_WARNING, |
247 | "SafeTermiateProcess failed with code %lu\n", error_code); | 290 | "SafeTermiateProcess failed with code %lu\n", |
291 | error_code); | ||
248 | /* The problem here is that a process that is already dying | 292 | /* The problem here is that a process that is already dying |
249 | * might cause SafeTerminateProcess to fail with | 293 | * might cause SafeTerminateProcess to fail with |
250 | * ERROR_ACCESS_DENIED, but the process WILL die eventually. | 294 | * ERROR_ACCESS_DENIED, but the process WILL die eventually. |
@@ -263,6 +307,7 @@ GNUNET_OS_process_kill (struct GNUNET_OS_Process *proc, int sig) | |||
263 | } | 307 | } |
264 | } | 308 | } |
265 | } | 309 | } |
310 | } | ||
266 | } | 311 | } |
267 | return 0; | 312 | return 0; |
268 | #else | 313 | #else |
@@ -277,12 +322,16 @@ GNUNET_OS_process_kill (struct GNUNET_OS_Process *proc, int sig) | |||
277 | errno = EINVAL; | 322 | errno = EINVAL; |
278 | return -1; | 323 | return -1; |
279 | #else | 324 | #else |
280 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Sending signal %d to pid: %u via system call\n", sig, proc->pid); | 325 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
326 | "Sending signal %d to pid: %u via system call\n", | ||
327 | sig, | ||
328 | proc->pid); | ||
281 | return PLIBC_KILL (proc->pid, sig); | 329 | return PLIBC_KILL (proc->pid, sig); |
282 | #endif | 330 | #endif |
283 | } | 331 | } |
284 | } | 332 | } |
285 | 333 | ||
334 | |||
286 | /** | 335 | /** |
287 | * Get the pid of the process in question | 336 | * Get the pid of the process in question |
288 | * | 337 | * |
@@ -298,7 +347,8 @@ GNUNET_OS_process_get_pid (struct GNUNET_OS_Process * proc) | |||
298 | 347 | ||
299 | 348 | ||
300 | /** | 349 | /** |
301 | * Cleans up process structure contents (OS-dependent) and deallocates it | 350 | * Cleans up process structure contents (OS-dependent) and deallocates |
351 | * it. | ||
302 | * | 352 | * |
303 | * @param proc pointer to process structure | 353 | * @param proc pointer to process structure |
304 | */ | 354 | */ |
@@ -314,6 +364,7 @@ GNUNET_OS_process_destroy (struct GNUNET_OS_Process *proc) | |||
314 | GNUNET_free (proc); | 364 | GNUNET_free (proc); |
315 | } | 365 | } |
316 | 366 | ||
367 | |||
317 | #if WINDOWS | 368 | #if WINDOWS |
318 | #include "gnunet_signal_lib.h" | 369 | #include "gnunet_signal_lib.h" |
319 | 370 | ||
@@ -324,6 +375,7 @@ extern GNUNET_SIGNAL_Handler w32_sigchld_handler; | |||
324 | */ | 375 | */ |
325 | #define DWORD_WINAPI DWORD WINAPI | 376 | #define DWORD_WINAPI DWORD WINAPI |
326 | 377 | ||
378 | |||
327 | /** | 379 | /** |
328 | * @brief Waits for a process to terminate and invokes the SIGCHLD handler | 380 | * @brief Waits for a process to terminate and invokes the SIGCHLD handler |
329 | * @param proc pointer to process structure | 381 | * @param proc pointer to process structure |
@@ -467,7 +519,9 @@ open_dev_null (int target_fd, | |||
467 | fd = open ("/dev/null", flags); | 519 | fd = open ("/dev/null", flags); |
468 | if (-1 == fd) | 520 | if (-1 == fd) |
469 | { | 521 | { |
470 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open", "/dev/null"); | 522 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, |
523 | "open", | ||
524 | "/dev/null"); | ||
471 | return; | 525 | return; |
472 | } | 526 | } |
473 | if (fd == target_fd) | 527 | if (fd == target_fd) |
@@ -531,23 +585,30 @@ start_process (int pipe_control, | |||
531 | int fd_stdin_read; | 585 | int fd_stdin_read; |
532 | int fd_stdin_write; | 586 | int fd_stdin_write; |
533 | 587 | ||
534 | if (GNUNET_SYSERR == GNUNET_OS_check_helper_binary (filename, GNUNET_NO, NULL)) | 588 | if (GNUNET_SYSERR == |
589 | GNUNET_OS_check_helper_binary (filename, GNUNET_NO, NULL)) | ||
535 | return NULL; /* not executable */ | 590 | return NULL; /* not executable */ |
536 | if (GNUNET_YES == pipe_control) | 591 | if (GNUNET_YES == pipe_control) |
537 | { | 592 | { |
538 | struct GNUNET_DISK_PipeHandle *childpipe; | 593 | struct GNUNET_DISK_PipeHandle *childpipe; |
539 | int dup_childpipe_read_fd = -1; | 594 | int dup_childpipe_read_fd = -1; |
540 | 595 | ||
541 | childpipe = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, GNUNET_YES, GNUNET_NO); | 596 | childpipe = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, |
597 | GNUNET_YES, GNUNET_NO); | ||
542 | if (NULL == childpipe) | 598 | if (NULL == childpipe) |
543 | return NULL; | 599 | return NULL; |
544 | childpipe_read = GNUNET_DISK_pipe_detach_end (childpipe, GNUNET_DISK_PIPE_END_READ); | 600 | childpipe_read = GNUNET_DISK_pipe_detach_end (childpipe, |
545 | childpipe_write = GNUNET_DISK_pipe_detach_end (childpipe, GNUNET_DISK_PIPE_END_WRITE); | 601 | GNUNET_DISK_PIPE_END_READ); |
602 | childpipe_write = GNUNET_DISK_pipe_detach_end (childpipe, | ||
603 | GNUNET_DISK_PIPE_END_WRITE); | ||
546 | GNUNET_DISK_pipe_close (childpipe); | 604 | GNUNET_DISK_pipe_close (childpipe); |
547 | if ((NULL == childpipe_read) || (NULL == childpipe_write) || | 605 | if ( (NULL == childpipe_read) || |
548 | (GNUNET_OK != GNUNET_DISK_internal_file_handle_ (childpipe_read, | 606 | (NULL == childpipe_write) || |
549 | &childpipe_read_fd, sizeof (int))) || | 607 | (GNUNET_OK != |
550 | (-1 == (dup_childpipe_read_fd = dup (childpipe_read_fd)))) | 608 | GNUNET_DISK_internal_file_handle_ (childpipe_read, |
609 | &childpipe_read_fd, | ||
610 | sizeof (int))) || | ||
611 | (-1 == (dup_childpipe_read_fd = dup (childpipe_read_fd)))) | ||
551 | { | 612 | { |
552 | if (NULL != childpipe_read) | 613 | if (NULL != childpipe_read) |
553 | GNUNET_DISK_file_close (childpipe_read); | 614 | GNUNET_DISK_file_close (childpipe_read); |
@@ -1762,17 +1823,19 @@ cmd_read (void *cls) | |||
1762 | 1823 | ||
1763 | cmd->rtask = NULL; | 1824 | cmd->rtask = NULL; |
1764 | tc = GNUNET_SCHEDULER_get_task_context (); | 1825 | tc = GNUNET_SCHEDULER_get_task_context (); |
1765 | if (GNUNET_YES != GNUNET_NETWORK_fdset_handle_isset (tc->read_ready, cmd->r)) | 1826 | if (GNUNET_YES != |
1827 | GNUNET_NETWORK_fdset_handle_isset (tc->read_ready, | ||
1828 | cmd->r)) | ||
1766 | { | 1829 | { |
1767 | /* timeout, shutdown, etc. */ | 1830 | /* timeout */ |
1768 | proc = cmd->proc; | 1831 | proc = cmd->proc; |
1769 | cmd->proc = NULL; | 1832 | cmd->proc = NULL; |
1770 | proc (cmd->proc_cls, NULL); | 1833 | proc (cmd->proc_cls, NULL); |
1771 | return; | 1834 | return; |
1772 | } | 1835 | } |
1773 | ret = | 1836 | ret = GNUNET_DISK_file_read (cmd->r, |
1774 | GNUNET_DISK_file_read (cmd->r, &cmd->buf[cmd->off], | 1837 | &cmd->buf[cmd->off], |
1775 | sizeof (cmd->buf) - cmd->off); | 1838 | sizeof (cmd->buf) - cmd->off); |
1776 | if (ret <= 0) | 1839 | if (ret <= 0) |
1777 | { | 1840 | { |
1778 | if ((cmd->off > 0) && (cmd->off < sizeof (cmd->buf))) | 1841 | if ((cmd->off > 0) && (cmd->off < sizeof (cmd->buf))) |
@@ -1795,9 +1858,11 @@ cmd_read (void *cls) | |||
1795 | cmd->off -= (end + 1 - cmd->buf); | 1858 | cmd->off -= (end + 1 - cmd->buf); |
1796 | end = memchr (cmd->buf, '\n', cmd->off); | 1859 | end = memchr (cmd->buf, '\n', cmd->off); |
1797 | } | 1860 | } |
1798 | cmd->rtask = | 1861 | cmd->rtask |
1799 | GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_absolute_get_remaining | 1862 | = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_absolute_get_remaining |
1800 | (cmd->timeout), cmd->r, &cmd_read, cmd); | 1863 | (cmd->timeout), |
1864 | cmd->r, | ||
1865 | &cmd_read, cmd); | ||
1801 | } | 1866 | } |
1802 | 1867 | ||
1803 | 1868 | ||
@@ -1824,12 +1889,15 @@ GNUNET_OS_command_run (GNUNET_OS_LineProcessor proc, | |||
1824 | struct GNUNET_DISK_PipeHandle *opipe; | 1889 | struct GNUNET_DISK_PipeHandle *opipe; |
1825 | va_list ap; | 1890 | va_list ap; |
1826 | 1891 | ||
1827 | opipe = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_NO, GNUNET_YES); | 1892 | opipe = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, |
1893 | GNUNET_NO, GNUNET_YES); | ||
1828 | if (NULL == opipe) | 1894 | if (NULL == opipe) |
1829 | return NULL; | 1895 | return NULL; |
1830 | va_start (ap, binary); | 1896 | va_start (ap, binary); |
1831 | /* redirect stdout, don't inherit stderr/stdin */ | 1897 | /* redirect stdout, don't inherit stderr/stdin */ |
1832 | eip = GNUNET_OS_start_process_va (GNUNET_NO, 0, NULL, opipe, NULL, binary, ap); | 1898 | eip = GNUNET_OS_start_process_va (GNUNET_NO, 0, NULL, |
1899 | opipe, NULL, binary, | ||
1900 | ap); | ||
1833 | va_end (ap); | 1901 | va_end (ap); |
1834 | if (NULL == eip) | 1902 | if (NULL == eip) |
1835 | { | 1903 | { |
@@ -1843,8 +1911,12 @@ GNUNET_OS_command_run (GNUNET_OS_LineProcessor proc, | |||
1843 | cmd->opipe = opipe; | 1911 | cmd->opipe = opipe; |
1844 | cmd->proc = proc; | 1912 | cmd->proc = proc; |
1845 | cmd->proc_cls = proc_cls; | 1913 | cmd->proc_cls = proc_cls; |
1846 | cmd->r = GNUNET_DISK_pipe_handle (opipe, GNUNET_DISK_PIPE_END_READ); | 1914 | cmd->r = GNUNET_DISK_pipe_handle (opipe, |
1847 | cmd->rtask = GNUNET_SCHEDULER_add_read_file (timeout, cmd->r, &cmd_read, cmd); | 1915 | GNUNET_DISK_PIPE_END_READ); |
1916 | cmd->rtask = GNUNET_SCHEDULER_add_read_file (timeout, | ||
1917 | cmd->r, | ||
1918 | &cmd_read, | ||
1919 | cmd); | ||
1848 | return cmd; | 1920 | return cmd; |
1849 | } | 1921 | } |
1850 | 1922 | ||
diff --git a/src/util/program.c b/src/util/program.c index bf7885fe9..72f6a1e6c 100644 --- a/src/util/program.c +++ b/src/util/program.c | |||
@@ -76,11 +76,7 @@ static void | |||
76 | program_main (void *cls) | 76 | program_main (void *cls) |
77 | { | 77 | { |
78 | struct CommandContext *cc = cls; | 78 | struct CommandContext *cc = cls; |
79 | const struct GNUNET_SCHEDULER_TaskContext *tc; | ||
80 | 79 | ||
81 | tc = GNUNET_SCHEDULER_get_task_context (); | ||
82 | if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason)) | ||
83 | return; | ||
84 | GNUNET_SPEEDUP_start_(cc->cfg); | 80 | GNUNET_SPEEDUP_start_(cc->cfg); |
85 | GNUNET_RESOLVER_connect (cc->cfg); | 81 | GNUNET_RESOLVER_connect (cc->cfg); |
86 | cc->task (cc->task_cls, cc->args, cc->cfgfile, cc->cfg); | 82 | cc->task (cc->task_cls, cc->args, cc->cfgfile, cc->cfg); |
diff --git a/src/util/resolver_api.c b/src/util/resolver_api.c index e7a836f03..0488d6a3c 100644 --- a/src/util/resolver_api.c +++ b/src/util/resolver_api.c | |||
@@ -118,7 +118,7 @@ struct GNUNET_RESOLVER_RequestHandle | |||
118 | GNUNET_RESOLVER_HostnameCallback name_callback; | 118 | GNUNET_RESOLVER_HostnameCallback name_callback; |
119 | 119 | ||
120 | /** | 120 | /** |
121 | * Closure for the respective "callback". | 121 | * Closure for the callbacks. |
122 | */ | 122 | */ |
123 | void *cls; | 123 | void *cls; |
124 | 124 | ||
@@ -131,7 +131,7 @@ struct GNUNET_RESOLVER_RequestHandle | |||
131 | * Task handle for making reply callbacks in numeric lookups | 131 | * Task handle for making reply callbacks in numeric lookups |
132 | * asynchronous, and for timeout handling. | 132 | * asynchronous, and for timeout handling. |
133 | */ | 133 | */ |
134 | struct GNUNET_SCHEDULER_Task * task; | 134 | struct GNUNET_SCHEDULER_Task *task; |
135 | 135 | ||
136 | /** | 136 | /** |
137 | * Desired address family. | 137 | * Desired address family. |
@@ -638,6 +638,7 @@ loopback_resolution (void *cls) | |||
638 | rh->addr_callback (rh->cls, | 638 | rh->addr_callback (rh->cls, |
639 | (const struct sockaddr *) &v4, | 639 | (const struct sockaddr *) &v4, |
640 | sizeof (v4)); | 640 | sizeof (v4)); |
641 | |||
641 | break; | 642 | break; |
642 | default: | 643 | default: |
643 | GNUNET_break (0); | 644 | GNUNET_break (0); |
@@ -683,7 +684,7 @@ process_requests () | |||
683 | /* nothing to do, release socket really soon if there is nothing | 684 | /* nothing to do, release socket really soon if there is nothing |
684 | * else happening... */ | 685 | * else happening... */ |
685 | s_task = | 686 | s_task = |
686 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MILLISECONDS, | 687 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, |
687 | &shutdown_task, | 688 | &shutdown_task, |
688 | NULL); | 689 | NULL); |
689 | return; | 690 | return; |
@@ -727,14 +728,9 @@ process_requests () | |||
727 | static void | 728 | static void |
728 | reconnect_task (void *cls) | 729 | reconnect_task (void *cls) |
729 | { | 730 | { |
730 | const struct GNUNET_SCHEDULER_TaskContext *tc; | ||
731 | |||
732 | r_task = NULL; | 731 | r_task = NULL; |
733 | if (NULL == req_head) | 732 | if (NULL == req_head) |
734 | return; /* no work pending */ | 733 | return; /* no work pending */ |
735 | tc = GNUNET_SCHEDULER_get_task_context (); | ||
736 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | ||
737 | return; | ||
738 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 734 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
739 | "Trying to connect to DNS service\n"); | 735 | "Trying to connect to DNS service\n"); |
740 | client = GNUNET_CLIENT_connect ("resolver", | 736 | client = GNUNET_CLIENT_connect ("resolver", |
@@ -774,7 +770,9 @@ reconnect () | |||
774 | break; | 770 | break; |
775 | case GNUNET_SYSERR: | 771 | case GNUNET_SYSERR: |
776 | /* request was cancelled, remove entirely */ | 772 | /* request was cancelled, remove entirely */ |
777 | GNUNET_CONTAINER_DLL_remove (req_head, req_tail, rh); | 773 | GNUNET_CONTAINER_DLL_remove (req_head, |
774 | req_tail, | ||
775 | rh); | ||
778 | GNUNET_free (rh); | 776 | GNUNET_free (rh); |
779 | break; | 777 | break; |
780 | default: | 778 | default: |
diff --git a/src/util/scheduler.c b/src/util/scheduler.c index dcf5aeeaa..81f968dee 100644 --- a/src/util/scheduler.c +++ b/src/util/scheduler.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet | 2 | This file is part of GNUnet |
3 | Copyright (C) 2009-2013 GNUnet e.V. | 3 | Copyright (C) 2009-2016 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as published |
@@ -152,6 +152,11 @@ struct GNUNET_SCHEDULER_Task | |||
152 | int lifeness; | 152 | int lifeness; |
153 | 153 | ||
154 | /** | 154 | /** |
155 | * Is this task run on shutdown? | ||
156 | */ | ||
157 | int on_shutdown; | ||
158 | |||
159 | /** | ||
155 | * Is this task in the ready list? | 160 | * Is this task in the ready list? |
156 | */ | 161 | */ |
157 | int in_ready_list; | 162 | int in_ready_list; |
@@ -184,6 +189,16 @@ static struct GNUNET_SCHEDULER_Task *pending_head; | |||
184 | static struct GNUNET_SCHEDULER_Task *pending_tail; | 189 | static struct GNUNET_SCHEDULER_Task *pending_tail; |
185 | 190 | ||
186 | /** | 191 | /** |
192 | * Head of list of tasks waiting for shutdown. | ||
193 | */ | ||
194 | static struct GNUNET_SCHEDULER_Task *shutdown_head; | ||
195 | |||
196 | /** | ||
197 | * Tail of list of tasks waiting for shutdown. | ||
198 | */ | ||
199 | static struct GNUNET_SCHEDULER_Task *shutdown_tail; | ||
200 | |||
201 | /** | ||
187 | * List of tasks waiting ONLY for a timeout event. | 202 | * List of tasks waiting ONLY for a timeout event. |
188 | * Sorted by timeout (earliest first). Used so that | 203 | * Sorted by timeout (earliest first). Used so that |
189 | * we do not traverse the list of these tasks when | 204 | * we do not traverse the list of these tasks when |
@@ -421,8 +436,6 @@ queue_ready_task (struct GNUNET_SCHEDULER_Task *task) | |||
421 | { | 436 | { |
422 | enum GNUNET_SCHEDULER_Priority p = check_priority (task->priority); | 437 | enum GNUNET_SCHEDULER_Priority p = check_priority (task->priority); |
423 | 438 | ||
424 | if (0 != (task->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | ||
425 | p = task->priority = GNUNET_SCHEDULER_PRIORITY_SHUTDOWN; | ||
426 | GNUNET_CONTAINER_DLL_insert (ready_head[p], | 439 | GNUNET_CONTAINER_DLL_insert (ready_head[p], |
427 | ready_tail[p], | 440 | ready_tail[p], |
428 | task); | 441 | task); |
@@ -477,29 +490,24 @@ check_ready (const struct GNUNET_NETWORK_FDSet *rs, | |||
477 | 490 | ||
478 | 491 | ||
479 | /** | 492 | /** |
480 | * Request the shutdown of a scheduler. Marks all currently | 493 | * Request the shutdown of a scheduler. Marks all tasks |
481 | * pending tasks as ready because of shutdown. This will | 494 | * awaiting shutdown as ready. Note that tasks |
482 | * cause all tasks to run (as soon as possible, respecting | 495 | * scheduled with #GNUNET_SCHEDULER_add_shutdown() AFTER this call |
483 | * priorities and prerequisite tasks). Note that tasks | 496 | * will be delayed until the next shutdown signal. |
484 | * scheduled AFTER this call may still be delayed arbitrarily. | ||
485 | * | ||
486 | * Note that we don't move the tasks into the ready queue yet; | ||
487 | * check_ready() will do that later, possibly adding additional | ||
488 | * readiness-factors | ||
489 | */ | 497 | */ |
490 | void | 498 | void |
491 | GNUNET_SCHEDULER_shutdown () | 499 | GNUNET_SCHEDULER_shutdown () |
492 | { | 500 | { |
493 | struct GNUNET_SCHEDULER_Task *pos; | 501 | struct GNUNET_SCHEDULER_Task *pos; |
494 | int i; | ||
495 | 502 | ||
496 | for (pos = pending_timeout_head; NULL != pos; pos = pos->next) | 503 | while (NULL != (pos = shutdown_head)) |
497 | pos->reason |= GNUNET_SCHEDULER_REASON_SHUTDOWN; | 504 | { |
498 | for (pos = pending_head; NULL != pos; pos = pos->next) | 505 | GNUNET_CONTAINER_DLL_remove (shutdown_head, |
506 | shutdown_tail, | ||
507 | pos); | ||
499 | pos->reason |= GNUNET_SCHEDULER_REASON_SHUTDOWN; | 508 | pos->reason |= GNUNET_SCHEDULER_REASON_SHUTDOWN; |
500 | for (i = 0; i < GNUNET_SCHEDULER_PRIORITY_COUNT; i++) | 509 | queue_ready_task (pos); |
501 | for (pos = ready_head[i]; NULL != pos; pos = pos->next) | 510 | } |
502 | pos->reason |= GNUNET_SCHEDULER_REASON_SHUTDOWN; | ||
503 | } | 511 | } |
504 | 512 | ||
505 | 513 | ||
@@ -523,6 +531,27 @@ destroy_task (struct GNUNET_SCHEDULER_Task *t) | |||
523 | 531 | ||
524 | 532 | ||
525 | /** | 533 | /** |
534 | * Output stack trace of task @a t. | ||
535 | * | ||
536 | * @param t task to dump stack trace of | ||
537 | */ | ||
538 | static void | ||
539 | dump_backtrace (struct GNUNET_SCHEDULER_Task *t) | ||
540 | { | ||
541 | #if EXECINFO | ||
542 | unsigned int i; | ||
543 | |||
544 | for (i = 0; i < t->num_backtrace_strings; i++) | ||
545 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
546 | "Task %p trace %u: %s\n", | ||
547 | t, | ||
548 | i, | ||
549 | t->backtrace_strings[i]); | ||
550 | #endif | ||
551 | } | ||
552 | |||
553 | |||
554 | /** | ||
526 | * Run at least one task in the highest-priority queue that is not | 555 | * Run at least one task in the highest-priority queue that is not |
527 | * empty. Keep running tasks until we are either no longer running | 556 | * empty. Keep running tasks until we are either no longer running |
528 | * "URGENT" tasks or until we have at least one "pending" task (which | 557 | * "URGENT" tasks or until we have at least one "pending" task (which |
@@ -589,16 +618,7 @@ run_ready (struct GNUNET_NETWORK_FDSet *rs, | |||
589 | "Running task: %p\n", | 618 | "Running task: %p\n", |
590 | pos); | 619 | pos); |
591 | pos->callback (pos->callback_cls); | 620 | pos->callback (pos->callback_cls); |
592 | #if EXECINFO | 621 | dump_backtrace (pos); |
593 | unsigned int i; | ||
594 | |||
595 | for (i = 0; i < pos->num_backtrace_strings; i++) | ||
596 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
597 | "Task %p trace %u: %s\n", | ||
598 | pos, | ||
599 | i, | ||
600 | pos->backtrace_strings[i]); | ||
601 | #endif | ||
602 | active_task = NULL; | 622 | active_task = NULL; |
603 | destroy_task (pos); | 623 | destroy_task (pos); |
604 | tasks_run++; | 624 | tasks_run++; |
@@ -684,10 +704,13 @@ check_lifeness () | |||
684 | for (t = pending_head; NULL != t; t = t->next) | 704 | for (t = pending_head; NULL != t; t = t->next) |
685 | if (t->lifeness == GNUNET_YES) | 705 | if (t->lifeness == GNUNET_YES) |
686 | return GNUNET_OK; | 706 | return GNUNET_OK; |
707 | for (t = shutdown_head; NULL != t; t = t->next) | ||
708 | if (t->lifeness == GNUNET_YES) | ||
709 | return GNUNET_OK; | ||
687 | for (t = pending_timeout_head; NULL != t; t = t->next) | 710 | for (t = pending_timeout_head; NULL != t; t = t->next) |
688 | if (t->lifeness == GNUNET_YES) | 711 | if (t->lifeness == GNUNET_YES) |
689 | return GNUNET_OK; | 712 | return GNUNET_OK; |
690 | if ((NULL != pending_head) || (NULL != pending_timeout_head)) | 713 | if (NULL != shutdown_head) |
691 | { | 714 | { |
692 | GNUNET_SCHEDULER_shutdown (); | 715 | GNUNET_SCHEDULER_shutdown (); |
693 | return GNUNET_OK; | 716 | return GNUNET_OK; |
@@ -749,15 +772,21 @@ GNUNET_SCHEDULER_run (GNUNET_SCHEDULER_TaskCallback task, | |||
749 | my_pid = getpid (); | 772 | my_pid = getpid (); |
750 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 773 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
751 | "Registering signal handlers\n"); | 774 | "Registering signal handlers\n"); |
752 | shc_int = GNUNET_SIGNAL_handler_install (SIGINT, &sighandler_shutdown); | 775 | shc_int = GNUNET_SIGNAL_handler_install (SIGINT, |
753 | shc_term = GNUNET_SIGNAL_handler_install (SIGTERM, &sighandler_shutdown); | 776 | &sighandler_shutdown); |
777 | shc_term = GNUNET_SIGNAL_handler_install (SIGTERM, | ||
778 | &sighandler_shutdown); | ||
754 | #if (SIGTERM != GNUNET_TERM_SIG) | 779 | #if (SIGTERM != GNUNET_TERM_SIG) |
755 | shc_gterm = GNUNET_SIGNAL_handler_install (GNUNET_TERM_SIG, &sighandler_shutdown); | 780 | shc_gterm = GNUNET_SIGNAL_handler_install (GNUNET_TERM_SIG, |
781 | &sighandler_shutdown); | ||
756 | #endif | 782 | #endif |
757 | #ifndef MINGW | 783 | #ifndef MINGW |
758 | shc_pipe = GNUNET_SIGNAL_handler_install (SIGPIPE, &sighandler_pipe); | 784 | shc_pipe = GNUNET_SIGNAL_handler_install (SIGPIPE, |
759 | shc_quit = GNUNET_SIGNAL_handler_install (SIGQUIT, &sighandler_shutdown); | 785 | &sighandler_pipe); |
760 | shc_hup = GNUNET_SIGNAL_handler_install (SIGHUP, &sighandler_shutdown); | 786 | shc_quit = GNUNET_SIGNAL_handler_install (SIGQUIT, |
787 | &sighandler_shutdown); | ||
788 | shc_hup = GNUNET_SIGNAL_handler_install (SIGHUP, | ||
789 | &sighandler_shutdown); | ||
761 | #endif | 790 | #endif |
762 | current_priority = GNUNET_SCHEDULER_PRIORITY_DEFAULT; | 791 | current_priority = GNUNET_SCHEDULER_PRIORITY_DEFAULT; |
763 | current_lifeness = GNUNET_YES; | 792 | current_lifeness = GNUNET_YES; |
@@ -826,14 +855,7 @@ GNUNET_SCHEDULER_run (GNUNET_SCHEDULER_TaskCallback task, | |||
826 | LOG (GNUNET_ERROR_TYPE_ERROR, | 855 | LOG (GNUNET_ERROR_TYPE_ERROR, |
827 | "Got invalid file descriptor %d!\n", | 856 | "Got invalid file descriptor %d!\n", |
828 | t->read_fd); | 857 | t->read_fd); |
829 | #if EXECINFO | 858 | dump_backtrace (t); |
830 | unsigned int i; | ||
831 | |||
832 | for (i = 0; i < t->num_backtrace_strings; i++) | ||
833 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
834 | "Trace: %s\n", | ||
835 | t->backtrace_strings[i]); | ||
836 | #endif | ||
837 | } | 859 | } |
838 | } | 860 | } |
839 | if (-1 != t->write_fd) | 861 | if (-1 != t->write_fd) |
@@ -844,14 +866,7 @@ GNUNET_SCHEDULER_run (GNUNET_SCHEDULER_TaskCallback task, | |||
844 | LOG (GNUNET_ERROR_TYPE_ERROR, | 866 | LOG (GNUNET_ERROR_TYPE_ERROR, |
845 | "Got invalid file descriptor %d!\n", | 867 | "Got invalid file descriptor %d!\n", |
846 | t->write_fd); | 868 | t->write_fd); |
847 | #if EXECINFO | 869 | dump_backtrace (t); |
848 | unsigned int i; | ||
849 | |||
850 | for (i = 0; i < t->num_backtrace_strings; i++) | ||
851 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
852 | "Trace: %s\n", | ||
853 | t->backtrace_strings[i]); | ||
854 | #endif | ||
855 | } | 870 | } |
856 | } | 871 | } |
857 | } | 872 | } |
@@ -959,7 +974,8 @@ GNUNET_SCHEDULER_cancel (struct GNUNET_SCHEDULER_Task *task) | |||
959 | enum GNUNET_SCHEDULER_Priority p; | 974 | enum GNUNET_SCHEDULER_Priority p; |
960 | void *ret; | 975 | void *ret; |
961 | 976 | ||
962 | GNUNET_assert (NULL != active_task); | 977 | GNUNET_assert ( (NULL != active_task) || |
978 | (GNUNET_NO == task->lifeness) ); | ||
963 | if (! task->in_ready_list) | 979 | if (! task->in_ready_list) |
964 | { | 980 | { |
965 | if ( (-1 == task->read_fd) && | 981 | if ( (-1 == task->read_fd) && |
@@ -967,9 +983,14 @@ GNUNET_SCHEDULER_cancel (struct GNUNET_SCHEDULER_Task *task) | |||
967 | (NULL == task->read_set) && | 983 | (NULL == task->read_set) && |
968 | (NULL == task->write_set) ) | 984 | (NULL == task->write_set) ) |
969 | { | 985 | { |
970 | GNUNET_CONTAINER_DLL_remove (pending_timeout_head, | 986 | if (GNUNET_YES == task->on_shutdown) |
971 | pending_timeout_tail, | 987 | GNUNET_CONTAINER_DLL_remove (shutdown_head, |
972 | task); | 988 | shutdown_tail, |
989 | task); | ||
990 | else | ||
991 | GNUNET_CONTAINER_DLL_remove (pending_timeout_head, | ||
992 | pending_timeout_tail, | ||
993 | task); | ||
973 | if (task == pending_timeout_last) | 994 | if (task == pending_timeout_last) |
974 | pending_timeout_last = NULL; | 995 | pending_timeout_last = NULL; |
975 | } | 996 | } |
@@ -998,6 +1019,27 @@ GNUNET_SCHEDULER_cancel (struct GNUNET_SCHEDULER_Task *task) | |||
998 | 1019 | ||
999 | 1020 | ||
1000 | /** | 1021 | /** |
1022 | * Initialize backtrace data for task @a t | ||
1023 | * | ||
1024 | * @param t task to initialize | ||
1025 | */ | ||
1026 | static void | ||
1027 | init_backtrace (struct GNUNET_SCHEDULER_Task *t) | ||
1028 | { | ||
1029 | #if EXECINFO | ||
1030 | void *backtrace_array[MAX_TRACE_DEPTH]; | ||
1031 | |||
1032 | t->num_backtrace_strings | ||
1033 | = backtrace (backtrace_array, MAX_TRACE_DEPTH); | ||
1034 | t->backtrace_strings = | ||
1035 | backtrace_symbols (backtrace_array, | ||
1036 | t->num_backtrace_strings); | ||
1037 | dump_backtrace (t); | ||
1038 | #endif | ||
1039 | } | ||
1040 | |||
1041 | |||
1042 | /** | ||
1001 | * Continue the current execution with the given function. This is | 1043 | * Continue the current execution with the given function. This is |
1002 | * similar to the other "add" functions except that there is no delay | 1044 | * similar to the other "add" functions except that there is no delay |
1003 | * and the reason code can be specified. | 1045 | * and the reason code can be specified. |
@@ -1015,19 +1057,10 @@ GNUNET_SCHEDULER_add_with_reason_and_priority (GNUNET_SCHEDULER_TaskCallback tas | |||
1015 | { | 1057 | { |
1016 | struct GNUNET_SCHEDULER_Task *t; | 1058 | struct GNUNET_SCHEDULER_Task *t; |
1017 | 1059 | ||
1018 | #if EXECINFO | ||
1019 | void *backtrace_array[50]; | ||
1020 | #endif | ||
1021 | |||
1022 | GNUNET_assert (NULL != task); | 1060 | GNUNET_assert (NULL != task); |
1023 | GNUNET_assert ((NULL != active_task) || | 1061 | GNUNET_assert ((NULL != active_task) || |
1024 | (GNUNET_SCHEDULER_REASON_STARTUP == reason)); | 1062 | (GNUNET_SCHEDULER_REASON_STARTUP == reason)); |
1025 | t = GNUNET_new (struct GNUNET_SCHEDULER_Task); | 1063 | t = GNUNET_new (struct GNUNET_SCHEDULER_Task); |
1026 | #if EXECINFO | ||
1027 | t->num_backtrace_strings = backtrace (backtrace_array, 50); | ||
1028 | t->backtrace_strings = | ||
1029 | backtrace_symbols (backtrace_array, t->num_backtrace_strings); | ||
1030 | #endif | ||
1031 | t->read_fd = -1; | 1064 | t->read_fd = -1; |
1032 | t->write_fd = -1; | 1065 | t->write_fd = -1; |
1033 | t->callback = task; | 1066 | t->callback = task; |
@@ -1041,6 +1074,7 @@ GNUNET_SCHEDULER_add_with_reason_and_priority (GNUNET_SCHEDULER_TaskCallback tas | |||
1041 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1074 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1042 | "Adding continuation task %p\n", | 1075 | "Adding continuation task %p\n", |
1043 | t); | 1076 | t); |
1077 | init_backtrace (t); | ||
1044 | queue_ready_task (t); | 1078 | queue_ready_task (t); |
1045 | } | 1079 | } |
1046 | 1080 | ||
@@ -1049,8 +1083,7 @@ GNUNET_SCHEDULER_add_with_reason_and_priority (GNUNET_SCHEDULER_TaskCallback tas | |||
1049 | * Schedule a new task to be run with a specified delay. The task | 1083 | * Schedule a new task to be run with a specified delay. The task |
1050 | * will be scheduled for execution once the delay has expired. | 1084 | * will be scheduled for execution once the delay has expired. |
1051 | * | 1085 | * |
1052 | * @param delay when should this operation time out? Use | 1086 | * @param delay when should this operation time out? |
1053 | * #GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown" | ||
1054 | * @param priority priority to use for the task | 1087 | * @param priority priority to use for the task |
1055 | * @param task main function of the task | 1088 | * @param task main function of the task |
1056 | * @param task_cls closure of @a task | 1089 | * @param task_cls closure of @a task |
@@ -1067,20 +1100,11 @@ GNUNET_SCHEDULER_add_delayed_with_priority (struct GNUNET_TIME_Relative delay, | |||
1067 | struct GNUNET_SCHEDULER_Task *pos; | 1100 | struct GNUNET_SCHEDULER_Task *pos; |
1068 | struct GNUNET_SCHEDULER_Task *prev; | 1101 | struct GNUNET_SCHEDULER_Task *prev; |
1069 | 1102 | ||
1070 | #if EXECINFO | ||
1071 | void *backtrace_array[MAX_TRACE_DEPTH]; | ||
1072 | #endif | ||
1073 | |||
1074 | GNUNET_assert (NULL != active_task); | 1103 | GNUNET_assert (NULL != active_task); |
1075 | GNUNET_assert (NULL != task); | 1104 | GNUNET_assert (NULL != task); |
1076 | t = GNUNET_new (struct GNUNET_SCHEDULER_Task); | 1105 | t = GNUNET_new (struct GNUNET_SCHEDULER_Task); |
1077 | t->callback = task; | 1106 | t->callback = task; |
1078 | t->callback_cls = task_cls; | 1107 | t->callback_cls = task_cls; |
1079 | #if EXECINFO | ||
1080 | t->num_backtrace_strings = backtrace (backtrace_array, MAX_TRACE_DEPTH); | ||
1081 | t->backtrace_strings = | ||
1082 | backtrace_symbols (backtrace_array, t->num_backtrace_strings); | ||
1083 | #endif | ||
1084 | t->read_fd = -1; | 1108 | t->read_fd = -1; |
1085 | t->write_fd = -1; | 1109 | t->write_fd = -1; |
1086 | #if PROFILE_DELAYS | 1110 | #if PROFILE_DELAYS |
@@ -1127,16 +1151,7 @@ GNUNET_SCHEDULER_add_delayed_with_priority (struct GNUNET_TIME_Relative delay, | |||
1127 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1151 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1128 | "Adding task: %p\n", | 1152 | "Adding task: %p\n", |
1129 | t); | 1153 | t); |
1130 | #if EXECINFO | 1154 | init_backtrace (t); |
1131 | unsigned int i; | ||
1132 | |||
1133 | for (i = 0; i < t->num_backtrace_strings; i++) | ||
1134 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1135 | "Task %p trace %d: %s\n", | ||
1136 | t, | ||
1137 | i, | ||
1138 | t->backtrace_strings[i]); | ||
1139 | #endif | ||
1140 | return t; | 1155 | return t; |
1141 | } | 1156 | } |
1142 | 1157 | ||
@@ -1167,16 +1182,16 @@ GNUNET_SCHEDULER_add_with_priority (enum GNUNET_SCHEDULER_Priority prio, | |||
1167 | * will be scheduled for execution once the delay has expired. It | 1182 | * will be scheduled for execution once the delay has expired. It |
1168 | * will be run with the DEFAULT priority. | 1183 | * will be run with the DEFAULT priority. |
1169 | * | 1184 | * |
1170 | * @param delay when should this operation time out? Use | 1185 | * @param delay when should this operation time out? |
1171 | * GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown" | ||
1172 | * @param task main function of the task | 1186 | * @param task main function of the task |
1173 | * @param task_cls closure of task | 1187 | * @param task_cls closure of @a task |
1174 | * @return unique task identifier for the job | 1188 | * @return unique task identifier for the job |
1175 | * only valid until "task" is started! | 1189 | * only valid until @a task is started! |
1176 | */ | 1190 | */ |
1177 | struct GNUNET_SCHEDULER_Task * | 1191 | struct GNUNET_SCHEDULER_Task * |
1178 | GNUNET_SCHEDULER_add_delayed (struct GNUNET_TIME_Relative delay, | 1192 | GNUNET_SCHEDULER_add_delayed (struct GNUNET_TIME_Relative delay, |
1179 | GNUNET_SCHEDULER_TaskCallback task, void *task_cls) | 1193 | GNUNET_SCHEDULER_TaskCallback task, |
1194 | void *task_cls) | ||
1180 | { | 1195 | { |
1181 | return GNUNET_SCHEDULER_add_delayed_with_priority (delay, | 1196 | return GNUNET_SCHEDULER_add_delayed_with_priority (delay, |
1182 | GNUNET_SCHEDULER_PRIORITY_DEFAULT, | 1197 | GNUNET_SCHEDULER_PRIORITY_DEFAULT, |
@@ -1197,12 +1212,56 @@ GNUNET_SCHEDULER_add_delayed (struct GNUNET_TIME_Relative delay, | |||
1197 | * @param task main function of the task | 1212 | * @param task main function of the task |
1198 | * @param task_cls closure of @a task | 1213 | * @param task_cls closure of @a task |
1199 | * @return unique task identifier for the job | 1214 | * @return unique task identifier for the job |
1200 | * only valid until "task" is started! | 1215 | * only valid until @a task is started! |
1201 | */ | 1216 | */ |
1202 | struct GNUNET_SCHEDULER_Task * | 1217 | struct GNUNET_SCHEDULER_Task * |
1203 | GNUNET_SCHEDULER_add_now (GNUNET_SCHEDULER_TaskCallback task, void *task_cls) | 1218 | GNUNET_SCHEDULER_add_now (GNUNET_SCHEDULER_TaskCallback task, |
1219 | void *task_cls) | ||
1204 | { | 1220 | { |
1205 | return GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_ZERO, task, task_cls); | 1221 | return GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_ZERO, |
1222 | task, | ||
1223 | task_cls); | ||
1224 | } | ||
1225 | |||
1226 | |||
1227 | /** | ||
1228 | * Schedule a new task to be run on shutdown, that is when a CTRL-C | ||
1229 | * signal is received, or when #GNUNET_SCHEDULER_shutdown() is being | ||
1230 | * invoked. | ||
1231 | * | ||
1232 | * @param task main function of the task | ||
1233 | * @param task_cls closure of @a task | ||
1234 | * @return unique task identifier for the job | ||
1235 | * only valid until @a task is started! | ||
1236 | */ | ||
1237 | struct GNUNET_SCHEDULER_Task * | ||
1238 | GNUNET_SCHEDULER_add_shutdown (GNUNET_SCHEDULER_TaskCallback task, | ||
1239 | void *task_cls) | ||
1240 | { | ||
1241 | struct GNUNET_SCHEDULER_Task *t; | ||
1242 | |||
1243 | GNUNET_assert (NULL != active_task); | ||
1244 | GNUNET_assert (NULL != task); | ||
1245 | t = GNUNET_new (struct GNUNET_SCHEDULER_Task); | ||
1246 | t->callback = task; | ||
1247 | t->callback_cls = task_cls; | ||
1248 | t->read_fd = -1; | ||
1249 | t->write_fd = -1; | ||
1250 | #if PROFILE_DELAYS | ||
1251 | t->start_time = GNUNET_TIME_absolute_get (); | ||
1252 | #endif | ||
1253 | t->timeout = GNUNET_TIME_UNIT_FOREVER_ABS; | ||
1254 | t->priority = GNUNET_SCHEDULER_PRIORITY_SHUTDOWN; | ||
1255 | t->on_shutdown = GNUNET_YES; | ||
1256 | t->lifeness = GNUNET_YES; | ||
1257 | GNUNET_CONTAINER_DLL_insert (shutdown_head, | ||
1258 | shutdown_tail, | ||
1259 | t); | ||
1260 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1261 | "Adding task: %p\n", | ||
1262 | t); | ||
1263 | init_backtrace (t); | ||
1264 | return t; | ||
1206 | } | 1265 | } |
1207 | 1266 | ||
1208 | 1267 | ||
@@ -1246,12 +1305,10 @@ GNUNET_SCHEDULER_add_now_with_lifeness (int lifeness, | |||
1246 | * (prerequisite-run) | 1305 | * (prerequisite-run) |
1247 | * && (delay-ready | 1306 | * && (delay-ready |
1248 | * || any-rs-ready | 1307 | * || any-rs-ready |
1249 | * || any-ws-ready | 1308 | * || any-ws-ready) |
1250 | * || shutdown-active ) | ||
1251 | * </code> | 1309 | * </code> |
1252 | * | 1310 | * |
1253 | * @param delay how long should we wait? Use #GNUNET_TIME_UNIT_FOREVER_REL for "forever", | 1311 | * @param delay how long should we wait? |
1254 | * which means that the task will only be run after we receive SIGTERM | ||
1255 | * @param priority priority to use | 1312 | * @param priority priority to use |
1256 | * @param rfd file descriptor we want to read (can be -1) | 1313 | * @param rfd file descriptor we want to read (can be -1) |
1257 | * @param wfd file descriptors we want to write (can be -1) | 1314 | * @param wfd file descriptors we want to write (can be -1) |
@@ -1271,20 +1328,11 @@ add_without_sets (struct GNUNET_TIME_Relative delay, | |||
1271 | { | 1328 | { |
1272 | struct GNUNET_SCHEDULER_Task *t; | 1329 | struct GNUNET_SCHEDULER_Task *t; |
1273 | 1330 | ||
1274 | #if EXECINFO | ||
1275 | void *backtrace_array[MAX_TRACE_DEPTH]; | ||
1276 | #endif | ||
1277 | |||
1278 | GNUNET_assert (NULL != active_task); | 1331 | GNUNET_assert (NULL != active_task); |
1279 | GNUNET_assert (NULL != task); | 1332 | GNUNET_assert (NULL != task); |
1280 | t = GNUNET_new (struct GNUNET_SCHEDULER_Task); | 1333 | t = GNUNET_new (struct GNUNET_SCHEDULER_Task); |
1281 | t->callback = task; | 1334 | t->callback = task; |
1282 | t->callback_cls = task_cls; | 1335 | t->callback_cls = task_cls; |
1283 | #if EXECINFO | ||
1284 | t->num_backtrace_strings = backtrace (backtrace_array, MAX_TRACE_DEPTH); | ||
1285 | t->backtrace_strings = | ||
1286 | backtrace_symbols (backtrace_array, t->num_backtrace_strings); | ||
1287 | #endif | ||
1288 | #if DEBUG_FDS | 1336 | #if DEBUG_FDS |
1289 | if (-1 != rfd) | 1337 | if (-1 != rfd) |
1290 | { | 1338 | { |
@@ -1295,14 +1343,7 @@ add_without_sets (struct GNUNET_TIME_Relative delay, | |||
1295 | LOG (GNUNET_ERROR_TYPE_ERROR, | 1343 | LOG (GNUNET_ERROR_TYPE_ERROR, |
1296 | "Got invalid file descriptor %d!\n", | 1344 | "Got invalid file descriptor %d!\n", |
1297 | rfd); | 1345 | rfd); |
1298 | #if EXECINFO | 1346 | init_backtrace (t); |
1299 | unsigned int i; | ||
1300 | |||
1301 | for (i = 0; i < t->num_backtrace_strings; i++) | ||
1302 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
1303 | "Trace: %s\n", | ||
1304 | t->backtrace_strings[i]); | ||
1305 | #endif | ||
1306 | GNUNET_assert (0); | 1347 | GNUNET_assert (0); |
1307 | } | 1348 | } |
1308 | } | 1349 | } |
@@ -1315,14 +1356,7 @@ add_without_sets (struct GNUNET_TIME_Relative delay, | |||
1315 | LOG (GNUNET_ERROR_TYPE_ERROR, | 1356 | LOG (GNUNET_ERROR_TYPE_ERROR, |
1316 | "Got invalid file descriptor %d!\n", | 1357 | "Got invalid file descriptor %d!\n", |
1317 | wfd); | 1358 | wfd); |
1318 | #if EXECINFO | 1359 | init_backtrace (t); |
1319 | unsigned int i; | ||
1320 | |||
1321 | for (i = 0; i < t->num_backtrace_strings; i++) | ||
1322 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1323 | "Trace: %s\n", | ||
1324 | t->backtrace_strings[i]); | ||
1325 | #endif | ||
1326 | GNUNET_assert (0); | 1360 | GNUNET_assert (0); |
1327 | } | 1361 | } |
1328 | } | 1362 | } |
@@ -1344,16 +1378,7 @@ add_without_sets (struct GNUNET_TIME_Relative delay, | |||
1344 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1378 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1345 | "Adding task %p\n", | 1379 | "Adding task %p\n", |
1346 | t); | 1380 | t); |
1347 | #if EXECINFO | 1381 | init_backtrace (t); |
1348 | unsigned int i; | ||
1349 | |||
1350 | for (i = 0; i < t->num_backtrace_strings; i++) | ||
1351 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1352 | "Task %p trace %d: %s\n", | ||
1353 | t, | ||
1354 | i, | ||
1355 | t->backtrace_strings[i]); | ||
1356 | #endif | ||
1357 | return t; | 1382 | return t; |
1358 | } | 1383 | } |
1359 | #endif | 1384 | #endif |
@@ -1366,8 +1391,7 @@ add_without_sets (struct GNUNET_TIME_Relative delay, | |||
1366 | * scheduled for execution once either the delay has expired or the | 1391 | * scheduled for execution once either the delay has expired or the |
1367 | * socket operation is ready. It will be run with the DEFAULT priority. | 1392 | * socket operation is ready. It will be run with the DEFAULT priority. |
1368 | * | 1393 | * |
1369 | * @param delay when should this operation time out? Use | 1394 | * @param delay when should this operation time out? |
1370 | * #GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown" | ||
1371 | * @param rfd read file-descriptor | 1395 | * @param rfd read file-descriptor |
1372 | * @param task main function of the task | 1396 | * @param task main function of the task |
1373 | * @param task_cls closure of @a task | 1397 | * @param task_cls closure of @a task |
@@ -1394,8 +1418,7 @@ GNUNET_SCHEDULER_add_read_net (struct GNUNET_TIME_Relative delay, | |||
1394 | * either the delay has expired or the socket operation is ready. It | 1418 | * either the delay has expired or the socket operation is ready. It |
1395 | * will be run with the DEFAULT priority. | 1419 | * will be run with the DEFAULT priority. |
1396 | * | 1420 | * |
1397 | * @param delay when should this operation time out? Use | 1421 | * @param delay when should this operation time out? |
1398 | * #GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown" | ||
1399 | * @param priority priority to use for the task | 1422 | * @param priority priority to use for the task |
1400 | * @param rfd read file-descriptor | 1423 | * @param rfd read file-descriptor |
1401 | * @param task main function of the task | 1424 | * @param task main function of the task |
@@ -1426,8 +1449,7 @@ GNUNET_SCHEDULER_add_read_net_with_priority (struct GNUNET_TIME_Relative delay, | |||
1426 | * socket operation is ready. It will be run with the priority of | 1449 | * socket operation is ready. It will be run with the priority of |
1427 | * the calling task. | 1450 | * the calling task. |
1428 | * | 1451 | * |
1429 | * @param delay when should this operation time out? Use | 1452 | * @param delay when should this operation time out? |
1430 | * #GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown" | ||
1431 | * @param wfd write file-descriptor | 1453 | * @param wfd write file-descriptor |
1432 | * @param task main function of the task | 1454 | * @param task main function of the task |
1433 | * @param task_cls closure of @a task | 1455 | * @param task_cls closure of @a task |
@@ -1454,8 +1476,7 @@ GNUNET_SCHEDULER_add_write_net (struct GNUNET_TIME_Relative delay, | |||
1454 | * scheduled for execution once either the delay has expired or the | 1476 | * scheduled for execution once either the delay has expired or the |
1455 | * socket operation is ready. | 1477 | * socket operation is ready. |
1456 | * | 1478 | * |
1457 | * @param delay when should this operation time out? Use | 1479 | * @param delay when should this operation time out? |
1458 | * #GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown" | ||
1459 | * @param priority priority of the task | 1480 | * @param priority priority of the task |
1460 | * @param fd file-descriptor | 1481 | * @param fd file-descriptor |
1461 | * @param on_read whether to poll the file-descriptor for readability | 1482 | * @param on_read whether to poll the file-descriptor for readability |
@@ -1505,8 +1526,7 @@ GNUNET_SCHEDULER_add_net_with_priority (struct GNUNET_TIME_Relative delay, | |||
1505 | * scheduled for execution once either the delay has expired or the | 1526 | * scheduled for execution once either the delay has expired or the |
1506 | * socket operation is ready. It will be run with the DEFAULT priority. | 1527 | * socket operation is ready. It will be run with the DEFAULT priority. |
1507 | * | 1528 | * |
1508 | * @param delay when should this operation time out? Use | 1529 | * @param delay when should this operation time out? |
1509 | * #GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown" | ||
1510 | * @param rfd read file-descriptor | 1530 | * @param rfd read file-descriptor |
1511 | * @param task main function of the task | 1531 | * @param task main function of the task |
1512 | * @param task_cls closure of @a task | 1532 | * @param task_cls closure of @a task |
@@ -1532,8 +1552,7 @@ GNUNET_SCHEDULER_add_read_file (struct GNUNET_TIME_Relative delay, | |||
1532 | * scheduled for execution once either the delay has expired or the | 1552 | * scheduled for execution once either the delay has expired or the |
1533 | * socket operation is ready. It will be run with the DEFAULT priority. | 1553 | * socket operation is ready. It will be run with the DEFAULT priority. |
1534 | * | 1554 | * |
1535 | * @param delay when should this operation time out? Use | 1555 | * @param delay when should this operation time out? |
1536 | * #GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown" | ||
1537 | * @param wfd write file-descriptor | 1556 | * @param wfd write file-descriptor |
1538 | * @param task main function of the task | 1557 | * @param task main function of the task |
1539 | * @param task_cls closure of @a task | 1558 | * @param task_cls closure of @a task |
@@ -1559,8 +1578,7 @@ GNUNET_SCHEDULER_add_write_file (struct GNUNET_TIME_Relative delay, | |||
1559 | * scheduled for execution once either the delay has expired or the | 1578 | * scheduled for execution once either the delay has expired or the |
1560 | * socket operation is ready. | 1579 | * socket operation is ready. |
1561 | * | 1580 | * |
1562 | * @param delay when should this operation time out? Use | 1581 | * @param delay when should this operation time out? |
1563 | * #GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown" | ||
1564 | * @param priority priority of the task | 1582 | * @param priority priority of the task |
1565 | * @param fd file-descriptor | 1583 | * @param fd file-descriptor |
1566 | * @param on_read whether to poll the file-descriptor for readability | 1584 | * @param on_read whether to poll the file-descriptor for readability |
@@ -1618,13 +1636,11 @@ GNUNET_SCHEDULER_add_file_with_priority (struct GNUNET_TIME_Relative delay, | |||
1618 | * (prerequisite-run) | 1636 | * (prerequisite-run) |
1619 | * && (delay-ready | 1637 | * && (delay-ready |
1620 | * || any-rs-ready | 1638 | * || any-rs-ready |
1621 | * || any-ws-ready | 1639 | * || any-ws-ready) ) |
1622 | * || (shutdown-active && run-on-shutdown) ) | ||
1623 | * </code> | 1640 | * </code> |
1624 | * | 1641 | * |
1625 | * @param prio how important is this task? | 1642 | * @param prio how important is this task? |
1626 | * @param delay how long should we wait? Use #GNUNET_TIME_UNIT_FOREVER_REL for "forever", | 1643 | * @param delay how long should we wait? |
1627 | * which means that the task will only be run after we receive SIGTERM | ||
1628 | * @param rs set of file descriptors we want to read (can be NULL) | 1644 | * @param rs set of file descriptors we want to read (can be NULL) |
1629 | * @param ws set of file descriptors we want to write (can be NULL) | 1645 | * @param ws set of file descriptors we want to write (can be NULL) |
1630 | * @param task main function of the task | 1646 | * @param task main function of the task |
@@ -1641,9 +1657,6 @@ GNUNET_SCHEDULER_add_select (enum GNUNET_SCHEDULER_Priority prio, | |||
1641 | void *task_cls) | 1657 | void *task_cls) |
1642 | { | 1658 | { |
1643 | struct GNUNET_SCHEDULER_Task *t; | 1659 | struct GNUNET_SCHEDULER_Task *t; |
1644 | #if EXECINFO | ||
1645 | void *backtrace_array[MAX_TRACE_DEPTH]; | ||
1646 | #endif | ||
1647 | 1660 | ||
1648 | if ( (NULL == rs) && | 1661 | if ( (NULL == rs) && |
1649 | (NULL == ws) ) | 1662 | (NULL == ws) ) |
@@ -1656,11 +1669,6 @@ GNUNET_SCHEDULER_add_select (enum GNUNET_SCHEDULER_Priority prio, | |||
1656 | t = GNUNET_new (struct GNUNET_SCHEDULER_Task); | 1669 | t = GNUNET_new (struct GNUNET_SCHEDULER_Task); |
1657 | t->callback = task; | 1670 | t->callback = task; |
1658 | t->callback_cls = task_cls; | 1671 | t->callback_cls = task_cls; |
1659 | #if EXECINFO | ||
1660 | t->num_backtrace_strings = backtrace (backtrace_array, MAX_TRACE_DEPTH); | ||
1661 | t->backtrace_strings = | ||
1662 | backtrace_symbols (backtrace_array, t->num_backtrace_strings); | ||
1663 | #endif | ||
1664 | t->read_fd = -1; | 1672 | t->read_fd = -1; |
1665 | t->write_fd = -1; | 1673 | t->write_fd = -1; |
1666 | if (NULL != rs) | 1674 | if (NULL != rs) |
@@ -1689,16 +1697,7 @@ GNUNET_SCHEDULER_add_select (enum GNUNET_SCHEDULER_Priority prio, | |||
1689 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1697 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1690 | "Adding task %p\n", | 1698 | "Adding task %p\n", |
1691 | t); | 1699 | t); |
1692 | #if EXECINFO | 1700 | init_backtrace (t); |
1693 | int i; | ||
1694 | |||
1695 | for (i = 0; i < t->num_backtrace_strings; i++) | ||
1696 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1697 | "Task p trace %d: %s\n", | ||
1698 | t, | ||
1699 | i, | ||
1700 | t->backtrace_strings[i]); | ||
1701 | #endif | ||
1702 | return t; | 1701 | return t; |
1703 | } | 1702 | } |
1704 | 1703 | ||
diff --git a/src/util/server.c b/src/util/server.c index 8dedd28fd..00e37c9d9 100644 --- a/src/util/server.c +++ b/src/util/server.c | |||
@@ -400,12 +400,6 @@ process_listen_socket (void *cls) | |||
400 | 400 | ||
401 | server->listen_task = NULL; | 401 | server->listen_task = NULL; |
402 | tc = GNUNET_SCHEDULER_get_task_context (); | 402 | tc = GNUNET_SCHEDULER_get_task_context (); |
403 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | ||
404 | { | ||
405 | /* ignore shutdown, someone else will take care of it! */ | ||
406 | GNUNET_SERVER_resume (server); | ||
407 | return; | ||
408 | } | ||
409 | for (i = 0; NULL != server->listen_sockets[i]; i++) | 403 | for (i = 0; NULL != server->listen_sockets[i]; i++) |
410 | { | 404 | { |
411 | if (GNUNET_NETWORK_fdset_isset (tc->read_ready, | 405 | if (GNUNET_NETWORK_fdset_isset (tc->read_ready, |
@@ -437,7 +431,8 @@ process_listen_socket (void *cls) | |||
437 | * @return NULL on error, otherwise the listen socket | 431 | * @return NULL on error, otherwise the listen socket |
438 | */ | 432 | */ |
439 | static struct GNUNET_NETWORK_Handle * | 433 | static struct GNUNET_NETWORK_Handle * |
440 | open_listen_socket (const struct sockaddr *server_addr, socklen_t socklen) | 434 | open_listen_socket (const struct sockaddr *server_addr, |
435 | socklen_t socklen) | ||
441 | { | 436 | { |
442 | struct GNUNET_NETWORK_Handle *sock; | 437 | struct GNUNET_NETWORK_Handle *sock; |
443 | uint16_t port; | 438 | uint16_t port; |
@@ -683,7 +678,7 @@ test_monitor_clients (struct GNUNET_SERVER_Handle *server) | |||
683 | if (GNUNET_NO == client->is_monitor) | 678 | if (GNUNET_NO == client->is_monitor) |
684 | return; /* not done yet */ | 679 | return; /* not done yet */ |
685 | server->in_soft_shutdown = GNUNET_SYSERR; | 680 | server->in_soft_shutdown = GNUNET_SYSERR; |
686 | GNUNET_SCHEDULER_add_now (&do_destroy, server); | 681 | (void) GNUNET_SCHEDULER_add_now (&do_destroy, server); |
687 | } | 682 | } |
688 | 683 | ||
689 | 684 | ||
@@ -720,8 +715,8 @@ GNUNET_SERVER_resume (struct GNUNET_SERVER_Handle *server) | |||
720 | return; /* nothing to do, no listen sockets! */ | 715 | return; /* nothing to do, no listen sockets! */ |
721 | if (NULL == server->listen_sockets[1]) | 716 | if (NULL == server->listen_sockets[1]) |
722 | { | 717 | { |
723 | /* simplified method: no fd set needed; this is then much simpler and | 718 | /* simplified method: no fd set needed; this is then much simpler |
724 | much more efficient */ | 719 | and much more efficient */ |
725 | server->listen_task = | 720 | server->listen_task = |
726 | GNUNET_SCHEDULER_add_read_net_with_priority (GNUNET_TIME_UNIT_FOREVER_REL, | 721 | GNUNET_SCHEDULER_add_read_net_with_priority (GNUNET_TIME_UNIT_FOREVER_REL, |
727 | GNUNET_SCHEDULER_PRIORITY_HIGH, | 722 | GNUNET_SCHEDULER_PRIORITY_HIGH, |
@@ -890,18 +885,16 @@ static void | |||
890 | warn_no_receive_done (void *cls) | 885 | warn_no_receive_done (void *cls) |
891 | { | 886 | { |
892 | struct GNUNET_SERVER_Client *client = cls; | 887 | struct GNUNET_SERVER_Client *client = cls; |
893 | const struct GNUNET_SCHEDULER_TaskContext *tc; | ||
894 | 888 | ||
895 | GNUNET_break (0 != client->warn_type); /* type should never be 0 here, as we don't use 0 */ | 889 | GNUNET_break (0 != client->warn_type); /* type should never be 0 here, as we don't use 0 */ |
896 | client->warn_task = | 890 | client->warn_task = |
897 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, | 891 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, |
898 | &warn_no_receive_done, client); | 892 | &warn_no_receive_done, client); |
899 | tc = GNUNET_SCHEDULER_get_task_context (); | 893 | LOG (GNUNET_ERROR_TYPE_WARNING, |
900 | if (0 == (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason)) | 894 | _("Processing code for message of type %u did not call `GNUNET_SERVER_receive_done' after %s\n"), |
901 | LOG (GNUNET_ERROR_TYPE_WARNING, | 895 | (unsigned int) client->warn_type, |
902 | _("Processing code for message of type %u did not call `GNUNET_SERVER_receive_done' after %s\n"), | 896 | GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (client->warn_start), |
903 | (unsigned int) client->warn_type, | 897 | GNUNET_YES)); |
904 | GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (client->warn_start), GNUNET_YES)); | ||
905 | } | 898 | } |
906 | 899 | ||
907 | 900 | ||
@@ -987,7 +980,8 @@ GNUNET_SERVER_inject (struct GNUNET_SERVER_Handle *server, | |||
987 | sender->warn_start = GNUNET_TIME_absolute_get (); | 980 | sender->warn_start = GNUNET_TIME_absolute_get (); |
988 | sender->warn_task = | 981 | sender->warn_task = |
989 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, | 982 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, |
990 | &warn_no_receive_done, sender); | 983 | &warn_no_receive_done, |
984 | sender); | ||
991 | sender->warn_type = type; | 985 | sender->warn_type = type; |
992 | } | 986 | } |
993 | sender->suspended++; | 987 | sender->suspended++; |
diff --git a/src/util/service.c b/src/util/service.c index 93a51f220..bdef17361 100644 --- a/src/util/service.c +++ b/src/util/service.c | |||
@@ -187,7 +187,7 @@ struct GNUNET_SERVICE_Context | |||
187 | /** | 187 | /** |
188 | * Task ID of the shutdown task. | 188 | * Task ID of the shutdown task. |
189 | */ | 189 | */ |
190 | struct GNUNET_SCHEDULER_Task * shutdown_task; | 190 | struct GNUNET_SCHEDULER_Task *shutdown_task; |
191 | 191 | ||
192 | /** | 192 | /** |
193 | * Idle timeout for server. | 193 | * Idle timeout for server. |
@@ -1151,11 +1151,7 @@ service_task (void *cls) | |||
1151 | { | 1151 | { |
1152 | struct GNUNET_SERVICE_Context *sctx = cls; | 1152 | struct GNUNET_SERVICE_Context *sctx = cls; |
1153 | unsigned int i; | 1153 | unsigned int i; |
1154 | const struct GNUNET_SCHEDULER_TaskContext *tc; | ||
1155 | 1154 | ||
1156 | tc = GNUNET_SCHEDULER_get_task_context (); | ||
1157 | if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason)) | ||
1158 | return; | ||
1159 | (void) GNUNET_SPEEDUP_start_ (sctx->cfg); | 1155 | (void) GNUNET_SPEEDUP_start_ (sctx->cfg); |
1160 | GNUNET_RESOLVER_connect (sctx->cfg); | 1156 | GNUNET_RESOLVER_connect (sctx->cfg); |
1161 | if (NULL != sctx->lsocks) | 1157 | if (NULL != sctx->lsocks) |
@@ -1191,9 +1187,8 @@ service_task (void *cls) | |||
1191 | { | 1187 | { |
1192 | /* install a task that will kill the server | 1188 | /* install a task that will kill the server |
1193 | * process if the scheduler ever gets a shutdown signal */ | 1189 | * process if the scheduler ever gets a shutdown signal */ |
1194 | sctx->shutdown_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, | 1190 | sctx->shutdown_task = GNUNET_SCHEDULER_add_shutdown (&shutdown_task, |
1195 | &shutdown_task, | 1191 | sctx); |
1196 | sctx); | ||
1197 | } | 1192 | } |
1198 | sctx->my_handlers = GNUNET_malloc (sizeof (defhandlers)); | 1193 | sctx->my_handlers = GNUNET_malloc (sizeof (defhandlers)); |
1199 | memcpy (sctx->my_handlers, defhandlers, sizeof (defhandlers)); | 1194 | memcpy (sctx->my_handlers, defhandlers, sizeof (defhandlers)); |
diff --git a/src/util/socks.c b/src/util/socks.c index cc59858dd..bda8765ad 100644 --- a/src/util/socks.c +++ b/src/util/socks.c | |||
@@ -328,7 +328,6 @@ register_reciever (struct GNUNET_SOCKS_Handshake *ih, int want) | |||
328 | * @param buf where the callee should write the message | 328 | * @param buf where the callee should write the message |
329 | * @return number of bytes written to @a buf | 329 | * @return number of bytes written to @a buf |
330 | */ | 330 | */ |
331 | |||
332 | size_t | 331 | size_t |
333 | transmit_ready (void *cls, | 332 | transmit_ready (void *cls, |
334 | size_t size, | 333 | size_t size, |
@@ -353,29 +352,19 @@ transmit_ready (void *cls, | |||
353 | * successful operations, including DNS resolution, do not use this. */ | 352 | * successful operations, including DNS resolution, do not use this. */ |
354 | if (NULL == buf) | 353 | if (NULL == buf) |
355 | { | 354 | { |
356 | const struct GNUNET_SCHEDULER_TaskContext *tc; | 355 | if (0 == ih->step) |
357 | 356 | { | |
358 | tc = GNUNET_SCHEDULER_get_task_context (); | 357 | LOG (GNUNET_ERROR_TYPE_WARNING, |
359 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | 358 | "Timeout contacting SOCKS server, retrying indefinitely, but probably hopeless.\n"); |
360 | return 0; | 359 | register_sender (ih); |
361 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT)) { | 360 | } |
362 | if (0==ih->step) | 361 | else |
363 | { | 362 | { |
364 | LOG (GNUNET_ERROR_TYPE_WARNING, | 363 | LOG (GNUNET_ERROR_TYPE_ERROR, |
365 | "Timeout contacting SOCKS server, retrying indefinitely, but probably hopeless.\n"); | 364 | "Timeout during mid SOCKS handshake (step %u), probably not a SOCKS server.\n", |
366 | register_sender (ih); | 365 | ih->step); |
367 | } | 366 | GNUNET_break (0); |
368 | else | ||
369 | { | ||
370 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
371 | "Timeout during mid SOCKS handshake (step %u), probably not a SOCKS server.\n", | ||
372 | ih->step); | ||
373 | GNUNET_break (0); | ||
374 | } | ||
375 | return 0; | ||
376 | } | 367 | } |
377 | /* if (reason == 48) register_sender (ih); */ | ||
378 | /* GNUNET_break(0); */ | ||
379 | return 0; | 368 | return 0; |
380 | } | 369 | } |
381 | 370 | ||
diff --git a/src/util/speedup.c b/src/util/speedup.c index 6dce6a490..97df65c8e 100644 --- a/src/util/speedup.c +++ b/src/util/speedup.c | |||
@@ -41,18 +41,16 @@ static void | |||
41 | do_speedup (void *cls) | 41 | do_speedup (void *cls) |
42 | { | 42 | { |
43 | static long long current_offset; | 43 | static long long current_offset; |
44 | const struct GNUNET_SCHEDULER_TaskContext *tc; | ||
45 | 44 | ||
46 | speedup_task = NULL; | 45 | speedup_task = NULL; |
47 | tc = GNUNET_SCHEDULER_get_task_context (); | ||
48 | if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason)) | ||
49 | return; | ||
50 | current_offset += delta.rel_value_us; | 46 | current_offset += delta.rel_value_us; |
51 | GNUNET_TIME_set_offset (current_offset); | 47 | GNUNET_TIME_set_offset (current_offset); |
52 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 48 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
53 | "Speeding up execution time by %s\n", | 49 | "Speeding up execution time by %s\n", |
54 | GNUNET_STRINGS_relative_time_to_string (delta, GNUNET_NO)); | 50 | GNUNET_STRINGS_relative_time_to_string (delta, GNUNET_NO)); |
55 | speedup_task = GNUNET_SCHEDULER_add_delayed (interval, &do_speedup, NULL); | 51 | speedup_task = GNUNET_SCHEDULER_add_delayed (interval, |
52 | &do_speedup, | ||
53 | NULL); | ||
56 | } | 54 | } |
57 | 55 | ||
58 | 56 | ||
@@ -65,16 +63,22 @@ do_speedup (void *cls) | |||
65 | int | 63 | int |
66 | GNUNET_SPEEDUP_start_ (const struct GNUNET_CONFIGURATION_Handle *cfg) | 64 | GNUNET_SPEEDUP_start_ (const struct GNUNET_CONFIGURATION_Handle *cfg) |
67 | { | 65 | { |
66 | GNUNET_assert (NULL == speedup_task); | ||
68 | if (GNUNET_OK != | 67 | if (GNUNET_OK != |
69 | GNUNET_CONFIGURATION_get_value_time (cfg, "testing", | 68 | GNUNET_CONFIGURATION_get_value_time (cfg, |
70 | "SPEEDUP_INTERVAL", &interval)) | 69 | "testing", |
70 | "SPEEDUP_INTERVAL", | ||
71 | &interval)) | ||
71 | return GNUNET_SYSERR; | 72 | return GNUNET_SYSERR; |
72 | if (GNUNET_OK != | 73 | if (GNUNET_OK != |
73 | GNUNET_CONFIGURATION_get_value_time (cfg, "testing", | 74 | GNUNET_CONFIGURATION_get_value_time (cfg, |
74 | "SPEEDUP_DELTA", &delta)) | 75 | "testing", |
76 | "SPEEDUP_DELTA", | ||
77 | &delta)) | ||
75 | return GNUNET_SYSERR; | 78 | return GNUNET_SYSERR; |
76 | 79 | ||
77 | if ((0 == interval.rel_value_us) || (0 == delta.rel_value_us)) | 80 | if ( (0 == interval.rel_value_us) || |
81 | (0 == delta.rel_value_us) ) | ||
78 | { | 82 | { |
79 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 83 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
80 | "Speed up disabled\n"); | 84 | "Speed up disabled\n"); |
@@ -87,7 +91,8 @@ GNUNET_SPEEDUP_start_ (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
87 | "Speed up executed every %s\n", | 91 | "Speed up executed every %s\n", |
88 | GNUNET_STRINGS_relative_time_to_string (interval, GNUNET_NO)); | 92 | GNUNET_STRINGS_relative_time_to_string (interval, GNUNET_NO)); |
89 | speedup_task = GNUNET_SCHEDULER_add_now_with_lifeness (GNUNET_NO, | 93 | speedup_task = GNUNET_SCHEDULER_add_now_with_lifeness (GNUNET_NO, |
90 | &do_speedup, NULL); | 94 | &do_speedup, |
95 | NULL); | ||
91 | return GNUNET_OK; | 96 | return GNUNET_OK; |
92 | } | 97 | } |
93 | 98 | ||
@@ -109,6 +114,4 @@ GNUNET_SPEEDUP_stop_ () | |||
109 | "Stopped execution speed up\n"); | 114 | "Stopped execution speed up\n"); |
110 | } | 115 | } |
111 | 116 | ||
112 | |||
113 | |||
114 | /* end of speedup.c */ | 117 | /* end of speedup.c */ |
diff --git a/src/util/test_common_logging_runtime_loglevels.c b/src/util/test_common_logging_runtime_loglevels.c index 21eb3c6c6..033b16ce1 100644 --- a/src/util/test_common_logging_runtime_loglevels.c +++ b/src/util/test_common_logging_runtime_loglevels.c | |||
@@ -234,7 +234,8 @@ read_call (void *cls) | |||
234 | FPRINTF (stderr, "got %d bytes, reading more\n", rd); | 234 | FPRINTF (stderr, "got %d bytes, reading more\n", rd); |
235 | #endif | 235 | #endif |
236 | read_task = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, | 236 | read_task = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, |
237 | stdout_read_handle, &read_call, | 237 | stdout_read_handle, |
238 | &read_call, | ||
238 | (void*) stdout_read_handle); | 239 | (void*) stdout_read_handle); |
239 | return; | 240 | return; |
240 | } | 241 | } |
@@ -411,7 +412,8 @@ runone () | |||
411 | 412 | ||
412 | die_task = | 413 | die_task = |
413 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | 414 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply |
414 | (GNUNET_TIME_UNIT_SECONDS, 10), &end_task, | 415 | (GNUNET_TIME_UNIT_SECONDS, 10), |
416 | &end_task, | ||
415 | NULL); | 417 | NULL); |
416 | 418 | ||
417 | bytes = 0; | 419 | bytes = 0; |
@@ -419,7 +421,8 @@ runone () | |||
419 | memset (&buf, 0, sizeof (buf)); | 421 | memset (&buf, 0, sizeof (buf)); |
420 | 422 | ||
421 | read_task = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, | 423 | read_task = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, |
422 | stdout_read_handle, &read_call, | 424 | stdout_read_handle, |
425 | &read_call, | ||
423 | (void*) stdout_read_handle); | 426 | (void*) stdout_read_handle); |
424 | } | 427 | } |
425 | 428 | ||
diff --git a/src/util/test_connection_receive_cancel.c b/src/util/test_connection_receive_cancel.c index 9ec96d8a6..9c0ab699e 100644 --- a/src/util/test_connection_receive_cancel.c +++ b/src/util/test_connection_receive_cancel.c | |||
@@ -60,7 +60,8 @@ open_listen_socket () | |||
60 | GNUNET_assert (desc != NULL); | 60 | GNUNET_assert (desc != NULL); |
61 | if (GNUNET_NETWORK_socket_setsockopt | 61 | if (GNUNET_NETWORK_socket_setsockopt |
62 | (desc, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on)) != GNUNET_OK) | 62 | (desc, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on)) != GNUNET_OK) |
63 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, "setsockopt"); | 63 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
64 | "setsockopt"); | ||
64 | GNUNET_assert (GNUNET_OK == | 65 | GNUNET_assert (GNUNET_OK == |
65 | GNUNET_NETWORK_socket_bind (desc, (const struct sockaddr *) &sa, | 66 | GNUNET_NETWORK_socket_bind (desc, (const struct sockaddr *) &sa, |
66 | sizeof (sa))); | 67 | sizeof (sa))); |
@@ -69,10 +70,13 @@ open_listen_socket () | |||
69 | } | 70 | } |
70 | 71 | ||
71 | 72 | ||
72 | |||
73 | static void | 73 | static void |
74 | dead_receive (void *cls, const void *buf, size_t available, | 74 | dead_receive (void *cls, |
75 | const struct sockaddr *addr, socklen_t addrlen, int errCode) | 75 | const void *buf, |
76 | size_t available, | ||
77 | const struct sockaddr *addr, | ||
78 | socklen_t addrlen, | ||
79 | int errCode) | ||
76 | { | 80 | { |
77 | GNUNET_assert (0); | 81 | GNUNET_assert (0); |
78 | } | 82 | } |
@@ -87,7 +91,8 @@ run_accept_cancel (void *cls) | |||
87 | GNUNET_CONNECTION_destroy (lsock); | 91 | GNUNET_CONNECTION_destroy (lsock); |
88 | GNUNET_CONNECTION_receive (asock, 1024, | 92 | GNUNET_CONNECTION_receive (asock, 1024, |
89 | GNUNET_TIME_relative_multiply | 93 | GNUNET_TIME_relative_multiply |
90 | (GNUNET_TIME_UNIT_SECONDS, 5), &dead_receive, cls); | 94 | (GNUNET_TIME_UNIT_SECONDS, 5), |
95 | &dead_receive, cls); | ||
91 | } | 96 | } |
92 | 97 | ||
93 | 98 | ||
@@ -103,7 +108,6 @@ receive_cancel_task (void *cls) | |||
103 | } | 108 | } |
104 | 109 | ||
105 | 110 | ||
106 | |||
107 | static void | 111 | static void |
108 | task_receive_cancel (void *cls) | 112 | task_receive_cancel (void *cls) |
109 | { | 113 | { |
@@ -112,14 +116,16 @@ task_receive_cancel (void *cls) | |||
112 | GNUNET_assert (lsock != NULL); | 116 | GNUNET_assert (lsock != NULL); |
113 | csock = GNUNET_CONNECTION_create_from_connect (cfg, "localhost", PORT); | 117 | csock = GNUNET_CONNECTION_create_from_connect (cfg, "localhost", PORT); |
114 | GNUNET_assert (csock != NULL); | 118 | GNUNET_assert (csock != NULL); |
115 | GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, ls, | 119 | GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, |
116 | &run_accept_cancel, cls); | 120 | ls, |
117 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &receive_cancel_task, | 121 | &run_accept_cancel, |
122 | cls); | ||
123 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, | ||
124 | &receive_cancel_task, | ||
118 | cls); | 125 | cls); |
119 | } | 126 | } |
120 | 127 | ||
121 | 128 | ||
122 | |||
123 | /** | 129 | /** |
124 | * Main method, starts scheduler with task_timeout. | 130 | * Main method, starts scheduler with task_timeout. |
125 | */ | 131 | */ |
@@ -130,7 +136,9 @@ check_receive_cancel () | |||
130 | 136 | ||
131 | ok = 1; | 137 | ok = 1; |
132 | cfg = GNUNET_CONFIGURATION_create (); | 138 | cfg = GNUNET_CONFIGURATION_create (); |
133 | GNUNET_CONFIGURATION_set_value_string (cfg, "resolver", "HOSTNAME", | 139 | GNUNET_CONFIGURATION_set_value_string (cfg, |
140 | "resolver", | ||
141 | "HOSTNAME", | ||
134 | "localhost"); | 142 | "localhost"); |
135 | GNUNET_SCHEDULER_run (&task_receive_cancel, &ok); | 143 | GNUNET_SCHEDULER_run (&task_receive_cancel, &ok); |
136 | GNUNET_CONFIGURATION_destroy (cfg); | 144 | GNUNET_CONFIGURATION_destroy (cfg); |
diff --git a/src/util/test_disk.c b/src/util/test_disk.c index 055e155e9..7b9a6d45c 100644 --- a/src/util/test_disk.c +++ b/src/util/test_disk.c | |||
@@ -28,6 +28,7 @@ | |||
28 | 28 | ||
29 | #define TESTSTRING "Hello World\0" | 29 | #define TESTSTRING "Hello World\0" |
30 | 30 | ||
31 | |||
31 | static int | 32 | static int |
32 | testReadWrite () | 33 | testReadWrite () |
33 | { | 34 | { |
@@ -79,6 +80,7 @@ testReadWrite () | |||
79 | return 0; | 80 | return 0; |
80 | } | 81 | } |
81 | 82 | ||
83 | |||
82 | static int | 84 | static int |
83 | testOpenClose () | 85 | testOpenClose () |
84 | { | 86 | { |
@@ -104,6 +106,7 @@ testOpenClose () | |||
104 | 106 | ||
105 | static int ok; | 107 | static int ok; |
106 | 108 | ||
109 | |||
107 | static int | 110 | static int |
108 | scan_callback (void *want, const char *filename) | 111 | scan_callback (void *want, const char *filename) |
109 | { | 112 | { |
@@ -112,41 +115,83 @@ scan_callback (void *want, const char *filename) | |||
112 | return GNUNET_OK; | 115 | return GNUNET_OK; |
113 | } | 116 | } |
114 | 117 | ||
118 | |||
115 | static int | 119 | static int |
116 | testDirScan () | 120 | testDirScan () |
117 | { | 121 | { |
118 | if (GNUNET_OK != | 122 | if (GNUNET_OK != |
119 | GNUNET_DISK_directory_create ("test" DIR_SEPARATOR_STR "entry")) | 123 | GNUNET_DISK_directory_create ("test" DIR_SEPARATOR_STR "entry")) |
124 | { | ||
125 | GNUNET_break (0); | ||
120 | return 1; | 126 | return 1; |
127 | } | ||
121 | if (GNUNET_OK != | 128 | if (GNUNET_OK != |
122 | GNUNET_DISK_directory_create ("test" DIR_SEPARATOR_STR "entry_more")) | 129 | GNUNET_DISK_directory_create ("test" DIR_SEPARATOR_STR "entry_more")) |
130 | { | ||
131 | GNUNET_break (0); | ||
123 | return 1; | 132 | return 1; |
133 | } | ||
124 | GNUNET_DISK_directory_scan ("test", &scan_callback, | 134 | GNUNET_DISK_directory_scan ("test", &scan_callback, |
125 | "test" DIR_SEPARATOR_STR "entry"); | 135 | "test" DIR_SEPARATOR_STR "entry"); |
126 | if (GNUNET_OK != GNUNET_DISK_directory_remove ("test")) | 136 | if (GNUNET_OK != GNUNET_DISK_directory_remove ("test")) |
137 | { | ||
138 | GNUNET_break (0); | ||
127 | return 1; | 139 | return 1; |
140 | } | ||
128 | if (ok < 2) | 141 | if (ok < 2) |
142 | { | ||
143 | GNUNET_break (0); | ||
129 | return 1; | 144 | return 1; |
145 | } | ||
130 | return 0; | 146 | return 0; |
131 | } | 147 | } |
132 | 148 | ||
133 | 149 | ||
134 | static int | 150 | static int |
151 | iter_callback (void *cls, | ||
152 | const char *filename) | ||
153 | { | ||
154 | int *i = cls; | ||
155 | |||
156 | (*i)++; | ||
157 | return GNUNET_OK; | ||
158 | } | ||
159 | |||
160 | |||
161 | static int | ||
135 | testDirIter () | 162 | testDirIter () |
136 | { | 163 | { |
137 | int i; | 164 | int i; |
138 | 165 | ||
139 | i = 0; | 166 | i = 0; |
140 | if (GNUNET_OK != GNUNET_DISK_directory_create ("test/entry")) | 167 | if (GNUNET_OK != GNUNET_DISK_directory_create ("test/entry")) |
168 | { | ||
169 | GNUNET_break (0); | ||
141 | return 1; | 170 | return 1; |
171 | } | ||
142 | if (GNUNET_OK != GNUNET_DISK_directory_create ("test/entry_many")) | 172 | if (GNUNET_OK != GNUNET_DISK_directory_create ("test/entry_many")) |
173 | { | ||
174 | GNUNET_break (0); | ||
143 | return 1; | 175 | return 1; |
176 | } | ||
144 | if (GNUNET_OK != GNUNET_DISK_directory_create ("test/entry_more")) | 177 | if (GNUNET_OK != GNUNET_DISK_directory_create ("test/entry_more")) |
178 | { | ||
179 | GNUNET_break (0); | ||
145 | return 1; | 180 | return 1; |
181 | } | ||
182 | GNUNET_DISK_directory_scan ("test", | ||
183 | &iter_callback, | ||
184 | &i); | ||
146 | if (GNUNET_OK != GNUNET_DISK_directory_remove ("test")) | 185 | if (GNUNET_OK != GNUNET_DISK_directory_remove ("test")) |
186 | { | ||
187 | GNUNET_break (0); | ||
147 | return 1; | 188 | return 1; |
189 | } | ||
148 | if (i < 3) | 190 | if (i < 3) |
191 | { | ||
192 | GNUNET_break (0); | ||
149 | return 1; | 193 | return 1; |
194 | } | ||
150 | return 0; | 195 | return 0; |
151 | } | 196 | } |
152 | 197 | ||
@@ -183,19 +228,40 @@ static int | |||
183 | testDirMani () | 228 | testDirMani () |
184 | { | 229 | { |
185 | if (GNUNET_OK != GNUNET_DISK_directory_create_for_file ("test/ing")) | 230 | if (GNUNET_OK != GNUNET_DISK_directory_create_for_file ("test/ing")) |
231 | { | ||
232 | GNUNET_break (0); | ||
186 | return 1; | 233 | return 1; |
234 | } | ||
187 | if (GNUNET_NO != GNUNET_DISK_file_test ("test")) | 235 | if (GNUNET_NO != GNUNET_DISK_file_test ("test")) |
236 | { | ||
237 | GNUNET_break (0); | ||
188 | return 1; | 238 | return 1; |
239 | } | ||
189 | if (GNUNET_NO != GNUNET_DISK_file_test ("test/ing")) | 240 | if (GNUNET_NO != GNUNET_DISK_file_test ("test/ing")) |
241 | { | ||
242 | GNUNET_break (0); | ||
190 | return 1; | 243 | return 1; |
244 | } | ||
191 | if (GNUNET_OK != GNUNET_DISK_directory_remove ("test")) | 245 | if (GNUNET_OK != GNUNET_DISK_directory_remove ("test")) |
246 | { | ||
247 | GNUNET_break (0); | ||
192 | return 1; | 248 | return 1; |
249 | } | ||
193 | if (GNUNET_OK != GNUNET_DISK_directory_create ("test")) | 250 | if (GNUNET_OK != GNUNET_DISK_directory_create ("test")) |
251 | { | ||
252 | GNUNET_break (0); | ||
194 | return 1; | 253 | return 1; |
254 | } | ||
195 | if (GNUNET_YES != GNUNET_DISK_directory_test ("test", GNUNET_YES)) | 255 | if (GNUNET_YES != GNUNET_DISK_directory_test ("test", GNUNET_YES)) |
256 | { | ||
257 | GNUNET_break (0); | ||
196 | return 1; | 258 | return 1; |
259 | } | ||
197 | if (GNUNET_OK != GNUNET_DISK_directory_remove ("test")) | 260 | if (GNUNET_OK != GNUNET_DISK_directory_remove ("test")) |
261 | { | ||
262 | GNUNET_break (0); | ||
198 | return 1; | 263 | return 1; |
264 | } | ||
199 | return 0; | 265 | return 0; |
200 | } | 266 | } |
201 | 267 | ||
@@ -213,9 +279,11 @@ main (int argc, char *argv[]) | |||
213 | failureCount += testCanonicalize (); | 279 | failureCount += testCanonicalize (); |
214 | failureCount += testChangeOwner (); | 280 | failureCount += testChangeOwner (); |
215 | failureCount += testDirMani (); | 281 | failureCount += testDirMani (); |
216 | if (failureCount != 0) | 282 | if (0 != failureCount) |
217 | { | 283 | { |
218 | FPRINTF (stderr, "\n%u TESTS FAILED!\n", failureCount); | 284 | FPRINTF (stderr, |
285 | "\n%u TESTS FAILED!\n", | ||
286 | failureCount); | ||
219 | return -1; | 287 | return -1; |
220 | } | 288 | } |
221 | return 0; | 289 | return 0; |
diff --git a/src/util/test_os_start_process.c b/src/util/test_os_start_process.c index c617917cc..929b24232 100644 --- a/src/util/test_os_start_process.c +++ b/src/util/test_os_start_process.c | |||
@@ -55,7 +55,9 @@ struct read_context | |||
55 | const struct GNUNET_DISK_FileHandle *stdout_read_handle; | 55 | const struct GNUNET_DISK_FileHandle *stdout_read_handle; |
56 | }; | 56 | }; |
57 | 57 | ||
58 | struct read_context rc; | 58 | |
59 | static struct read_context rc; | ||
60 | |||
59 | 61 | ||
60 | static void | 62 | static void |
61 | end_task (void *cls) | 63 | end_task (void *cls) |
@@ -77,35 +79,39 @@ read_call (void *cls) | |||
77 | { | 79 | { |
78 | int bytes; | 80 | int bytes; |
79 | 81 | ||
80 | bytes = GNUNET_DISK_file_read (rc.stdout_read_handle, &rc.buf[rc.buf_offset], \ | 82 | bytes = GNUNET_DISK_file_read (rc.stdout_read_handle, |
81 | sizeof (rc.buf) - rc.buf_offset); | 83 | &rc.buf[rc.buf_offset], |
82 | 84 | sizeof (rc.buf) - rc.buf_offset); | |
83 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "bytes is %d\n", bytes); | 85 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
86 | "bytes is %d\n", | ||
87 | bytes); | ||
84 | 88 | ||
85 | if (bytes < 1) | 89 | if (bytes < 1) |
86 | { | 90 | { |
87 | GNUNET_break (0); | 91 | GNUNET_break (0); |
88 | ok = 1; | 92 | ok = 1; |
89 | GNUNET_SCHEDULER_cancel (die_task); | 93 | GNUNET_SCHEDULER_cancel (die_task); |
90 | GNUNET_SCHEDULER_add_now (&end_task, NULL); | 94 | (void) GNUNET_SCHEDULER_add_now (&end_task, NULL); |
91 | return; | 95 | return; |
92 | } | 96 | } |
93 | 97 | ||
94 | ok = strncmp (rc.buf, test_phrase, strlen (test_phrase)); | 98 | ok = strncmp (rc.buf, test_phrase, strlen (test_phrase)); |
95 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "read %s\n", &rc.buf[rc.buf_offset]); | 99 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
100 | "read %s\n", | ||
101 | &rc.buf[rc.buf_offset]); | ||
96 | rc.buf_offset += bytes; | 102 | rc.buf_offset += bytes; |
97 | 103 | ||
98 | if (0 == ok) | 104 | if (0 == ok) |
99 | { | 105 | { |
100 | GNUNET_SCHEDULER_cancel (die_task); | 106 | GNUNET_SCHEDULER_cancel (die_task); |
101 | GNUNET_SCHEDULER_add_now (&end_task, NULL); | 107 | (void) GNUNET_SCHEDULER_add_now (&end_task, NULL); |
102 | return; | 108 | return; |
103 | } | 109 | } |
104 | 110 | ||
105 | GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, | 111 | GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, |
106 | rc.stdout_read_handle, &read_call, | 112 | rc.stdout_read_handle, |
113 | &read_call, | ||
107 | NULL); | 114 | NULL); |
108 | |||
109 | } | 115 | } |
110 | 116 | ||
111 | 117 | ||
@@ -164,13 +170,15 @@ run_task (void *cls) | |||
164 | 170 | ||
165 | die_task = | 171 | die_task = |
166 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | 172 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply |
167 | (GNUNET_TIME_UNIT_MINUTES, 1), &end_task, | 173 | (GNUNET_TIME_UNIT_MINUTES, 1), |
174 | &end_task, | ||
168 | NULL); | 175 | NULL); |
169 | 176 | ||
170 | memset (&rc, 0, sizeof (rc)); | 177 | memset (&rc, 0, sizeof (rc)); |
171 | rc.stdout_read_handle = stdout_read_handle; | 178 | rc.stdout_read_handle = stdout_read_handle; |
172 | GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, | 179 | GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, |
173 | stdout_read_handle, &read_call, | 180 | stdout_read_handle, |
181 | &read_call, | ||
174 | NULL); | 182 | NULL); |
175 | } | 183 | } |
176 | 184 | ||
@@ -205,9 +213,12 @@ check_kill () | |||
205 | fn = GNUNET_OS_get_libexec_binary_path ("gnunet-service-resolver"); | 213 | fn = GNUNET_OS_get_libexec_binary_path ("gnunet-service-resolver"); |
206 | proc = | 214 | proc = |
207 | GNUNET_OS_start_process (GNUNET_YES, GNUNET_OS_INHERIT_STD_ERR, | 215 | GNUNET_OS_start_process (GNUNET_YES, GNUNET_OS_INHERIT_STD_ERR, |
208 | hello_pipe_stdin, hello_pipe_stdout, NULL, | 216 | hello_pipe_stdin, |
217 | hello_pipe_stdout, | ||
218 | NULL, | ||
209 | fn, | 219 | fn, |
210 | "gnunet-service-resolver", "-", NULL); | 220 | "gnunet-service-resolver", "-", |
221 | NULL); | ||
211 | sleep (1); /* give process time to start, so we actually use the pipe-kill mechanism! */ | 222 | sleep (1); /* give process time to start, so we actually use the pipe-kill mechanism! */ |
212 | GNUNET_free (fn); | 223 | GNUNET_free (fn); |
213 | if (0 != GNUNET_OS_process_kill (proc, GNUNET_TERM_SIG)) | 224 | if (0 != GNUNET_OS_process_kill (proc, GNUNET_TERM_SIG)) |
diff --git a/src/util/test_scheduler.c b/src/util/test_scheduler.c index a246d75c5..55d4c7137 100644 --- a/src/util/test_scheduler.c +++ b/src/util/test_scheduler.c | |||
@@ -25,7 +25,7 @@ | |||
25 | #include "gnunet_util_lib.h" | 25 | #include "gnunet_util_lib.h" |
26 | 26 | ||
27 | 27 | ||
28 | struct GNUNET_DISK_PipeHandle *p; | 28 | static struct GNUNET_DISK_PipeHandle *p; |
29 | 29 | ||
30 | static const struct GNUNET_DISK_FileHandle *fds[2]; | 30 | static const struct GNUNET_DISK_FileHandle *fds[2]; |
31 | 31 | ||
@@ -80,7 +80,6 @@ taskLast (void *cls) | |||
80 | { | 80 | { |
81 | int *ok = cls; | 81 | int *ok = cls; |
82 | 82 | ||
83 | /* t4 should be ready (albeit with lower priority) */ | ||
84 | GNUNET_assert (8 == *ok); | 83 | GNUNET_assert (8 == *ok); |
85 | (*ok) = 0; | 84 | (*ok) = 0; |
86 | } | 85 | } |
@@ -98,8 +97,8 @@ taskRd (void *cls) | |||
98 | GNUNET_assert (GNUNET_NETWORK_fdset_handle_isset (tc->read_ready, fds[0])); | 97 | GNUNET_assert (GNUNET_NETWORK_fdset_handle_isset (tc->read_ready, fds[0])); |
99 | GNUNET_assert (1 == GNUNET_DISK_file_read (fds[0], &c, 1)); | 98 | GNUNET_assert (1 == GNUNET_DISK_file_read (fds[0], &c, 1)); |
100 | (*ok) = 8; | 99 | (*ok) = 8; |
101 | GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE, &taskLast, | 100 | GNUNET_SCHEDULER_add_shutdown (&taskLast, |
102 | cls); | 101 | cls); |
103 | GNUNET_SCHEDULER_shutdown (); | 102 | GNUNET_SCHEDULER_shutdown (); |
104 | } | 103 | } |
105 | 104 | ||
@@ -115,10 +114,14 @@ task4 (void *cls) | |||
115 | GNUNET_assert (NULL != p); | 114 | GNUNET_assert (NULL != p); |
116 | fds[0] = GNUNET_DISK_pipe_handle (p, GNUNET_DISK_PIPE_END_READ); | 115 | fds[0] = GNUNET_DISK_pipe_handle (p, GNUNET_DISK_PIPE_END_READ); |
117 | fds[1] = GNUNET_DISK_pipe_handle (p, GNUNET_DISK_PIPE_END_WRITE); | 116 | fds[1] = GNUNET_DISK_pipe_handle (p, GNUNET_DISK_PIPE_END_WRITE); |
118 | GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, fds[0], &taskRd, | 117 | GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, |
118 | fds[0], | ||
119 | &taskRd, | ||
119 | cls); | 120 | cls); |
120 | GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL, fds[1], | 121 | GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL, |
121 | &taskWrt, cls); | 122 | fds[1], |
123 | &taskWrt, | ||
124 | cls); | ||
122 | } | 125 | } |
123 | 126 | ||
124 | 127 | ||
@@ -130,9 +133,12 @@ task1 (void *cls) | |||
130 | GNUNET_assert (1 == *ok); | 133 | GNUNET_assert (1 == *ok); |
131 | (*ok) = 2; | 134 | (*ok) = 2; |
132 | GNUNET_SCHEDULER_add_now (&task3, cls); | 135 | GNUNET_SCHEDULER_add_now (&task3, cls); |
133 | GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_UI, &task2, | 136 | GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_UI, |
137 | &task2, | ||
134 | cls); | 138 | cls); |
135 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &task4, cls); | 139 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, |
140 | &task4, | ||
141 | cls); | ||
136 | } | 142 | } |
137 | 143 | ||
138 | 144 | ||
@@ -158,7 +164,7 @@ taskShutdown (void *cls) | |||
158 | 164 | ||
159 | GNUNET_assert (1 == *ok); | 165 | GNUNET_assert (1 == *ok); |
160 | *ok = 8; | 166 | *ok = 8; |
161 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &taskLast, cls); | 167 | GNUNET_SCHEDULER_add_shutdown (&taskLast, cls); |
162 | GNUNET_SCHEDULER_shutdown (); | 168 | GNUNET_SCHEDULER_shutdown (); |
163 | } | 169 | } |
164 | 170 | ||
@@ -186,8 +192,9 @@ taskSig (void *cls) | |||
186 | 192 | ||
187 | GNUNET_assert (1 == *ok); | 193 | GNUNET_assert (1 == *ok); |
188 | *ok = 8; | 194 | *ok = 8; |
189 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &taskLast, cls); | 195 | GNUNET_SCHEDULER_add_shutdown (&taskLast, cls); |
190 | GNUNET_break (0 == PLIBC_KILL (getpid (), GNUNET_TERM_SIG)); | 196 | GNUNET_break (0 == PLIBC_KILL (getpid (), |
197 | GNUNET_TERM_SIG)); | ||
191 | } | 198 | } |
192 | 199 | ||
193 | 200 | ||
@@ -214,8 +221,7 @@ taskCancel (void *cls) | |||
214 | 221 | ||
215 | GNUNET_assert (1 == *ok); | 222 | GNUNET_assert (1 == *ok); |
216 | *ok = 0; | 223 | *ok = 0; |
217 | GNUNET_SCHEDULER_cancel (GNUNET_SCHEDULER_add_now | 224 | GNUNET_SCHEDULER_cancel (GNUNET_SCHEDULER_add_now (&taskNeverRun, NULL)); |
218 | (&taskNeverRun, NULL)); | ||
219 | } | 225 | } |
220 | 226 | ||
221 | 227 | ||
diff --git a/src/util/test_scheduler_delay.c b/src/util/test_scheduler_delay.c index c55f28e9b..93568cd81 100644 --- a/src/util/test_scheduler_delay.c +++ b/src/util/test_scheduler_delay.c | |||
@@ -62,7 +62,8 @@ test_task (void *cls) | |||
62 | return; | 62 | return; |
63 | } | 63 | } |
64 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | 64 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply |
65 | (GNUNET_TIME_UNIT_MICROSECONDS, i), &test_task, | 65 | (GNUNET_TIME_UNIT_MICROSECONDS, i), |
66 | &test_task, | ||
66 | NULL); | 67 | NULL); |
67 | i += INCR; | 68 | i += INCR; |
68 | } | 69 | } |
@@ -71,7 +72,9 @@ test_task (void *cls) | |||
71 | int | 72 | int |
72 | main (int argc, char *argv[]) | 73 | main (int argc, char *argv[]) |
73 | { | 74 | { |
74 | GNUNET_log_setup ("test-scheduler-delay", "WARNING", NULL); | 75 | GNUNET_log_setup ("test-scheduler-delay", |
76 | "WARNING", | ||
77 | NULL); | ||
75 | target = GNUNET_TIME_absolute_get (); | 78 | target = GNUNET_TIME_absolute_get (); |
76 | GNUNET_SCHEDULER_run (&test_task, NULL); | 79 | GNUNET_SCHEDULER_run (&test_task, NULL); |
77 | FPRINTF (stdout, | 80 | FPRINTF (stdout, |
diff --git a/src/util/test_server_disconnect.c b/src/util/test_server_disconnect.c index 21abf92bb..f59fa547f 100644 --- a/src/util/test_server_disconnect.c +++ b/src/util/test_server_disconnect.c | |||
@@ -76,7 +76,8 @@ server_disconnect (void *cls) | |||
76 | 76 | ||
77 | 77 | ||
78 | static void | 78 | static void |
79 | recv_cb (void *cls, struct GNUNET_SERVER_Client *client, | 79 | recv_cb (void *cls, |
80 | struct GNUNET_SERVER_Client *client, | ||
80 | const struct GNUNET_MessageHeader *message) | 81 | const struct GNUNET_MessageHeader *message) |
81 | { | 82 | { |
82 | GNUNET_assert (ok == 2); | 83 | GNUNET_assert (ok == 2); |
diff --git a/src/util/test_server_with_client_unix.c b/src/util/test_server_with_client_unix.c index ec84b08f8..64f1d9c23 100644 --- a/src/util/test_server_with_client_unix.c +++ b/src/util/test_server_with_client_unix.c | |||
@@ -50,16 +50,18 @@ send_done (void *cls) | |||
50 | 50 | ||
51 | 51 | ||
52 | static void | 52 | static void |
53 | recv_cb (void *cls, struct GNUNET_SERVER_Client *argclient, | 53 | recv_cb (void *cls, |
54 | struct GNUNET_SERVER_Client *argclient, | ||
54 | const struct GNUNET_MessageHeader *message) | 55 | const struct GNUNET_MessageHeader *message) |
55 | { | 56 | { |
56 | switch (ok) | 57 | switch (ok) |
57 | { | 58 | { |
58 | case 2: | 59 | case 2: |
59 | ok++; | 60 | ok++; |
60 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | 61 | (void) GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply |
61 | (GNUNET_TIME_UNIT_MILLISECONDS, 50), | 62 | (GNUNET_TIME_UNIT_MILLISECONDS, 50), |
62 | &send_done, argclient); | 63 | &send_done, |
64 | argclient); | ||
63 | break; | 65 | break; |
64 | case 4: | 66 | case 4: |
65 | ok++; | 67 | ok++; |
@@ -91,13 +93,14 @@ clean_up (void *cls) | |||
91 | * @param client identification of the client | 93 | * @param client identification of the client |
92 | */ | 94 | */ |
93 | static void | 95 | static void |
94 | notify_disconnect (void *cls, struct GNUNET_SERVER_Client *client) | 96 | notify_disconnect (void *cls, |
97 | struct GNUNET_SERVER_Client *client) | ||
95 | { | 98 | { |
96 | if (client == NULL) | 99 | if (client == NULL) |
97 | return; | 100 | return; |
98 | GNUNET_assert (ok == 5); | 101 | GNUNET_assert (ok == 5); |
99 | ok = 0; | 102 | ok = 0; |
100 | GNUNET_SCHEDULER_add_now (&clean_up, NULL); | 103 | (void) GNUNET_SCHEDULER_add_now (&clean_up, NULL); |
101 | } | 104 | } |
102 | 105 | ||
103 | 106 | ||
diff --git a/src/util/test_speedup.c b/src/util/test_speedup.c index 5d46e3127..b9f2cfb4d 100644 --- a/src/util/test_speedup.c +++ b/src/util/test_speedup.c | |||
@@ -53,7 +53,9 @@ run (void *cls) | |||
53 | fprintf (stderr, "..%u", cycles); | 53 | fprintf (stderr, "..%u", cycles); |
54 | if (cycles <= 5) | 54 | if (cycles <= 5) |
55 | { | 55 | { |
56 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &run, NULL); | 56 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, |
57 | &run, | ||
58 | NULL); | ||
57 | return; | 59 | return; |
58 | } | 60 | } |
59 | end = GNUNET_TIME_absolute_get(); | 61 | end = GNUNET_TIME_absolute_get(); |
@@ -66,21 +68,22 @@ run (void *cls) | |||
66 | * | 68 | * |
67 | */ | 69 | */ |
68 | static void | 70 | static void |
69 | check (void *cls, char *const *args, | 71 | check (void *cls, |
72 | char *const *args, | ||
70 | const char *cfgfile, | 73 | const char *cfgfile, |
71 | const struct GNUNET_CONFIGURATION_Handle * | 74 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
72 | cfg) | ||
73 | { | 75 | { |
74 | fprintf (stderr, "0"); | 76 | fprintf (stderr, "0"); |
75 | fflush(stdout); | 77 | fflush (stdout); |
76 | GNUNET_SCHEDULER_add_now(&run, NULL); | 78 | GNUNET_SCHEDULER_add_now (&run, NULL); |
77 | } | 79 | } |
78 | 80 | ||
79 | 81 | ||
80 | int | 82 | int |
81 | main (int argc, char *argv[]) | 83 | main (int argc, char *argv[]) |
82 | { | 84 | { |
83 | static char *const argvn[] = { "test-speedup", | 85 | static char *const argvn[] = { |
86 | "test-speedup", | ||
84 | "-c", "test_speedup_data.conf", | 87 | "-c", "test_speedup_data.conf", |
85 | NULL | 88 | NULL |
86 | }; | 89 | }; |