diff options
author | Ron Yorston <rmy@pobox.com> | 2023-03-03 11:32:44 +0000 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2023-03-03 12:21:51 +0000 |
commit | 1036069556897964766dfdf22cda1dd11d891cdf (patch) | |
tree | f13ed04a7e86d811e6223d1bc2ecaefbb5c9856f | |
parent | 0678b843f10191abadc5f47cef9a8ab6a29b7326 (diff) | |
download | busybox-w32-1036069556897964766dfdf22cda1dd11d891cdf.tar.gz busybox-w32-1036069556897964766dfdf22cda1dd11d891cdf.tar.bz2 busybox-w32-1036069556897964766dfdf22cda1dd11d891cdf.zip |
nc: switch to using poll(2)
Upstream started using poll(2) rather than select(2) in `nc` some
time ago, in commit 5b3b468ec (nc: use poll() instead of select()).
Now that poll(2) in busybox-w32 has been updated to work with `nc`
switch to using the same code as upstream.
As a result of this change nothing in busybox-w32 now uses the
select(2) implementation. This reduces the size of the binaries
by about 3.4KB.
-rw-r--r-- | networking/nc.c | 51 |
1 files changed, 2 insertions, 49 deletions
diff --git a/networking/nc.c b/networking/nc.c index d039e2055..ee008595d 100644 --- a/networking/nc.c +++ b/networking/nc.c | |||
@@ -30,7 +30,7 @@ | |||
30 | //config:config NC_EXTRA | 30 | //config:config NC_EXTRA |
31 | //config: bool "Netcat extensions (-eiw and -f FILE)" | 31 | //config: bool "Netcat extensions (-eiw and -f FILE)" |
32 | //config: default y | 32 | //config: default y |
33 | //config: depends on NC || NETCAT | 33 | //config: depends on (NC || NETCAT) && PLATFORM_POSIX |
34 | //config: help | 34 | //config: help |
35 | //config: Add -e (support for executing the rest of the command line after | 35 | //config: Add -e (support for executing the rest of the command line after |
36 | //config: making or receiving a successful connection), -i (delay interval for | 36 | //config: making or receiving a successful connection), -i (delay interval for |
@@ -127,13 +127,11 @@ int nc_main(int argc, char **argv) | |||
127 | IF_NOT_NC_SERVER(const) unsigned do_listen = 0; | 127 | IF_NOT_NC_SERVER(const) unsigned do_listen = 0; |
128 | #if !ENABLE_PLATFORM_MINGW32 | 128 | #if !ENABLE_PLATFORM_MINGW32 |
129 | IF_NOT_NC_EXTRA (const) unsigned wsecs = 0; | 129 | IF_NOT_NC_EXTRA (const) unsigned wsecs = 0; |
130 | #endif | ||
130 | IF_NOT_NC_EXTRA (const) unsigned delay = 0; | 131 | IF_NOT_NC_EXTRA (const) unsigned delay = 0; |
131 | IF_NOT_NC_EXTRA (const int execparam = 0;) | 132 | IF_NOT_NC_EXTRA (const int execparam = 0;) |
132 | IF_NC_EXTRA (char **execparam = NULL;) | 133 | IF_NC_EXTRA (char **execparam = NULL;) |
133 | struct pollfd pfds[2]; | 134 | struct pollfd pfds[2]; |
134 | #else | ||
135 | fd_set readfds, testfds; | ||
136 | #endif | ||
137 | int opt; /* must be signed (getopt returns -1) */ | 135 | int opt; /* must be signed (getopt returns -1) */ |
138 | 136 | ||
139 | if (ENABLE_NC_SERVER || ENABLE_NC_EXTRA) { | 137 | if (ENABLE_NC_SERVER || ENABLE_NC_EXTRA) { |
@@ -220,9 +218,7 @@ int nc_main(int argc, char **argv) | |||
220 | cfd = accept(sfd, NULL, 0); | 218 | cfd = accept(sfd, NULL, 0); |
221 | if (cfd < 0) | 219 | if (cfd < 0) |
222 | bb_simple_perror_msg_and_die("accept"); | 220 | bb_simple_perror_msg_and_die("accept"); |
223 | #if !ENABLE_PLATFORM_MINGW32 | ||
224 | if (!execparam) | 221 | if (!execparam) |
225 | #endif | ||
226 | close(sfd); | 222 | close(sfd); |
227 | } else { | 223 | } else { |
228 | cfd = create_and_connect_stream_or_die(argv[0], | 224 | cfd = create_and_connect_stream_or_die(argv[0], |
@@ -259,20 +255,13 @@ int nc_main(int argc, char **argv) | |||
259 | 255 | ||
260 | /* loop copying stdin to cfd, and cfd to stdout */ | 256 | /* loop copying stdin to cfd, and cfd to stdout */ |
261 | 257 | ||
262 | #if !ENABLE_PLATFORM_MINGW32 | ||
263 | pfds[0].fd = STDIN_FILENO; | 258 | pfds[0].fd = STDIN_FILENO; |
264 | pfds[0].events = POLLIN; | 259 | pfds[0].events = POLLIN; |
265 | pfds[1].fd = cfd; | 260 | pfds[1].fd = cfd; |
266 | pfds[1].events = POLLIN; | 261 | pfds[1].events = POLLIN; |
267 | #else | ||
268 | FD_ZERO(&readfds); | ||
269 | FD_SET(cfd, &readfds); | ||
270 | FD_SET(STDIN_FILENO, &readfds); | ||
271 | #endif | ||
272 | 262 | ||
273 | #define iobuf bb_common_bufsiz1 | 263 | #define iobuf bb_common_bufsiz1 |
274 | setup_common_bufsiz(); | 264 | setup_common_bufsiz(); |
275 | #if !ENABLE_PLATFORM_MINGW32 | ||
276 | for (;;) { | 265 | for (;;) { |
277 | int fdidx; | 266 | int fdidx; |
278 | int ofd; | 267 | int ofd; |
@@ -307,41 +296,5 @@ int nc_main(int argc, char **argv) | |||
307 | fdidx++; | 296 | fdidx++; |
308 | } | 297 | } |
309 | } | 298 | } |
310 | #else | ||
311 | for (;;) { | ||
312 | int fd; | ||
313 | int ofd; | ||
314 | int nread; | ||
315 | |||
316 | testfds = readfds; | ||
317 | |||
318 | if (select(cfd + 1, &testfds, NULL, NULL, NULL) < 0) | ||
319 | bb_simple_perror_msg_and_die("select"); | ||
320 | |||
321 | fd = STDIN_FILENO; | ||
322 | while (1) { | ||
323 | if (FD_ISSET(fd, &testfds)) { | ||
324 | nread = safe_read(fd, iobuf, COMMON_BUFSIZE); | ||
325 | if (fd == cfd) { | ||
326 | if (nread < 1) | ||
327 | exit_SUCCESS(); | ||
328 | ofd = STDOUT_FILENO; | ||
329 | } else { | ||
330 | if (nread < 1) { | ||
331 | /* Close outgoing half-connection so they get EOF, | ||
332 | * but leave incoming alone so we can see response */ | ||
333 | shutdown(cfd, SHUT_WR); | ||
334 | FD_CLR(STDIN_FILENO, &readfds); | ||
335 | } | ||
336 | ofd = cfd; | ||
337 | } | ||
338 | xwrite(ofd, iobuf, nread); | ||
339 | } | ||
340 | if (fd == cfd) | ||
341 | break; | ||
342 | fd = cfd; | ||
343 | } | ||
344 | } | ||
345 | #endif | ||
346 | } | 299 | } |
347 | #endif | 300 | #endif |