aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--networking/nc.c17
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}