diff options
author | Tomoya Adachi | 2009-08-03 02:45:24 +0200 |
---|---|---|
committer | Denys Vlasenko | 2009-08-03 02:45:24 +0200 |
commit | 471ca65091b4366b6b496aeda1c80d01078c8333 (patch) | |
tree | c7fb9ad5406cd26d8d7eb060ecd3f7be6787209a /networking | |
parent | 1e32f91e3b953ebf614e428abc8c61e7d00ee70f (diff) | |
download | busybox-471ca65091b4366b6b496aeda1c80d01078c8333.zip busybox-471ca65091b4366b6b496aeda1c80d01078c8333.tar.gz |
nc: fix nc -ll; report vfork errors; make select loop faster
function old new delta
nc_main 933 946 +13
Signed-off-by: Tomoya Adachi <adachi@il.is.s.u-tokyo.ac.jp>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'networking')
-rw-r--r-- | networking/nc.c | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/networking/nc.c b/networking/nc.c index fe845f5..1babe3b 100644 --- a/networking/nc.c +++ b/networking/nc.c @@ -172,11 +172,12 @@ int nc_main(int argc, char **argv) testfds = readfds; - if (select(FD_SETSIZE, &testfds, NULL, NULL, NULL) < 0) + if (select(cfd + 1, &testfds, NULL, NULL, NULL) < 0) bb_perror_msg_and_die("select"); #define iobuf bb_common_bufsiz1 - for (fd = 0; fd < FD_SETSIZE; fd++) { + fd = STDIN_FILENO; + while (1) { if (FD_ISSET(fd, &testfds)) { nread = safe_read(fd, iobuf, sizeof(iobuf)); if (fd == cfd) { @@ -184,17 +185,21 @@ int nc_main(int argc, char **argv) exit(EXIT_SUCCESS); ofd = STDOUT_FILENO; } else { - if (nread<1) { - // Close outgoing half-connection so they get EOF, but - // leave incoming alone so we can see response. + if (nread < 1) { + /* Close outgoing half-connection so they get EOF, + * but leave incoming alone so we can see response */ shutdown(cfd, 1); FD_CLR(STDIN_FILENO, &readfds); } ofd = cfd; } xwrite(ofd, iobuf, nread); - if (delay > 0) sleep(delay); + if (delay > 0) + sleep(delay); } + if (fd == cfd) + break; + fd = cfd; } } } |