diff options
author | lurchi <lurchi@strangeplace.net> | 2018-01-10 23:14:55 +0100 |
---|---|---|
committer | lurchi <lurchi@strangeplace.net> | 2018-01-10 23:14:55 +0100 |
commit | 67bb148acd0de26403e4dd89659efeec8889a2c5 (patch) | |
tree | c050e53a906c8db43f6d038ad38ae9ecc90e322f /src/util/scheduler.c | |
parent | c9a693fc4221ddcec8c0582174ad87488ea64650 (diff) | |
download | gnunet-67bb148acd0de26403e4dd89659efeec8889a2c5.tar.gz gnunet-67bb148acd0de26403e4dd89659efeec8889a2c5.zip |
gracefully accept empty FD set that claim to contain FDs
Diffstat (limited to 'src/util/scheduler.c')
-rw-r--r-- | src/util/scheduler.c | 92 |
1 files changed, 48 insertions, 44 deletions
diff --git a/src/util/scheduler.c b/src/util/scheduler.c index df43fdbee..279a4ed02 100644 --- a/src/util/scheduler.c +++ b/src/util/scheduler.c | |||
@@ -1746,58 +1746,62 @@ GNUNET_SCHEDULER_add_select (enum GNUNET_SCHEDULER_Priority prio, | |||
1746 | void *task_cls) | 1746 | void *task_cls) |
1747 | { | 1747 | { |
1748 | struct GNUNET_SCHEDULER_Task *t; | 1748 | struct GNUNET_SCHEDULER_Task *t; |
1749 | const struct GNUNET_NETWORK_Handle **read_nhandles; | 1749 | const struct GNUNET_NETWORK_Handle **read_nhandles = NULL; |
1750 | const struct GNUNET_NETWORK_Handle **write_nhandles; | 1750 | const struct GNUNET_NETWORK_Handle **write_nhandles = NULL; |
1751 | const struct GNUNET_DISK_FileHandle **read_fhandles; | 1751 | const struct GNUNET_DISK_FileHandle **read_fhandles = NULL; |
1752 | const struct GNUNET_DISK_FileHandle **write_fhandles; | 1752 | const struct GNUNET_DISK_FileHandle **write_fhandles = NULL; |
1753 | unsigned int read_nhandles_len, write_nhandles_len, | 1753 | unsigned int read_nhandles_len = 0; |
1754 | read_fhandles_len, write_fhandles_len; | 1754 | unsigned int write_nhandles_len = 0; |
1755 | 1755 | unsigned int read_fhandles_len = 0; | |
1756 | unsigned int write_fhandles_len = 0; | ||
1757 | |||
1758 | /* scheduler must be running */ | ||
1759 | GNUNET_assert (NULL != scheduler_driver); | ||
1760 | GNUNET_assert (NULL != active_task); | ||
1761 | GNUNET_assert (NULL != task); | ||
1756 | int no_rs = (NULL == rs); | 1762 | int no_rs = (NULL == rs); |
1757 | int no_ws = (NULL == ws); | 1763 | int no_ws = (NULL == ws); |
1758 | int empty_rs = (NULL != rs) && (0 == rs->nsds); | 1764 | int empty_rs = (NULL != rs) && (0 == rs->nsds); |
1759 | int empty_ws = (NULL != ws) && (0 == ws->nsds); | 1765 | int empty_ws = (NULL != ws) && (0 == ws->nsds); |
1760 | int no_socket_descriptors = (no_rs && no_ws) || | 1766 | int no_fds = (no_rs && no_ws) || |
1761 | (empty_rs && empty_ws) || | 1767 | (empty_rs && empty_ws) || |
1762 | (no_rs && empty_ws) || | 1768 | (no_rs && empty_ws) || |
1763 | (no_ws && empty_rs); | 1769 | (no_ws && empty_rs); |
1764 | if (no_socket_descriptors) | 1770 | if (! no_fds) |
1771 | { | ||
1772 | if (NULL != rs) | ||
1773 | { | ||
1774 | extract_handles (rs, | ||
1775 | &read_nhandles, | ||
1776 | &read_nhandles_len, | ||
1777 | &read_fhandles, | ||
1778 | &read_fhandles_len); | ||
1779 | } | ||
1780 | if (NULL != ws) | ||
1781 | { | ||
1782 | extract_handles (ws, | ||
1783 | &write_nhandles, | ||
1784 | &write_nhandles_len, | ||
1785 | &write_fhandles, | ||
1786 | &write_fhandles_len); | ||
1787 | } | ||
1788 | } | ||
1789 | /** | ||
1790 | * here we consider the case that a GNUNET_NETWORK_FDSet might be empty | ||
1791 | * although its maximum FD number (nsds) is greater than 0. We handle | ||
1792 | * this case gracefully because some libraries such as libmicrohttpd | ||
1793 | * only provide a hint what the maximum FD number in an FD set might be | ||
1794 | * and not the exact FD number (see e.g. gnunet-rest-service.c) | ||
1795 | */ | ||
1796 | int no_fds_extracted = (0 == read_nhandles_len) && | ||
1797 | (0 == read_fhandles_len) && | ||
1798 | (0 == write_nhandles_len) && | ||
1799 | (0 == write_fhandles_len); | ||
1800 | if (no_fds || no_fds_extracted) | ||
1765 | return GNUNET_SCHEDULER_add_delayed_with_priority (delay, | 1801 | return GNUNET_SCHEDULER_add_delayed_with_priority (delay, |
1766 | prio, | 1802 | prio, |
1767 | task, | 1803 | task, |
1768 | task_cls); | 1804 | task_cls); |
1769 | /* scheduler must be running */ | ||
1770 | GNUNET_assert (NULL != scheduler_driver); | ||
1771 | GNUNET_assert (NULL != active_task); | ||
1772 | GNUNET_assert (NULL != task); | ||
1773 | read_nhandles = NULL; | ||
1774 | write_nhandles = NULL; | ||
1775 | read_fhandles = NULL; | ||
1776 | write_fhandles = NULL; | ||
1777 | read_nhandles_len = 0; | ||
1778 | write_nhandles_len = 0; | ||
1779 | read_fhandles_len = 0; | ||
1780 | write_fhandles_len = 0; | ||
1781 | if (NULL != rs) | ||
1782 | { | ||
1783 | extract_handles (rs, | ||
1784 | &read_nhandles, | ||
1785 | &read_nhandles_len, | ||
1786 | &read_fhandles, | ||
1787 | &read_fhandles_len); | ||
1788 | } | ||
1789 | if (NULL != ws) | ||
1790 | { | ||
1791 | extract_handles (ws, | ||
1792 | &write_nhandles, | ||
1793 | &write_nhandles_len, | ||
1794 | &write_fhandles, | ||
1795 | &write_fhandles_len); | ||
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); | 1805 | t = GNUNET_new (struct GNUNET_SCHEDULER_Task); |
1802 | init_fd_info (t, | 1806 | init_fd_info (t, |
1803 | read_nhandles, | 1807 | read_nhandles, |