Mercurial > hg > toybox
changeset 324:50c8afc263ee
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.
author | Rob Landley <rob@landley.net> |
---|---|
date | Tue, 18 Nov 2008 22:17:43 -0600 |
parents | dd0b130edf6d |
children | 5d0fbdb2fc86 |
files | toys/netcat.c |
diffstat | 1 files changed, 2 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/toys/netcat.c Sun Nov 16 02:41:04 2008 -0600 +++ b/toys/netcat.c Tue Nov 18 22:17:43 2008 -0600 @@ -93,6 +93,7 @@ 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 @@ 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 @@ 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"