diff options
author | Artur Grabowski <art@cvs.openbsd.org> | 2000-07-07 15:34:03 +0000 |
---|---|---|
committer | Artur Grabowski <art@cvs.openbsd.org> | 2000-07-07 15:34:03 +0000 |
commit | f5a304e3b09c4d007053fb665ec71188a9523438 (patch) | |
tree | 5724d35dcafeb70e1c1bba1401d5381fa06c776d | |
parent | 2463afab2f08604a64d28ffa34565c84f3aabe1c (diff) |
If the timeout is not set, don't send a zeroed timeout to select.
This solves the problem with nc hogging all cpu.
-rw-r--r-- | usr.bin/nc/netcat.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/usr.bin/nc/netcat.c b/usr.bin/nc/netcat.c index 31f49a3fc35..eb4351dbe1b 100644 --- a/usr.bin/nc/netcat.c +++ b/usr.bin/nc/netcat.c @@ -1125,14 +1125,20 @@ readwrite(fd) /* and now the big ol' select shoveling loop ... */ while (FD_ISSET(fd, &fds1)) { /* i.e. till the *net* closes! */ + struct timeval *tv; + wretry = 8200; /* more than we'll ever hafta write */ if (wfirst) { /* any saved stdin buffer? */ wfirst = 0; /* clear flag for the duration */ goto shovel; /* and go handle it first */ } fds2 = fds1; - memcpy(&timer2, &timer1, sizeof(struct timeval)); - rr = select(getdtablesize(), &fds2, 0, 0, &timer2); + if (timer1.tv_sec > 0 || timer1.tv_usec > 0) { + memcpy(&timer2, &timer1, sizeof(struct timeval)); + tv = &timer2; + } else + tv = NULL; + rr = select(getdtablesize(), &fds2, 0, 0, tv); if (rr < 0) { if (errno != EINTR) { /* might have gotten ^Zed, etc * ? */ |