diff options
author | LRN <lrn1986@gmail.com> | 2015-01-24 23:01:25 +0000 |
---|---|---|
committer | LRN <lrn1986@gmail.com> | 2015-01-24 23:01:25 +0000 |
commit | b321893de2f2dddd32a3fe2d727593c71a4875f3 (patch) | |
tree | bd285454e16804efcbfc43998bf29dc8e709d380 /src/util/network.c | |
parent | a1193adca1ddba0f6ac1c58154ae8377225063a3 (diff) | |
download | gnunet-b321893de2f2dddd32a3fe2d727593c71a4875f3.tar.gz gnunet-b321893de2f2dddd32a3fe2d727593c71a4875f3.zip |
Add GNUNET_NETWORK_fdset_handle_set_first
Diffstat (limited to 'src/util/network.c')
-rw-r--r-- | src/util/network.c | 50 |
1 files changed, 44 insertions, 6 deletions
diff --git a/src/util/network.c b/src/util/network.c index c2ba51d94..26a803cde 100644 --- a/src/util/network.c +++ b/src/util/network.c | |||
@@ -1273,6 +1273,34 @@ GNUNET_NETWORK_fdset_handle_set (struct GNUNET_NETWORK_FDSet *fds, | |||
1273 | 1273 | ||
1274 | 1274 | ||
1275 | /** | 1275 | /** |
1276 | * Add a file handle to the fd set | ||
1277 | * @param fds fd set | ||
1278 | * @param h the file handle to add | ||
1279 | */ | ||
1280 | void | ||
1281 | GNUNET_NETWORK_fdset_handle_set_first (struct GNUNET_NETWORK_FDSet *fds, | ||
1282 | const struct GNUNET_DISK_FileHandle *h) | ||
1283 | { | ||
1284 | #ifdef MINGW | ||
1285 | if (fds->handles_pos == fds->handles_size) | ||
1286 | GNUNET_array_grow (fds->handles, | ||
1287 | fds->handles_size, | ||
1288 | fds->handles_size * 2 + 2); | ||
1289 | fds->handles[fds->handles_pos++] = h; | ||
1290 | if (fds->handles[0] != h) | ||
1291 | { | ||
1292 | const struct GNUNET_DISK_FileHandle *bak = fds->handles[0]; | ||
1293 | fds->handles[0] = h; | ||
1294 | fds->handles[fds->handles_pos] = bak; | ||
1295 | } | ||
1296 | fds->handles_pos++; | ||
1297 | #else | ||
1298 | GNUNET_NETWORK_fdset_handle_set (fds, h); | ||
1299 | #endif | ||
1300 | } | ||
1301 | |||
1302 | |||
1303 | /** | ||
1276 | * Check if a file handle is part of an fd set | 1304 | * Check if a file handle is part of an fd set |
1277 | * | 1305 | * |
1278 | * @param fds fd set | 1306 | * @param fds fd set |
@@ -1717,10 +1745,14 @@ pipe_except_ready (struct GNUNET_DISK_FileHandle *fh) | |||
1717 | * @param except GNUNET_NO if fds should be checked for readiness to read, | 1745 | * @param except GNUNET_NO if fds should be checked for readiness to read, |
1718 | * GNUNET_YES if fds should be checked for exceptions | 1746 | * GNUNET_YES if fds should be checked for exceptions |
1719 | * (there is no way to check for write-readiness - pipes are always write-ready) | 1747 | * (there is no way to check for write-readiness - pipes are always write-ready) |
1748 | * @param set_for_sure a HANDLE that is known to be set already, | ||
1749 | * because WaitForMultipleObjects() returned its index. | ||
1720 | * @return number of ready handles | 1750 | * @return number of ready handles |
1721 | */ | 1751 | */ |
1722 | static int | 1752 | static int |
1723 | check_handles_status (struct GNUNET_NETWORK_FDSet *fds, int except) | 1753 | check_handles_status (struct GNUNET_NETWORK_FDSet *fds, |
1754 | int except, | ||
1755 | HANDLE set_for_sure) | ||
1724 | { | 1756 | { |
1725 | struct GNUNET_DISK_FileHandle *fh; | 1757 | struct GNUNET_DISK_FileHandle *fh; |
1726 | unsigned int roff; | 1758 | unsigned int roff; |
@@ -1729,7 +1761,11 @@ check_handles_status (struct GNUNET_NETWORK_FDSet *fds, int except) | |||
1729 | for (woff = 0, roff = 0; roff < fds->handles_pos; roff++) | 1761 | for (woff = 0, roff = 0; roff < fds->handles_pos; roff++) |
1730 | { | 1762 | { |
1731 | fh = fds->handles[roff]; | 1763 | fh = fds->handles[roff]; |
1732 | if (fh->type == GNUNET_DISK_HANLDE_TYPE_PIPE) | 1764 | if (fh == set_for_sure) |
1765 | { | ||
1766 | fds->handles[woff++] = fh; | ||
1767 | } | ||
1768 | else if (fh->type == GNUNET_DISK_HANLDE_TYPE_PIPE) | ||
1733 | { | 1769 | { |
1734 | if ((except && pipe_except_ready (fh)) || | 1770 | if ((except && pipe_except_ready (fh)) || |
1735 | (!except && pipe_read_ready (fh))) | 1771 | (!except && pipe_read_ready (fh))) |
@@ -1899,14 +1935,14 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds, | |||
1899 | 1935 | ||
1900 | /* Read Pipes */ | 1936 | /* Read Pipes */ |
1901 | if (rfds && (rfds->handles_pos > 0)) | 1937 | if (rfds && (rfds->handles_pos > 0)) |
1902 | retcode += check_handles_status (rfds, GNUNET_NO); | 1938 | retcode += check_handles_status (rfds, GNUNET_NO, NULL); |
1903 | 1939 | ||
1904 | /* wfds handles remain untouched, on W32 | 1940 | /* wfds handles remain untouched, on W32 |
1905 | we pretend our pipes are "always" write-ready */ | 1941 | we pretend our pipes are "always" write-ready */ |
1906 | 1942 | ||
1907 | /* except pipes */ | 1943 | /* except pipes */ |
1908 | if (efds && (efds->handles_pos > 0)) | 1944 | if (efds && (efds->handles_pos > 0)) |
1909 | retcode += check_handles_status (efds, GNUNET_YES); | 1945 | retcode += check_handles_status (efds, GNUNET_YES, NULL); |
1910 | 1946 | ||
1911 | if (rfds) | 1947 | if (rfds) |
1912 | { | 1948 | { |
@@ -2131,7 +2167,7 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds, | |||
2131 | 2167 | ||
2132 | /* We may have some pipes ready for reading. */ | 2168 | /* We may have some pipes ready for reading. */ |
2133 | if (returnedpos < read_pipes_off) | 2169 | if (returnedpos < read_pipes_off) |
2134 | retcode += check_handles_status (rfds, GNUNET_NO); | 2170 | retcode += check_handles_status (rfds, GNUNET_NO, handle_array[returnedpos]); |
2135 | else | 2171 | else |
2136 | rfds->handles_pos = 0; | 2172 | rfds->handles_pos = 0; |
2137 | 2173 | ||
@@ -2147,7 +2183,9 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds, | |||
2147 | } | 2183 | } |
2148 | if (efds) | 2184 | if (efds) |
2149 | { | 2185 | { |
2150 | retcode += check_handles_status (rfds, GNUNET_YES); | 2186 | retcode += check_handles_status (rfds, |
2187 | GNUNET_YES, | ||
2188 | returnedpos < nhandles ? handle_array[returnedpos] : NULL); | ||
2151 | if (-1 != sp.status) | 2189 | if (-1 != sp.status) |
2152 | GNUNET_NETWORK_fdset_copy_native (efds, &aexcept, retcode); | 2190 | GNUNET_NETWORK_fdset_copy_native (efds, &aexcept, retcode); |
2153 | } | 2191 | } |