aboutsummaryrefslogtreecommitdiff
path: root/toys/net
diff options
context:
space:
mode:
authorJosh Gao <jmgao@google.com>2017-06-09 10:51:18 -0700
committerRob Landley <rob@landley.net>2017-07-21 13:43:29 -0500
commit67bf48c1cb3ed55249c27e6f02f5c938b20e027d (patch)
treec11174ecd9eaf81ed92499d16c48d5b2ec4ef486 /toys/net
parent8d6d9bf4f1a3caa0decb058dece8c4b4bd463e4a (diff)
downloadtoybox-67bf48c1cb3ed55249c27e6f02f5c938b20e027d.tar.gz
netcat: make -l exit after handling a request.
Bug: http://b/62305466
Diffstat (limited to 'toys/net')
-rw-r--r--toys/net/netcat.c17
1 files changed, 8 insertions, 9 deletions
diff --git a/toys/net/netcat.c b/toys/net/netcat.c
index 13ba3114..795f7b3c 100644
--- a/toys/net/netcat.c
+++ b/toys/net/netcat.c
@@ -126,11 +126,15 @@ void netcat_main(void)
// TODO xconnect
if (connect(sockfd, (struct sockaddr *)address, sizeof(*address))<0)
perror_exit("connect");
- in1 = out2 = sockfd;
- // Listen for incoming connections
+ // We have a connection. Disarm timeout.
+ set_alarm(0);
+
+ in1 = out2 = sockfd;
+ pollinate(in1, in2, out1, out2, TT.idle, TT.quit_delay);
} else {
+ // Listen for incoming connections
socklen_t len = sizeof(*address);
if (listen(sockfd, 5)) error_exit("listen");
@@ -143,7 +147,7 @@ void netcat_main(void)
if (CFG_TOYBOX_FORK && toys.optc && xfork()) goto cleanup;
}
- for (;;) {
+ do {
child = 0;
len = sizeof(*address); // gcc's insane optimizer can overwrite this
in1 = out2 = accept(sockfd, (struct sockaddr *)address, &len);
@@ -189,15 +193,10 @@ void netcat_main(void)
pollinate(in1, in2, out1, out2, TT.idle, TT.quit_delay);
close(in1);
- }
+ } while (!(toys.optflags&FLAG_l));
}
}
- // We have a connection. Disarm timeout.
- set_alarm(0);
-
- pollinate(in1, in2, out1, out2, TT.idle, TT.quit_delay);
-
cleanup:
if (CFG_TOYBOX_FREE) {
close(in1);