mirror of
https://git.FreeBSD.org/src.git
synced 2025-01-11 14:10:34 +00:00
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
This commit is contained in:
parent
3ae3f8b0be
commit
4dd2af159e
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=78647
@ -598,7 +598,8 @@ res_send(buf, buflen, ans, anssiz)
|
||||
* 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 @@ res_send(buf, buflen, ans, anssiz)
|
||||
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 @@ res_send(buf, buflen, ans, anssiz)
|
||||
|
||||
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) {
|
||||
|
Loading…
Reference in New Issue
Block a user