diff options
author | Tomoya Adachi <adachi@il.is.s.u-tokyo.ac.jp> | 2009-08-03 02:45:24 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2009-08-03 02:45:24 +0200 |
commit | 471ca65091b4366b6b496aeda1c80d01078c8333 (patch) | |
tree | c7fb9ad5406cd26d8d7eb060ecd3f7be6787209a | |
parent | 1e32f91e3b953ebf614e428abc8c61e7d00ee70f (diff) | |
download | busybox-w32-471ca65091b4366b6b496aeda1c80d01078c8333.tar.gz busybox-w32-471ca65091b4366b6b496aeda1c80d01078c8333.tar.bz2 busybox-w32-471ca65091b4366b6b496aeda1c80d01078c8333.zip |
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>
-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 fe845f582..1babe3bb7 100644 --- a/networking/nc.c +++ b/networking/nc.c | |||
@@ -172,11 +172,12 @@ int nc_main(int argc, char **argv) | |||
172 | 172 | ||
173 | testfds = readfds; | 173 | testfds = readfds; |
174 | 174 | ||
175 | if (select(FD_SETSIZE, &testfds, NULL, NULL, NULL) < 0) | 175 | if (select(cfd + 1, &testfds, NULL, NULL, NULL) < 0) |
176 | bb_perror_msg_and_die("select"); | 176 | bb_perror_msg_and_die("select"); |
177 | 177 | ||
178 | #define iobuf bb_common_bufsiz1 | 178 | #define iobuf bb_common_bufsiz1 |
179 | for (fd = 0; fd < FD_SETSIZE; fd++) { | 179 | fd = STDIN_FILENO; |
180 | while (1) { | ||
180 | if (FD_ISSET(fd, &testfds)) { | 181 | if (FD_ISSET(fd, &testfds)) { |
181 | nread = safe_read(fd, iobuf, sizeof(iobuf)); | 182 | nread = safe_read(fd, iobuf, sizeof(iobuf)); |
182 | if (fd == cfd) { | 183 | if (fd == cfd) { |
@@ -184,17 +185,21 @@ int nc_main(int argc, char **argv) | |||
184 | exit(EXIT_SUCCESS); | 185 | exit(EXIT_SUCCESS); |
185 | ofd = STDOUT_FILENO; | 186 | ofd = STDOUT_FILENO; |
186 | } else { | 187 | } else { |
187 | if (nread<1) { | 188 | if (nread < 1) { |
188 | // Close outgoing half-connection so they get EOF, but | 189 | /* Close outgoing half-connection so they get EOF, |
189 | // leave incoming alone so we can see response. | 190 | * but leave incoming alone so we can see response */ |
190 | shutdown(cfd, 1); | 191 | shutdown(cfd, 1); |
191 | FD_CLR(STDIN_FILENO, &readfds); | 192 | FD_CLR(STDIN_FILENO, &readfds); |
192 | } | 193 | } |
193 | ofd = cfd; | 194 | ofd = cfd; |
194 | } | 195 | } |
195 | xwrite(ofd, iobuf, nread); | 196 | xwrite(ofd, iobuf, nread); |
196 | if (delay > 0) sleep(delay); | 197 | if (delay > 0) |
198 | sleep(delay); | ||
197 | } | 199 | } |
200 | if (fd == cfd) | ||
201 | break; | ||
202 | fd = cfd; | ||
198 | } | 203 | } |
199 | } | 204 | } |
200 | } | 205 | } |