aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--networking/nc.c17
1 files changed, 6 insertions, 11 deletions
diff --git a/networking/nc.c b/networking/nc.c
index 1babe3bb7..fe845f582 100644
--- a/networking/nc.c
+++ b/networking/nc.c
@@ -172,12 +172,11 @@ int nc_main(int argc, char **argv)
172 172
173 testfds = readfds; 173 testfds = readfds;
174 174
175 if (select(cfd + 1, &testfds, NULL, NULL, NULL) < 0) 175 if (select(FD_SETSIZE, &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 fd = STDIN_FILENO; 179 for (fd = 0; fd < FD_SETSIZE; fd++) {
180 while (1) {
181 if (FD_ISSET(fd, &testfds)) { 180 if (FD_ISSET(fd, &testfds)) {
182 nread = safe_read(fd, iobuf, sizeof(iobuf)); 181 nread = safe_read(fd, iobuf, sizeof(iobuf));
183 if (fd == cfd) { 182 if (fd == cfd) {
@@ -185,21 +184,17 @@ int nc_main(int argc, char **argv)
185 exit(EXIT_SUCCESS); 184 exit(EXIT_SUCCESS);
186 ofd = STDOUT_FILENO; 185 ofd = STDOUT_FILENO;
187 } else { 186 } else {
188 if (nread < 1) { 187 if (nread<1) {
189 /* Close outgoing half-connection so they get EOF, 188 // Close outgoing half-connection so they get EOF, but
190 * but leave incoming alone so we can see response */ 189 // leave incoming alone so we can see response.
191 shutdown(cfd, 1); 190 shutdown(cfd, 1);
192 FD_CLR(STDIN_FILENO, &readfds); 191 FD_CLR(STDIN_FILENO, &readfds);
193 } 192 }
194 ofd = cfd; 193 ofd = cfd;
195 } 194 }
196 xwrite(ofd, iobuf, nread); 195 xwrite(ofd, iobuf, nread);
197 if (delay > 0) 196 if (delay > 0) sleep(delay);
198 sleep(delay);
199 } 197 }
200 if (fd == cfd)
201 break;
202 fd = cfd;
203 } 198 }
204 } 199 }
205} 200}