diff options
author | Rob Landley <rob@landley.net> | 2008-11-18 22:17:43 -0600 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2008-11-18 22:17:43 -0600 |
commit | 7dbbe0d9ddc3d1b43b6699dc3c9cdd8a7b61851e (patch) | |
tree | 49aca5a645eea6b4ca3a03af7b063cd3b962a7c3 /toys | |
parent | 206a832f21f7b28f32127812da5ea764f8dd2644 (diff) | |
download | toybox-7dbbe0d9ddc3d1b43b6699dc3c9cdd8a7b61851e.tar.gz |
More than 4k of input can be queued up in a pipe, so loop needs to continue reading until POLLIN is exhausted before acknowledging POLLHUP.
Diffstat (limited to 'toys')
-rw-r--r-- | toys/netcat.c | 6 |
1 files changed, 2 insertions, 4 deletions
diff --git a/toys/netcat.c b/toys/netcat.c index 0ed2a36a..82039a91 100644 --- a/toys/netcat.c +++ b/toys/netcat.c @@ -93,6 +93,7 @@ void netcat_main(void) int sockfd=-1, pollcount=2; struct pollfd pollfds[2]; + memset(pollfds, 0, 2*sizeof(struct pollfd)); pollfds[0].events = pollfds[1].events = POLLIN; set_alarm(TT.wait); @@ -108,8 +109,6 @@ void netcat_main(void) int temp; struct sockaddr_in address; - pollfds[1].fd = 0; - // Setup socket sockfd = socket(AF_INET, SOCK_STREAM, 0); if (-1 == sockfd) perror_exit("socket"); @@ -212,8 +211,7 @@ void netcat_main(void) int len = read(pollfds[i].fd, toybuf, sizeof(toybuf)); if (len<1) goto dohupnow; xwrite(i ? pollfds[0].fd : 1, toybuf, len); - } - if (pollfds[i].revents & POLLHUP) { + } else if (pollfds[i].revents & POLLHUP) { dohupnow: // Close half-connection. This is needed for things like // "echo GET / | netcat landley.net 80" |