aboutsummaryrefslogtreecommitdiff
path: root/networking
diff options
context:
space:
mode:
Diffstat (limited to 'networking')
-rw-r--r--networking/ftpgetput.c6
-rw-r--r--networking/nc.c33
-rw-r--r--networking/wget.c6
3 files changed, 29 insertions, 16 deletions
diff --git a/networking/ftpgetput.c b/networking/ftpgetput.c
index d70f4ca77..cb0a96b59 100644
--- a/networking/ftpgetput.c
+++ b/networking/ftpgetput.c
@@ -123,6 +123,9 @@ static int ftpcmd(const char *s1, const char *s2)
123 fprintf(control_stream, (s2 ? "%s %s\r\n" : "%s %s\r\n"+3), 123 fprintf(control_stream, (s2 ? "%s %s\r\n" : "%s %s\r\n"+3),
124 s1, s2); 124 s1, s2);
125 fflush(control_stream); 125 fflush(control_stream);
126#if ENABLE_PLATFORM_MINGW32
127 fseek(control_stream, 0L, SEEK_CUR);
128#endif
126 } 129 }
127 130
128 do { 131 do {
@@ -131,6 +134,9 @@ static int ftpcmd(const char *s1, const char *s2)
131 ftp_die(NULL); 134 ftp_die(NULL);
132 } 135 }
133 } while (!isdigit(buf[0]) || buf[3] != ' '); 136 } while (!isdigit(buf[0]) || buf[3] != ' ');
137#if ENABLE_PLATFORM_MINGW32
138 fseek(control_stream, 0L, SEEK_CUR);
139#endif
134 140
135 buf[3] = '\0'; 141 buf[3] = '\0';
136 n = xatou(buf); 142 n = xatou(buf);
diff --git a/networking/nc.c b/networking/nc.c
index a13d77a00..df073d7df 100644
--- a/networking/nc.c
+++ b/networking/nc.c
@@ -117,7 +117,7 @@ int nc_main(int argc, char **argv)
117 IF_NOT_NC_EXTRA (const) unsigned delay = 0; 117 IF_NOT_NC_EXTRA (const) unsigned delay = 0;
118 IF_NOT_NC_EXTRA (const int execparam = 0;) 118 IF_NOT_NC_EXTRA (const int execparam = 0;)
119 IF_NC_EXTRA (char **execparam = NULL;) 119 IF_NC_EXTRA (char **execparam = NULL;)
120 struct pollfd pfds[2]; 120 fd_set readfds, testfds;
121 int opt; /* must be signed (getopt returns -1) */ 121 int opt; /* must be signed (getopt returns -1) */
122 122
123 if (ENABLE_NC_SERVER || ENABLE_NC_EXTRA) { 123 if (ENABLE_NC_SERVER || ENABLE_NC_EXTRA) {
@@ -235,28 +235,29 @@ int nc_main(int argc, char **argv)
235 IF_NC_EXTRA(bb_perror_msg_and_die("can't execute '%s'", execparam[0]);) 235 IF_NC_EXTRA(bb_perror_msg_and_die("can't execute '%s'", execparam[0]);)
236 } 236 }
237 237
238 /* loop copying stdin to cfd, and cfd to stdout */ 238 /* Select loop copying stdin to cfd, and cfd to stdout */
239 239
240 pfds[0].fd = STDIN_FILENO; 240 FD_ZERO(&readfds);
241 pfds[0].events = POLLIN; 241 FD_SET(cfd, &readfds);
242 pfds[1].fd = cfd; 242 FD_SET(STDIN_FILENO, &readfds);
243 pfds[1].events = POLLIN;
244 243
245#define iobuf bb_common_bufsiz1 244#define iobuf bb_common_bufsiz1
246 setup_common_bufsiz(); 245 setup_common_bufsiz();
247 for (;;) { 246 for (;;) {
248 int fdidx; 247 int fd;
249 int ofd; 248 int ofd;
250 int nread; 249 int nread;
251 250
252 if (safe_poll(pfds, 2, -1) < 0) 251 testfds = readfds;
253 bb_perror_msg_and_die("poll");
254 252
255 fdidx = 0; 253 if (select(cfd + 1, &testfds, NULL, NULL, NULL) < 0)
254 bb_perror_msg_and_die("select");
255
256 fd = STDIN_FILENO;
256 while (1) { 257 while (1) {
257 if (pfds[fdidx].revents) { 258 if (FD_ISSET(fd, &testfds)) {
258 nread = safe_read(pfds[fdidx].fd, iobuf, COMMON_BUFSIZE); 259 nread = safe_read(fd, iobuf, COMMON_BUFSIZE);
259 if (fdidx != 0) { 260 if (fd == cfd) {
260 if (nread < 1) 261 if (nread < 1)
261 exit(EXIT_SUCCESS); 262 exit(EXIT_SUCCESS);
262 ofd = STDOUT_FILENO; 263 ofd = STDOUT_FILENO;
@@ -265,7 +266,7 @@ int nc_main(int argc, char **argv)
265 /* Close outgoing half-connection so they get EOF, 266 /* Close outgoing half-connection so they get EOF,
266 * but leave incoming alone so we can see response */ 267 * but leave incoming alone so we can see response */
267 shutdown(cfd, SHUT_WR); 268 shutdown(cfd, SHUT_WR);
268 pfds[0].fd = -1; 269 FD_CLR(STDIN_FILENO, &readfds);
269 } 270 }
270 ofd = cfd; 271 ofd = cfd;
271 } 272 }
@@ -273,9 +274,9 @@ int nc_main(int argc, char **argv)
273 if (delay > 0) 274 if (delay > 0)
274 sleep(delay); 275 sleep(delay);
275 } 276 }
276 if (fdidx == 1) 277 if (fd == cfd)
277 break; 278 break;
278 fdidx++; 279 fd = cfd;
279 } 280 }
280 } 281 }
281} 282}
diff --git a/networking/wget.c b/networking/wget.c
index e47c9a51b..ab9bc1836 100644
--- a/networking/wget.c
+++ b/networking/wget.c
@@ -457,11 +457,17 @@ static int ftpcmd(const char *s1, const char *s2, FILE *fp)
457 fprintf(stderr, "--> %s%s\n\n", s1, s2); 457 fprintf(stderr, "--> %s%s\n\n", s1, s2);
458 fflush(fp); 458 fflush(fp);
459 log_io("> %s%s", s1, s2); 459 log_io("> %s%s", s1, s2);
460#if ENABLE_PLATFORM_MINGW32
461 fseek(fp, 0L, SEEK_CUR);
462#endif
460 } 463 }
461 464
462 do { 465 do {
463 fgets_and_trim(fp, "%s\n"); 466 fgets_and_trim(fp, "%s\n");
464 } while (!isdigit(G.wget_buf[0]) || G.wget_buf[3] != ' '); 467 } while (!isdigit(G.wget_buf[0]) || G.wget_buf[3] != ' ');
468#if ENABLE_PLATFORM_MINGW32
469 fseek(fp, 0L, SEEK_CUR);
470#endif
465 471
466 G.wget_buf[3] = '\0'; 472 G.wget_buf[3] = '\0';
467 result = xatoi_positive(G.wget_buf); 473 result = xatoi_positive(G.wget_buf);