aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/include/gnunet_scheduler_lib.h53
-rw-r--r--src/util/scheduler.c177
2 files changed, 158 insertions, 72 deletions
diff --git a/src/include/gnunet_scheduler_lib.h b/src/include/gnunet_scheduler_lib.h
index 83d9d261a..24e316b47 100644
--- a/src/include/gnunet_scheduler_lib.h
+++ b/src/include/gnunet_scheduler_lib.h
@@ -29,6 +29,8 @@
29#ifndef GNUNET_SCHEDULER_LIB_H 29#ifndef GNUNET_SCHEDULER_LIB_H
30#define GNUNET_SCHEDULER_LIB_H 30#define GNUNET_SCHEDULER_LIB_H
31 31
32#include <stdbool.h>
33
32#ifdef __cplusplus 34#ifdef __cplusplus
33extern "C" 35extern "C"
34{ 36{
@@ -468,6 +470,31 @@ GNUNET_SCHEDULER_add_write_net (struct GNUNET_TIME_Relative delay,
468 470
469/** 471/**
470 * Schedule a new task to be run with a specified delay or when the 472 * Schedule a new task to be run with a specified delay or when the
473 * specified file descriptor is ready. The delay can be
474 * used as a timeout on the socket being ready. The task will be
475 * scheduled for execution once either the delay has expired or the
476 * socket operation is ready.
477 *
478 * @param delay when should this operation time out? Use
479 * GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown"
480 * @param priority priority of the task
481 * @param fd file-descriptor
482 * @param on_read whether to poll the file-descriptor for readability
483 * @param on_write whether to poll the file-descriptor for writability
484 * @param task main function of the task
485 * @param task_cls closure of task
486 * @return unique task identifier for the job
487 * only valid until "task" is started!
488 */
489GNUNET_SCHEDULER_TaskIdentifier
490GNUNET_SCHEDULER_add_net_with_priority (struct GNUNET_TIME_Relative delay,
491 enum GNUNET_SCHEDULER_Priority priority,
492 struct GNUNET_NETWORK_Handle *fd,
493 bool on_read, bool on_write,
494 GNUNET_SCHEDULER_Task task, void *task_cls);
495
496/**
497 * Schedule a new task to be run with a specified delay or when the
471 * specified file descriptor is ready for reading. The delay can be 498 * specified file descriptor is ready for reading. The delay can be
472 * used as a timeout on the socket being ready. The task will be 499 * used as a timeout on the socket being ready. The task will be
473 * scheduled for execution once either the delay has expired or the 500 * scheduled for execution once either the delay has expired or the
@@ -509,6 +536,32 @@ GNUNET_SCHEDULER_add_write_file (struct GNUNET_TIME_Relative delay,
509 536
510 537
511/** 538/**
539 * Schedule a new task to be run with a specified delay or when the
540 * specified file descriptor is ready. The delay can be
541 * used as a timeout on the socket being ready. The task will be
542 * scheduled for execution once either the delay has expired or the
543 * socket operation is ready.
544 *
545 * @param delay when should this operation time out? Use
546 * GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown"
547 * @param priority priority of the task
548 * @param fd file-descriptor
549 * @param on_read whether to poll the file-descriptor for readability
550 * @param on_write whether to poll the file-descriptor for writability
551 * @param task main function of the task
552 * @param task_cls closure of task
553 * @return unique task identifier for the job
554 * only valid until "task" is started!
555 */
556GNUNET_SCHEDULER_TaskIdentifier
557GNUNET_SCHEDULER_add_file_with_priority (struct GNUNET_TIME_Relative delay,
558 enum GNUNET_SCHEDULER_Priority priority,
559 const struct GNUNET_DISK_FileHandle *fd,
560 bool on_read, bool on_write,
561 GNUNET_SCHEDULER_Task task, void *task_cls);
562
563
564/**
512 * Schedule a new task to be run with a specified delay or when any of 565 * Schedule a new task to be run with a specified delay or when any of
513 * the specified file descriptor sets is ready. The delay can be used 566 * the specified file descriptor sets is ready. The delay can be used
514 * as a timeout on the socket(s) being ready. The task will be 567 * as a timeout on the socket(s) being ready. The task will be
diff --git a/src/util/scheduler.c b/src/util/scheduler.c
index cf1e073b1..ba6a04e4f 100644
--- a/src/util/scheduler.c
+++ b/src/util/scheduler.c
@@ -1418,25 +1418,10 @@ GNUNET_SCHEDULER_add_read_net_with_priority (struct GNUNET_TIME_Relative delay,
1418 struct GNUNET_NETWORK_Handle *rfd, 1418 struct GNUNET_NETWORK_Handle *rfd,
1419 GNUNET_SCHEDULER_Task task, void *task_cls) 1419 GNUNET_SCHEDULER_Task task, void *task_cls)
1420{ 1420{
1421#if MINGW 1421 return GNUNET_SCHEDULER_add_net_with_priority (
1422 struct GNUNET_NETWORK_FDSet *rs; 1422 delay, priority,
1423 GNUNET_SCHEDULER_TaskIdentifier ret; 1423 rfd, true, false,
1424 1424 task, task_cls);
1425 GNUNET_assert (NULL != rfd);
1426 rs = GNUNET_NETWORK_fdset_create ();
1427 GNUNET_NETWORK_fdset_set (rs, rfd);
1428 ret =
1429 GNUNET_SCHEDULER_add_select (priority,
1430 delay, rs, NULL,
1431 task, task_cls);
1432 GNUNET_NETWORK_fdset_destroy (rs);
1433 return ret;
1434#else
1435 return add_without_sets (delay,
1436 priority,
1437 GNUNET_NETWORK_get_fd (rfd), -1, task,
1438 task_cls);
1439#endif
1440} 1425}
1441 1426
1442 1427
@@ -1461,25 +1446,58 @@ GNUNET_SCHEDULER_add_write_net (struct GNUNET_TIME_Relative delay,
1461 struct GNUNET_NETWORK_Handle *wfd, 1446 struct GNUNET_NETWORK_Handle *wfd,
1462 GNUNET_SCHEDULER_Task task, void *task_cls) 1447 GNUNET_SCHEDULER_Task task, void *task_cls)
1463{ 1448{
1449 return GNUNET_SCHEDULER_add_net_with_priority (
1450 delay, GNUNET_SCHEDULER_PRIORITY_DEFAULT,
1451 wfd, false, true,
1452 task, task_cls);
1453}
1454
1455/**
1456 * Schedule a new task to be run with a specified delay or when the
1457 * specified file descriptor is ready. The delay can be
1458 * used as a timeout on the socket being ready. The task will be
1459 * scheduled for execution once either the delay has expired or the
1460 * socket operation is ready.
1461 *
1462 * @param delay when should this operation time out? Use
1463 * GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown"
1464 * @param priority priority of the task
1465 * @param fd file-descriptor
1466 * @param on_read whether to poll the file-descriptor for readability
1467 * @param on_write whether to poll the file-descriptor for writability
1468 * @param task main function of the task
1469 * @param task_cls closure of task
1470 * @return unique task identifier for the job
1471 * only valid until "task" is started!
1472 */
1473GNUNET_SCHEDULER_TaskIdentifier
1474GNUNET_SCHEDULER_add_net_with_priority (struct GNUNET_TIME_Relative delay,
1475 enum GNUNET_SCHEDULER_Priority priority,
1476 struct GNUNET_NETWORK_Handle *fd,
1477 bool on_read, bool on_write,
1478 GNUNET_SCHEDULER_Task task, void *task_cls)
1479{
1464#if MINGW 1480#if MINGW
1465 struct GNUNET_NETWORK_FDSet *ws; 1481 struct GNUNET_NETWORK_FDSet *s;
1466 GNUNET_SCHEDULER_TaskIdentifier ret; 1482 GNUNET_SCHEDULER_TaskIdentifier ret;
1467 1483
1468 GNUNET_assert (NULL != wfd); 1484 GNUNET_assert (fd != NULL);
1469 ws = GNUNET_NETWORK_fdset_create (); 1485 s = GNUNET_NETWORK_fdset_create ();
1470 GNUNET_NETWORK_fdset_set (ws, wfd); 1486 GNUNET_NETWORK_fdset_set (s, fd);
1471 ret = 1487 ret = GNUNET_SCHEDULER_add_select (
1472 GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, 1488 priority, delay,
1473 delay, NULL, ws, 1489 on_read ? s : NULL,
1474 task, task_cls); 1490 on_write ? s : NULL,
1475 GNUNET_NETWORK_fdset_destroy (ws); 1491 task, task_cls);
1492 GNUNET_NETWORK_fdset_destroy (s);
1476 return ret; 1493 return ret;
1477#else 1494#else
1478 GNUNET_assert (GNUNET_NETWORK_get_fd (wfd) >= 0); 1495 GNUNET_assert (GNUNET_NETWORK_get_fd (fd) >= 0);
1479 return add_without_sets (delay, 1496 return add_without_sets (
1480 GNUNET_SCHEDULER_PRIORITY_DEFAULT, 1497 delay, priority,
1481 -1, GNUNET_NETWORK_get_fd (wfd), task, 1498 on_read ? GNUNET_NETWORK_get_fd (fd) : -1,
1482 task_cls); 1499 on_write ? GNUNET_NETWORK_get_fd (fd) : -1,
1500 task, task_cls);
1483#endif 1501#endif
1484} 1502}
1485 1503
@@ -1504,28 +1522,10 @@ GNUNET_SCHEDULER_add_read_file (struct GNUNET_TIME_Relative delay,
1504 const struct GNUNET_DISK_FileHandle *rfd, 1522 const struct GNUNET_DISK_FileHandle *rfd,
1505 GNUNET_SCHEDULER_Task task, void *task_cls) 1523 GNUNET_SCHEDULER_Task task, void *task_cls)
1506{ 1524{
1507#if MINGW 1525 return GNUNET_SCHEDULER_add_file_with_priority (
1508 struct GNUNET_NETWORK_FDSet *rs; 1526 delay, GNUNET_SCHEDULER_PRIORITY_DEFAULT,
1509 GNUNET_SCHEDULER_TaskIdentifier ret; 1527 rfd, true, false,
1510 1528 task, task_cls);
1511 GNUNET_assert (NULL != rfd);
1512 rs = GNUNET_NETWORK_fdset_create ();
1513 GNUNET_NETWORK_fdset_handle_set (rs, rfd);
1514 ret =
1515 GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
1516 delay, rs, NULL,
1517 task, task_cls);
1518 GNUNET_NETWORK_fdset_destroy (rs);
1519 return ret;
1520#else
1521 int fd;
1522
1523 GNUNET_DISK_internal_file_handle_ (rfd, &fd, sizeof (int));
1524 return add_without_sets (delay,
1525 GNUNET_SCHEDULER_PRIORITY_DEFAULT,
1526 fd, -1, task, task_cls);
1527
1528#endif
1529} 1529}
1530 1530
1531 1531
@@ -1549,28 +1549,61 @@ GNUNET_SCHEDULER_add_write_file (struct GNUNET_TIME_Relative delay,
1549 const struct GNUNET_DISK_FileHandle *wfd, 1549 const struct GNUNET_DISK_FileHandle *wfd,
1550 GNUNET_SCHEDULER_Task task, void *task_cls) 1550 GNUNET_SCHEDULER_Task task, void *task_cls)
1551{ 1551{
1552 return GNUNET_SCHEDULER_add_file_with_priority (
1553 delay, GNUNET_SCHEDULER_PRIORITY_DEFAULT,
1554 wfd, false, true,
1555 task, task_cls);
1556}
1557
1558/**
1559 * Schedule a new task to be run with a specified delay or when the
1560 * specified file descriptor is ready. The delay can be
1561 * used as a timeout on the socket being ready. The task will be
1562 * scheduled for execution once either the delay has expired or the
1563 * socket operation is ready.
1564 *
1565 * @param delay when should this operation time out? Use
1566 * GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown"
1567 * @param priority priority of the task
1568 * @param fd file-descriptor
1569 * @param on_read whether to poll the file-descriptor for readability
1570 * @param on_write whether to poll the file-descriptor for writability
1571 * @param task main function of the task
1572 * @param task_cls closure of task
1573 * @return unique task identifier for the job
1574 * only valid until "task" is started!
1575 */
1576GNUNET_SCHEDULER_TaskIdentifier
1577GNUNET_SCHEDULER_add_file_with_priority (struct GNUNET_TIME_Relative delay,
1578 enum GNUNET_SCHEDULER_Priority priority,
1579 const struct GNUNET_DISK_FileHandle *fd,
1580 bool on_read, bool on_write,
1581 GNUNET_SCHEDULER_Task task, void *task_cls)
1582{
1552#if MINGW 1583#if MINGW
1553 struct GNUNET_NETWORK_FDSet *ws; 1584 struct GNUNET_NETWORK_FDSet *s;
1554 GNUNET_SCHEDULER_TaskIdentifier ret; 1585 GNUNET_SCHEDULER_TaskIdentifier ret;
1555 1586
1556 GNUNET_assert (NULL != wfd); 1587 GNUNET_assert (fd != NULL);
1557 ws = GNUNET_NETWORK_fdset_create (); 1588 s = GNUNET_NETWORK_fdset_create ();
1558 GNUNET_NETWORK_fdset_handle_set (ws, wfd); 1589 GNUNET_NETWORK_fdset_handle_set (s, fd);
1559 ret = 1590 ret = GNUNET_SCHEDULER_add_select (
1560 GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, 1591 priority, delay,
1561 delay, NULL, ws, 1592 on_read ? s : NULL,
1562 task, task_cls); 1593 on_write ? s : NULL,
1563 GNUNET_NETWORK_fdset_destroy (ws); 1594 task, task_cls);
1595 GNUNET_NETWORK_fdset_destroy (s);
1564 return ret; 1596 return ret;
1565#else 1597#else
1566 int fd; 1598 int real_fd;
1567 1599
1568 GNUNET_DISK_internal_file_handle_ (wfd, &fd, sizeof (int)); 1600 GNUNET_DISK_internal_file_handle_ (fd, &real_fd, sizeof (int));
1569 GNUNET_assert (fd >= 0); 1601 GNUNET_assert (real_fd > 0);
1570 return add_without_sets (delay, 1602 return add_without_sets (
1571 GNUNET_SCHEDULER_PRIORITY_DEFAULT, 1603 delay, priority,
1572 -1, fd, task, task_cls); 1604 on_read ? real_fd : -1,
1573 1605 on_write ? real_fd : -1,
1606 task, task_cls);
1574#endif 1607#endif
1575} 1608}
1576 1609