X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~mdw/git/adns/blobdiff_plain/ab898cf443c0302e801234d8df345e7eb8e8c06f..a225dda5a42c61fc6befec3e4e8ba39c32fc93db:/src/event.c diff --git a/src/event.c b/src/event.c index 6ddf492..e3f72a4 100644 --- a/src/event.c +++ b/src/event.c @@ -47,6 +47,7 @@ void adns__tcp_closenext(adns_state ads) { serv= ads->tcpserver; close(ads->tcpsocket); + ads->tcpsocket= -1; ads->tcpstate= server_disconnected; ads->tcprecv.used= ads->tcprecv_skip= ads->tcpsend.used= 0; ads->tcpserver= (serv+1)%ads->nservers; @@ -182,7 +183,12 @@ void adns__timeouts(adns_state ads, int act, if (!tv_io) continue; inter_maxtoabs(tv_io,tvbuf,now,qu->timeout); } else { - if (!act) continue; + if (!act) { + tvbuf->tv_sec= 0; + tvbuf->tv_usec= 0; + *tv_io= tvbuf; + return; + } LIST_UNLINK(ads->timew,qu); if (qu->state != query_tosend) { adns__query_fail(qu,adns_s_timeout); @@ -526,7 +532,7 @@ void adns_globalsystemfailure(adns_state ads) { } int adns_processany(adns_state ads) { - int r; + int r, i; struct timeval now; struct pollfd pollfds[MAX_POLLFDS]; int npollfds; @@ -541,6 +547,7 @@ int adns_processany(adns_state ads) { * likely just to want to do a read on one or two fds anyway. */ npollfds= adns__pollfds(ads,pollfds); + for (i=0; ioutput.head) return EWOULDBLOCK; - qu= ads->output.head; + if (ads->output.head) { + qu= ads->output.head; + } else if (ads->timew.head) { + return EAGAIN; + } else { + return ESRCH; + } } else { - if (qu->id>=0) return EWOULDBLOCK; + if (qu->id>=0) return EAGAIN; } LIST_UNLINK(ads->output,qu); *answer= qu->answer; @@ -587,7 +599,7 @@ int adns_wait(adns_state ads, adns__consistency(ads,*query_io,cc_entex); for (;;) { r= adns__internal_check(ads,query_io,answer_r,context_r); - if (r != EWOULDBLOCK) break; + if (r != EAGAIN) break; maxfd= 0; tvp= 0; FD_ZERO(&readfds); FD_ZERO(&writefds); FD_ZERO(&exceptfds); adns_beforeselect(ads,&maxfd,&readfds,&writefds,&exceptfds,&tvp,&tvbuf,0);