From 364df2ca4c5a5f54cb008109cefc506187073c29 Mon Sep 17 00:00:00 2001 From: jlemon Date: Sat, 23 Jun 2001 06:54:28 +0000 Subject: Bring in fix from rev 1.32 that got lost during the conversion to kqueue. This prevents an indefinte timeout in case the kevent call is interrupted for some reason. PR: 26665 MFC in: 2 weeks --- lib/libc/net/res_send.c | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) (limited to 'lib/libc') diff --git a/lib/libc/net/res_send.c b/lib/libc/net/res_send.c index 3513a49..e56b91f 100644 --- a/lib/libc/net/res_send.c +++ b/lib/libc/net/res_send.c @@ -598,7 +598,8 @@ read_len: * Use datagrams. */ struct kevent kv; - struct timespec timeout; + struct timespec ts; + struct timeval timeout, ctv; struct sockaddr_storage from; int fromlen; @@ -707,7 +708,10 @@ read_len: timeout.tv_sec /= _res.nscount; if ((long) timeout.tv_sec <= 0) timeout.tv_sec = 1; - timeout.tv_nsec = 0; + timeout.tv_usec = 0; + TIMEVAL_TO_TIMESPEC(&timeout, &ts); + (void) gettimeofday(&ctv, NULL); + timeradd(&timeout, &ctv, &timeout); wait: if (s < 0) { Perror(stderr, "s out-of-bounds", EMFILE); @@ -717,13 +721,20 @@ read_len: EV_SET(&kv, s, EVFILT_READ, EV_ADD | EV_ONESHOT, 0,0,0); - n = _kevent(kq, &kv, 1, &kv, 1, &timeout); + n = _kevent(kq, &kv, 1, &kv, 1, &ts); if (n < 0) { - if (errno == EINTR) - goto wait; - Perror(stderr, "kevent", errno); - res_close(); - goto next_ns; + if (errno == EINTR) { + (void) gettimeofday(&ctv, NULL); + if (timercmp(&ctv, &timeout, <)) { + timersub(&timeout, &ctv, &ctv); + TIMEVAL_TO_TIMESPEC(&ctv, &ts); + goto wait; + } + } else { + Perror(stderr, "kevent", errno); + res_close(); + goto next_ns; + } } if (n == 0) { -- cgit v1.1