From: ian Date: Tue, 27 Jun 2000 23:01:42 +0000 (+0000) Subject: + * Do not spin if TCP connection blocks for writing (and add test case). X-Git-Tag: rel-adns-0-9~11 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=adns.git;a=commitdiff_plain;h=fb901bf5198d9d29014068dcd8a29c72d90f5eac + * Do not spin if TCP connection blocks for writing (and add test case). @@ -1,4 +1,4 @@ -adns (0.9) unstable; urgency=low +adns (0.9) unstable; urgency=high Bug fixes: * Don't make _processany always kill the TCP connection with the message @@ -7,6 +7,9 @@ `qu->interim_allocd>=0' on some platforms eg 64 bit). * adnsresfilter doesn't resolve textual prefixes of addresses (eg, 10.0.0.1 out of 10.0.0.123) if input happens to block at that point. + * Do not spin if TCP connection blocks for writing (and add test case). + * Fail queries if TCP dies repeatedly, rather than retrying many times. + * Do not abort in a couple of places if TCP unexpectedly broken. Portability/compilation fixes: * Move `extern "C" {' to after #include <...>'s. --- diff --git a/changelog b/changelog index 5382757..25dc347 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,4 @@ -adns (0.9) unstable; urgency=low +adns (0.9) unstable; urgency=high Bug fixes: * Don't make _processany always kill the TCP connection with the message @@ -7,6 +7,9 @@ adns (0.9) unstable; urgency=low `qu->interim_allocd>=0' on some platforms eg 64 bit). * adnsresfilter doesn't resolve textual prefixes of addresses (eg, 10.0.0.1 out of 10.0.0.123) if input happens to block at that point. + * Do not spin if TCP connection blocks for writing (and add test case). + * Fail queries if TCP dies repeatedly, rather than retrying many times. + * Do not abort in a couple of places if TCP unexpectedly broken. Portability/compilation fixes: * Move `extern "C" {' to after #include <...>'s. diff --git a/client/adnstest.c b/client/adnstest.c index d8c81d2..178bda5 100644 --- a/client/adnstest.c +++ b/client/adnstest.c @@ -232,6 +232,8 @@ int main(int argc, char *const *argv) { } if (r) failure_errno("init",r); + setvbuf(stdout,0,_IOLBF,0); + for (qi=0; qitcpstate == server_connecting || ads->tcpstate == server_ok); serv= ads->tcpserver; if (what) adns__warn(ads,serv,0,"TCP connection failed: %s: %s",what,why); + if (ads->tcpstate == server_connecting) { + /* Counts as a retry for all the queries waiting for TCP. */ + for (qu= ads->tcpw.head; qu; qu= qu->next) + qu->retries++; + } + tcp_close(ads); ads->tcpstate= server_broken; ads->tcpserver= (serv+1)%ads->nservers; @@ -328,6 +335,7 @@ int adns_processreadable(adns_state ads, int fd, const struct timeval *now) { switch (ads->tcpstate) { case server_disconnected: + case server_broken: case server_connecting: break; case server_ok: @@ -425,6 +433,7 @@ int adns_processwriteable(adns_state ads, int fd, const struct timeval *now) { switch (ads->tcpstate) { case server_disconnected: + case server_broken: break; case server_connecting: if (fd != ads->tcpsocket) break; @@ -447,8 +456,8 @@ int adns_processwriteable(adns_state ads, int fd, const struct timeval *now) { r= 0; goto xit; } /* not reached */ case server_ok: - if (!(ads->tcpsend.used && fd == ads->tcpsocket)) break; - for (;;) { + if (fd != ads->tcpsocket) break; + while (ads->tcpsend.used) { adns__sigpipe_protect(ads); r= write(ads->tcpsocket,ads->tcpsend.buf,ads->tcpsend.used); adns__sigpipe_unprotect(ads); @@ -462,7 +471,9 @@ int adns_processwriteable(adns_state ads, int fd, const struct timeval *now) { ads->tcpsend.used -= r; memmove(ads->tcpsend.buf,ads->tcpsend.buf+r,ads->tcpsend.used); } - } /* not reached */ + } + r= 0; + goto xit; default: abort(); } @@ -476,6 +487,7 @@ int adns_processexceptional(adns_state ads, int fd, const struct timeval *now) { adns__consistency(ads,0,cc_entex); switch (ads->tcpstate) { case server_disconnected: + case server_broken: break; case server_connecting: case server_ok: @@ -596,6 +608,7 @@ void adns_globalsystemfailure(adns_state ads) { adns__tcp_broken(ads,0,0); break; case server_disconnected: + case server_broken: break; default: abort();