diff options
author | lurchi <lurchi@strangeplace.net> | 2017-07-21 01:27:22 +0200 |
---|---|---|
committer | lurchi <lurchi@strangeplace.net> | 2017-07-21 01:27:22 +0200 |
commit | 516babaed25b7b23ba27fc837bdc19643ec54d78 (patch) | |
tree | 204a33ff28454cd3f16536af298fb119f327312f /src/util/scheduler.c | |
parent | 7f843df63bd3d1a85d687f3e0de23594b43af6d3 (diff) | |
download | gnunet-516babaed25b7b23ba27fc837bdc19643ec54d78.tar.gz gnunet-516babaed25b7b23ba27fc837bdc19643ec54d78.zip |
adapt add_without_sets to scheduler driver API; reimplement initFdInfo
Diffstat (limited to 'src/util/scheduler.c')
-rw-r--r-- | src/util/scheduler.c | 113 |
1 files changed, 84 insertions, 29 deletions
diff --git a/src/util/scheduler.c b/src/util/scheduler.c index 1275a684b..070c0daa8 100644 --- a/src/util/scheduler.c +++ b/src/util/scheduler.c | |||
@@ -1055,23 +1055,67 @@ GNUNET_SCHEDULER_get_load (enum GNUNET_SCHEDULER_Priority p) | |||
1055 | * @param task id of the task to cancel | 1055 | * @param task id of the task to cancel |
1056 | * @return original closure of the task | 1056 | * @return original closure of the task |
1057 | */ | 1057 | */ |
1058 | void initFdInfo(struct GNUNET_SCHEDULER_FdInfo *fdi, struct GNUNET_SCHEDULER_Task *task) | 1058 | void |
1059 | initFdInfo(struct GNUNET_SCHEDULER_Task *task, | ||
1060 | struct GNUNET_NETWORK_Handle *read_nh, | ||
1061 | struct GNUNET_NETWORK_Handle *write_nh, | ||
1062 | struct GNUNET_DISK_FileHandle *read_fh, | ||
1063 | struct GNUNET_DISK_FileHandle *write_fh) | ||
1059 | { | 1064 | { |
1060 | if (-1 != task->read_fd) | 1065 | // either only network handles or only file handles are allowed |
1066 | GNUNET_assert (!((NULL != read_nh || NULL != write_nh) && (NULL != read_fh || NULL != write_fh))); | ||
1067 | |||
1068 | if (NULL != read_nh && NULL != write_nh) | ||
1069 | { | ||
1070 | t->fds_len = 2; | ||
1071 | t->fds = | ||
1072 | GNUNET_new_array (2, struct GNUNET_SCHEDULER_FdInfo); | ||
1073 | struct GNUNET_SCHEDULER_FdInfo *read_fdi = t->fds; | ||
1074 | struct GNUENT_SCHEDULER_FdInfo *write_fdi = t->fds + 1; | ||
1075 | read_fdi->fd = read_nh; | ||
1076 | read_fdi->et = GNUNET_SCHEDULER_ET_IN; | ||
1077 | read_fdi->sock = GNUNET_NETWORK_get_fd (read_nh); | ||
1078 | write_fdi->fd = write_nh; | ||
1079 | write_fdi->et = GNUNET_SCHEDULER_ET_OUT; | ||
1080 | write_fdi->sock = GNUNET_NETWORK_get_fd (write_nh); | ||
1081 | } | ||
1082 | else if (NULL != read_fh && NULL != write_fh) | ||
1061 | { | 1083 | { |
1062 | fdi->sock=task->read_fd; | 1084 | t->fds_len = 2; |
1085 | t->fds = | ||
1086 | GNUNET_new_array (2, struct GNUNET_SCHEDULER_FdInfo); | ||
1087 | struct GNUNET_SCHEDULER_FdInfo *read_fdi = t->fds; | ||
1088 | struct GNUENT_SCHEDULER_FdInfo *write_fdi = t->fds + 1; | ||
1089 | read_fdi->fh = read_fh; | ||
1090 | read_fdi->et = GNUNET_SCHEDULER_ET_IN; | ||
1091 | write_fdi->fh = write_fh; | ||
1092 | write_fdi->et = GNUNET_SCHEDULER_ET_OUT; | ||
1063 | } | 1093 | } |
1064 | else if (-1 != task->write_fd) | 1094 | else if (NULL != read_nh) |
1065 | { | 1095 | { |
1066 | fdi->sock=task->write_fd; | 1096 | struct GNUNET_SCHEDULER_FdInfo *read_fdi = &t->fdx; |
1097 | read_fdi->fd = read_nh; | ||
1098 | read_fdi->et = GNUNET_SCHEDULER_ET_IN; | ||
1099 | read_fdi->sock = GNUNET_NETWORK_get_fd (read_nh); | ||
1067 | } | 1100 | } |
1068 | else if (NULL != task->read_set) | 1101 | else if (NULL != write_nh) |
1069 | { | 1102 | { |
1070 | fdi->fd=task->read_set; | 1103 | struct GNUNET_SCHEDULER_FdInfo *write_fdi = &t->fdx; |
1104 | write_fdi->fd = write_nh; | ||
1105 | write_fdi->et = GNUNET_SCHEDULER_ET_OUT; | ||
1106 | write_fdi->sock = GNUNET_NETWORK_get_fd (write_nh); | ||
1071 | } | 1107 | } |
1072 | else if (NULL != task->write_set) | 1108 | else if (NULL != read_fh) |
1073 | { | 1109 | { |
1074 | fdi->fd=task->write_set; | 1110 | struct GNUNET_SCHEDULER_FdInfo *read_fdi = &t->fdx; |
1111 | read_fdi->fh = read_fh; | ||
1112 | read_fdi->et = GNUNET_SCHEDULER_ET_IN; | ||
1113 | } | ||
1114 | else if (NULL != write_fh) | ||
1115 | { | ||
1116 | struct GNUNET_SCHEDULER_FdInfo *write_fdi = &t->fdx; | ||
1117 | write_fdi->fh = write_fh; | ||
1118 | write_fdi->et = GNUNET_SCHEDULER_ET_OUT; | ||
1075 | } | 1119 | } |
1076 | } | 1120 | } |
1077 | 1121 | ||
@@ -1080,7 +1124,7 @@ GNUNET_SCHEDULER_cancel (struct GNUNET_SCHEDULER_Task *task) | |||
1080 | { | 1124 | { |
1081 | enum GNUNET_SCHEDULER_Priority p; | 1125 | enum GNUNET_SCHEDULER_Priority p; |
1082 | void *ret; | 1126 | void *ret; |
1083 | GNUNET_SCHEDULER_FdInfo *fdi; | 1127 | struct GNUNET_SCHEDULER_FdInfo *fdi; |
1084 | 1128 | ||
1085 | GNUNET_assert ( (NULL != active_task) || | 1129 | GNUNET_assert ( (NULL != active_task) || |
1086 | (GNUNET_NO == task->lifeness) ); | 1130 | (GNUNET_NO == task->lifeness) ); |
@@ -1480,9 +1524,13 @@ GNUNET_SCHEDULER_add_now_with_lifeness (int lifeness, | |||
1480 | #ifndef MINGW | 1524 | #ifndef MINGW |
1481 | static struct GNUNET_SCHEDULER_Task * | 1525 | static struct GNUNET_SCHEDULER_Task * |
1482 | add_without_sets (struct GNUNET_TIME_Relative delay, | 1526 | add_without_sets (struct GNUNET_TIME_Relative delay, |
1483 | enum GNUNET_SCHEDULER_Priority priority, | 1527 | enum GNUNET_SCHEDULER_Priority priority, |
1484 | int rfd, | 1528 | struct GNUNET_NETWORK_Handle *read_nh, |
1485 | int wfd, | 1529 | struct GNUNET_NETWORK_Handle *write_nh, |
1530 | struct GNUNET_DISK_FileHandle *read_fh, | ||
1531 | struct GNUNET_DISK_FileHandle *write_fh, | ||
1532 | //int rfd, | ||
1533 | //int wfd, | ||
1486 | GNUNET_SCHEDULER_TaskCallback task, | 1534 | GNUNET_SCHEDULER_TaskCallback task, |
1487 | void *task_cls) | 1535 | void *task_cls) |
1488 | { | 1536 | { |
@@ -1530,12 +1578,17 @@ add_without_sets (struct GNUNET_TIME_Relative delay, | |||
1530 | t->timeout = GNUNET_TIME_relative_to_absolute (delay); | 1578 | t->timeout = GNUNET_TIME_relative_to_absolute (delay); |
1531 | t->priority = check_priority ((priority == GNUNET_SCHEDULER_PRIORITY_KEEP) ? current_priority : priority); | 1579 | t->priority = check_priority ((priority == GNUNET_SCHEDULER_PRIORITY_KEEP) ? current_priority : priority); |
1532 | t->lifeness = current_lifeness; | 1580 | t->lifeness = current_lifeness; |
1533 | /*GNUNET_CONTAINER_DLL_insert (pending_head, | 1581 | //GNUNET_CONTAINER_DLL_insert (pending_head, |
1534 | pending_tail, | 1582 | // pending_tail, |
1535 | t);*/ | 1583 | // t); |
1536 | fdi = GNUNET_new (struct GNUNET_SCHEDULER_FdInfo); | 1584 | //fdi = GNUNET_new (struct GNUNET_SCHEDULER_FdInfo); |
1537 | initFdInfo(fdi, t); | 1585 | //initFdInfo(fdi, t); |
1586 | //scheduler_driver->add(scheduler_driver->cls, t , fdi); | ||
1587 | //initFdInfo (&t->fdx, read_nh, write_nh, read_fh, write_fh) | ||
1588 | initFdInfo (t, read_nh, write_nh, read_fh, write_fh); | ||
1589 | // FIXME: call add for each fdi if t->fds is a list | ||
1538 | scheduler_driver->add(scheduler_driver->cls, t , fdi); | 1590 | scheduler_driver->add(scheduler_driver->cls, t , fdi); |
1591 | |||
1539 | max_priority_added = GNUNET_MAX (max_priority_added, | 1592 | max_priority_added = GNUNET_MAX (max_priority_added, |
1540 | t->priority); | 1593 | t->priority); |
1541 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1594 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
@@ -1673,10 +1726,13 @@ GNUNET_SCHEDULER_add_net_with_priority (struct GNUNET_TIME_Relative delay, | |||
1673 | GNUNET_NETWORK_fdset_destroy (s); | 1726 | GNUNET_NETWORK_fdset_destroy (s); |
1674 | return ret; | 1727 | return ret; |
1675 | #else | 1728 | #else |
1729 | GNUNET_assert (on_read || on_write); | ||
1676 | GNUNET_assert (GNUNET_NETWORK_get_fd (fd) >= 0); | 1730 | GNUNET_assert (GNUNET_NETWORK_get_fd (fd) >= 0); |
1677 | return add_without_sets (delay, priority, | 1731 | return add_without_sets (delay, priority, |
1678 | on_read ? GNUNET_NETWORK_get_fd (fd) : -1, | 1732 | on_read ? fd : NULL, |
1679 | on_write ? GNUNET_NETWORK_get_fd (fd) : -1, | 1733 | on_write ? fd : NULL, |
1734 | NULL, | ||
1735 | NULL, | ||
1680 | task, task_cls); | 1736 | task, task_cls); |
1681 | #endif | 1737 | #endif |
1682 | } | 1738 | } |
@@ -1773,15 +1829,14 @@ GNUNET_SCHEDULER_add_file_with_priority (struct GNUNET_TIME_Relative delay, | |||
1773 | GNUNET_NETWORK_fdset_destroy (s); | 1829 | GNUNET_NETWORK_fdset_destroy (s); |
1774 | return ret; | 1830 | return ret; |
1775 | #else | 1831 | #else |
1776 | int real_fd; | 1832 | GNUNET_assert (on_read || on_write); |
1777 | 1833 | GNUNET_assert(fd->fd >= 0); | |
1778 | GNUNET_DISK_internal_file_handle_ (fd, &real_fd, sizeof (int)); | 1834 | return add_without_sets (delay, priority, |
1779 | GNUNET_assert (real_fd >= 0); | 1835 | NULL, |
1780 | return add_without_sets ( | 1836 | NULL, |
1781 | delay, priority, | 1837 | on_read ? fd : NULL, |
1782 | on_read ? real_fd : -1, | 1838 | on_write ? fd : NULL, |
1783 | on_write ? real_fd : -1, | 1839 | task, task_cls); |
1784 | task, task_cls); | ||
1785 | #endif | 1840 | #endif |
1786 | } | 1841 | } |
1787 | 1842 | ||