diff options
author | lurchi <lurchi@strangeplace.net> | 2018-01-10 17:19:44 +0100 |
---|---|---|
committer | lurchi <lurchi@strangeplace.net> | 2018-01-10 17:19:44 +0100 |
commit | c66e64df31713e5e97297300ec8b39536da1369b (patch) | |
tree | 6e0c3e8e82ab17352c20366fef39f0c45f37253f /src/util/scheduler.c | |
parent | 16f04cf4fb1a7b489b3672d19818ffd1fd8d57f1 (diff) | |
download | gnunet-c66e64df31713e5e97297300ec8b39536da1369b.tar.gz gnunet-c66e64df31713e5e97297300ec8b39536da1369b.zip |
properly detect calling add_select without descriptors; simplify extract_handles
Diffstat (limited to 'src/util/scheduler.c')
-rw-r--r-- | src/util/scheduler.c | 41 |
1 files changed, 21 insertions, 20 deletions
diff --git a/src/util/scheduler.c b/src/util/scheduler.c index c2061b50f..df43fdbee 100644 --- a/src/util/scheduler.c +++ b/src/util/scheduler.c | |||
@@ -1659,8 +1659,7 @@ GNUNET_SCHEDULER_add_file_with_priority (struct GNUNET_TIME_Relative delay, | |||
1659 | 1659 | ||
1660 | 1660 | ||
1661 | void | 1661 | void |
1662 | extract_handles (struct GNUNET_SCHEDULER_Task *t, | 1662 | extract_handles (const struct GNUNET_NETWORK_FDSet *fdset, |
1663 | const struct GNUNET_NETWORK_FDSet *fdset, | ||
1664 | const struct GNUNET_NETWORK_Handle ***ntarget, | 1663 | const struct GNUNET_NETWORK_Handle ***ntarget, |
1665 | unsigned int *extracted_nhandles, | 1664 | unsigned int *extracted_nhandles, |
1666 | const struct GNUNET_DISK_FileHandle ***ftarget, | 1665 | const struct GNUNET_DISK_FileHandle ***ftarget, |
@@ -1673,7 +1672,6 @@ extract_handles (struct GNUNET_SCHEDULER_Task *t, | |||
1673 | unsigned int nhandles_len; | 1672 | unsigned int nhandles_len; |
1674 | unsigned int fhandles_len; | 1673 | unsigned int fhandles_len; |
1675 | 1674 | ||
1676 | (void) t; | ||
1677 | nhandles = NULL; | 1675 | nhandles = NULL; |
1678 | fhandles = NULL; | 1676 | fhandles = NULL; |
1679 | nhandles_len = 0; | 1677 | nhandles_len = 0; |
@@ -1754,11 +1752,16 @@ GNUNET_SCHEDULER_add_select (enum GNUNET_SCHEDULER_Priority prio, | |||
1754 | const struct GNUNET_DISK_FileHandle **write_fhandles; | 1752 | const struct GNUNET_DISK_FileHandle **write_fhandles; |
1755 | unsigned int read_nhandles_len, write_nhandles_len, | 1753 | unsigned int read_nhandles_len, write_nhandles_len, |
1756 | read_fhandles_len, write_fhandles_len; | 1754 | read_fhandles_len, write_fhandles_len; |
1757 | int no_fdsets = (NULL == rs) && (NULL == ws); | 1755 | |
1758 | int no_socket_descriptors = | 1756 | int no_rs = (NULL == rs); |
1759 | ((NULL != rs) && (0 == rs->nsds)) && ((NULL != ws) && (0 == ws->nsds)); | 1757 | int no_ws = (NULL == ws); |
1760 | 1758 | int empty_rs = (NULL != rs) && (0 == rs->nsds); | |
1761 | if (no_fdsets || no_socket_descriptors) | 1759 | int empty_ws = (NULL != ws) && (0 == ws->nsds); |
1760 | int no_socket_descriptors = (no_rs && no_ws) || | ||
1761 | (empty_rs && empty_ws) || | ||
1762 | (no_rs && empty_ws) || | ||
1763 | (no_ws && empty_rs); | ||
1764 | if (no_socket_descriptors) | ||
1762 | return GNUNET_SCHEDULER_add_delayed_with_priority (delay, | 1765 | return GNUNET_SCHEDULER_add_delayed_with_priority (delay, |
1763 | prio, | 1766 | prio, |
1764 | task, | 1767 | task, |
@@ -1767,12 +1770,6 @@ GNUNET_SCHEDULER_add_select (enum GNUNET_SCHEDULER_Priority prio, | |||
1767 | GNUNET_assert (NULL != scheduler_driver); | 1770 | GNUNET_assert (NULL != scheduler_driver); |
1768 | GNUNET_assert (NULL != active_task); | 1771 | GNUNET_assert (NULL != active_task); |
1769 | GNUNET_assert (NULL != task); | 1772 | GNUNET_assert (NULL != task); |
1770 | t = GNUNET_new (struct GNUNET_SCHEDULER_Task); | ||
1771 | t->callback = task; | ||
1772 | t->callback_cls = task_cls; | ||
1773 | t->read_fd = -1; | ||
1774 | t->write_fd = -1; | ||
1775 | t->own_handles = GNUNET_YES; | ||
1776 | read_nhandles = NULL; | 1773 | read_nhandles = NULL; |
1777 | write_nhandles = NULL; | 1774 | write_nhandles = NULL; |
1778 | read_fhandles = NULL; | 1775 | read_fhandles = NULL; |
@@ -1783,8 +1780,7 @@ GNUNET_SCHEDULER_add_select (enum GNUNET_SCHEDULER_Priority prio, | |||
1783 | write_fhandles_len = 0; | 1780 | write_fhandles_len = 0; |
1784 | if (NULL != rs) | 1781 | if (NULL != rs) |
1785 | { | 1782 | { |
1786 | extract_handles (t, | 1783 | extract_handles (rs, |
1787 | rs, | ||
1788 | &read_nhandles, | 1784 | &read_nhandles, |
1789 | &read_nhandles_len, | 1785 | &read_nhandles_len, |
1790 | &read_fhandles, | 1786 | &read_fhandles, |
@@ -1792,13 +1788,17 @@ GNUNET_SCHEDULER_add_select (enum GNUNET_SCHEDULER_Priority prio, | |||
1792 | } | 1788 | } |
1793 | if (NULL != ws) | 1789 | if (NULL != ws) |
1794 | { | 1790 | { |
1795 | extract_handles (t, | 1791 | extract_handles (ws, |
1796 | ws, | ||
1797 | &write_nhandles, | 1792 | &write_nhandles, |
1798 | &write_nhandles_len, | 1793 | &write_nhandles_len, |
1799 | &write_fhandles, | 1794 | &write_fhandles, |
1800 | &write_fhandles_len); | 1795 | &write_fhandles_len); |
1801 | } | 1796 | } |
1797 | GNUNET_assert ((read_nhandles > 0) || | ||
1798 | (read_fhandles > 0) || | ||
1799 | (write_nhandles > 0) || | ||
1800 | (write_fhandles > 0)); | ||
1801 | t = GNUNET_new (struct GNUNET_SCHEDULER_Task); | ||
1802 | init_fd_info (t, | 1802 | init_fd_info (t, |
1803 | read_nhandles, | 1803 | read_nhandles, |
1804 | read_nhandles_len, | 1804 | read_nhandles_len, |
@@ -1808,6 +1808,9 @@ GNUNET_SCHEDULER_add_select (enum GNUNET_SCHEDULER_Priority prio, | |||
1808 | read_fhandles_len, | 1808 | read_fhandles_len, |
1809 | write_fhandles, | 1809 | write_fhandles, |
1810 | write_fhandles_len); | 1810 | write_fhandles_len); |
1811 | t->callback = task; | ||
1812 | t->callback_cls = task_cls; | ||
1813 | t->own_handles = GNUNET_YES; | ||
1811 | /* free the arrays of pointers to network / file handles, the actual | 1814 | /* free the arrays of pointers to network / file handles, the actual |
1812 | * handles will be freed in destroy_task */ | 1815 | * handles will be freed in destroy_task */ |
1813 | GNUNET_array_grow (read_nhandles, read_nhandles_len, 0); | 1816 | GNUNET_array_grow (read_nhandles, read_nhandles_len, 0); |
@@ -2187,8 +2190,6 @@ select_del (void *cls, | |||
2187 | context = cls; | 2190 | context = cls; |
2188 | ret = GNUNET_SYSERR; | 2191 | ret = GNUNET_SYSERR; |
2189 | pos = context->scheduled_head; | 2192 | pos = context->scheduled_head; |
2190 | if (0 == task->fds_len) | ||
2191 | return GNUNET_OK; | ||
2192 | while (NULL != pos) | 2193 | while (NULL != pos) |
2193 | { | 2194 | { |
2194 | struct Scheduled *next = pos->next; | 2195 | struct Scheduled *next = pos->next; |