aboutsummaryrefslogtreecommitdiff
path: root/networking/nc.c
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2021-01-24 12:24:58 +0000
committerRon Yorston <rmy@pobox.com>2021-01-24 12:24:58 +0000
commit3c85cc0c4821f7131d90f5010b2930bdb0eae4d4 (patch)
tree71b079bf50e176e5caf97f9007647121a54f6eb9 /networking/nc.c
parenta19a9c222e3966b445de3259ce83dfff4411a67d (diff)
downloadbusybox-w32-3c85cc0c4821f7131d90f5010b2930bdb0eae4d4.tar.gz
busybox-w32-3c85cc0c4821f7131d90f5010b2930bdb0eae4d4.tar.bz2
busybox-w32-3c85cc0c4821f7131d90f5010b2930bdb0eae4d4.zip
nc: alter conditional compilation
Change conditional compilation to use PLATFORM_MINGW32 instead of NC_EXTRA. Enabling NC_EXTRA won't work for busybox-w32, but then it didn't before. Also, instead of just reverting upstream commit 5b3b468ec (nc: use poll() instead of select()) include both old and new code, keyed on PLATFORM_MINGW32.
Diffstat (limited to '')
-rw-r--r--networking/nc.c62
1 files changed, 55 insertions, 7 deletions
diff --git a/networking/nc.c b/networking/nc.c
index 3dce6a528..3483edb01 100644
--- a/networking/nc.c
+++ b/networking/nc.c
@@ -110,7 +110,7 @@
110 * when compared to "standard" nc 110 * when compared to "standard" nc
111 */ 111 */
112 112
113#if ENABLE_NC_EXTRA 113#if !ENABLE_PLATFORM_MINGW32
114static void timeout(int signum UNUSED_PARAM) 114static void timeout(int signum UNUSED_PARAM)
115{ 115{
116 bb_simple_error_msg_and_die("timed out"); 116 bb_simple_error_msg_and_die("timed out");
@@ -125,11 +125,15 @@ int nc_main(int argc, char **argv)
125 int cfd = 0; 125 int cfd = 0;
126 unsigned lport = 0; 126 unsigned lport = 0;
127 IF_NOT_NC_SERVER(const) unsigned do_listen = 0; 127 IF_NOT_NC_SERVER(const) unsigned do_listen = 0;
128#if !ENABLE_PLATFORM_MINGW32
128 IF_NOT_NC_EXTRA (const) unsigned wsecs = 0; 129 IF_NOT_NC_EXTRA (const) unsigned wsecs = 0;
129 IF_NOT_NC_EXTRA (const) unsigned delay = 0; 130 IF_NOT_NC_EXTRA (const) unsigned delay = 0;
130 IF_NOT_NC_EXTRA (const int execparam = 0;) 131 IF_NOT_NC_EXTRA (const int execparam = 0;)
131 IF_NC_EXTRA (char **execparam = NULL;) 132 IF_NC_EXTRA (char **execparam = NULL;)
133 struct pollfd pfds[2];
134#else
132 fd_set readfds, testfds; 135 fd_set readfds, testfds;
136#endif
133 int opt; /* must be signed (getopt returns -1) */ 137 int opt; /* must be signed (getopt returns -1) */
134 138
135 if (ENABLE_NC_SERVER || ENABLE_NC_EXTRA) { 139 if (ENABLE_NC_SERVER || ENABLE_NC_EXTRA) {
@@ -189,7 +193,7 @@ int nc_main(int argc, char **argv)
189 argv++; 193 argv++;
190 } 194 }
191 195
192#if ENABLE_NC_EXTRA 196#if !ENABLE_PLATFORM_MINGW32
193 if (wsecs) { 197 if (wsecs) {
194 signal(SIGALRM, timeout); 198 signal(SIGALRM, timeout);
195 alarm(wsecs); 199 alarm(wsecs);
@@ -212,11 +216,13 @@ int nc_main(int argc, char **argv)
212 } 216 }
213#endif 217#endif
214 close_on_exec_on(sfd); 218 close_on_exec_on(sfd);
215 IF_NC_EXTRA(accept_again:) 219 IF_NOT_PLATFORM_MINGW32(accept_again:)
216 cfd = accept(sfd, NULL, 0); 220 cfd = accept(sfd, NULL, 0);
217 if (cfd < 0) 221 if (cfd < 0)
218 bb_simple_perror_msg_and_die("accept"); 222 bb_simple_perror_msg_and_die("accept");
223#if !ENABLE_PLATFORM_MINGW32
219 if (!execparam) 224 if (!execparam)
225#endif
220 close(sfd); 226 close(sfd);
221 } else { 227 } else {
222 cfd = create_and_connect_stream_or_die(argv[0], 228 cfd = create_and_connect_stream_or_die(argv[0],
@@ -224,13 +230,13 @@ int nc_main(int argc, char **argv)
224 } 230 }
225 } 231 }
226 232
233#if !ENABLE_PLATFORM_MINGW32
227 if (wsecs) { 234 if (wsecs) {
228 alarm(0); 235 alarm(0);
229 /* Non-ignored signals revert to SIG_DFL on exec anyway */ 236 /* Non-ignored signals revert to SIG_DFL on exec anyway */
230 /*signal(SIGALRM, SIG_DFL);*/ 237 /*signal(SIGALRM, SIG_DFL);*/
231 } 238 }
232 239
233#if ENABLE_NC_EXTRA
234 /* -e given? */ 240 /* -e given? */
235 if (execparam) { 241 if (execparam) {
236 pid_t pid; 242 pid_t pid;
@@ -251,14 +257,57 @@ int nc_main(int argc, char **argv)
251 } 257 }
252#endif 258#endif
253 259
254 /* Select loop copying stdin to cfd, and cfd to stdout */ 260 /* loop copying stdin to cfd, and cfd to stdout */
255 261
262#if !ENABLE_PLATFORM_MINGW32
263 pfds[0].fd = STDIN_FILENO;
264 pfds[0].events = POLLIN;
265 pfds[1].fd = cfd;
266 pfds[1].events = POLLIN;
267#else
256 FD_ZERO(&readfds); 268 FD_ZERO(&readfds);
257 FD_SET(cfd, &readfds); 269 FD_SET(cfd, &readfds);
258 FD_SET(STDIN_FILENO, &readfds); 270 FD_SET(STDIN_FILENO, &readfds);
271#endif
259 272
260#define iobuf bb_common_bufsiz1 273#define iobuf bb_common_bufsiz1
261 setup_common_bufsiz(); 274 setup_common_bufsiz();
275#if !ENABLE_PLATFORM_MINGW32
276 for (;;) {
277 int fdidx;
278 int ofd;
279 int nread;
280
281 if (safe_poll(pfds, 2, -1) < 0)
282 bb_simple_perror_msg_and_die("poll");
283
284 fdidx = 0;
285 while (1) {
286 if (pfds[fdidx].revents) {
287 nread = safe_read(pfds[fdidx].fd, iobuf, COMMON_BUFSIZE);
288 if (fdidx != 0) {
289 if (nread < 1)
290 exit(EXIT_SUCCESS);
291 ofd = STDOUT_FILENO;
292 } else {
293 if (nread < 1) {
294 /* Close outgoing half-connection so they get EOF,
295 * but leave incoming alone so we can see response */
296 shutdown(cfd, SHUT_WR);
297 pfds[0].fd = -1;
298 }
299 ofd = cfd;
300 }
301 xwrite(ofd, iobuf, nread);
302 if (delay > 0)
303 sleep(delay);
304 }
305 if (fdidx == 1)
306 break;
307 fdidx++;
308 }
309 }
310#else
262 for (;;) { 311 for (;;) {
263 int fd; 312 int fd;
264 int ofd; 313 int ofd;
@@ -287,13 +336,12 @@ int nc_main(int argc, char **argv)
287 ofd = cfd; 336 ofd = cfd;
288 } 337 }
289 xwrite(ofd, iobuf, nread); 338 xwrite(ofd, iobuf, nread);
290 if (delay > 0)
291 sleep(delay);
292 } 339 }
293 if (fd == cfd) 340 if (fd == cfd)
294 break; 341 break;
295 fd = cfd; 342 fd = cfd;
296 } 343 }
297 } 344 }
345#endif
298} 346}
299#endif 347#endif