*/
/*
* This file is
- * Copyright (C) 1997-1999 Ian Jackson <ian@davenant.greenend.org.uk>
+ * Copyright (C) 1997-2000 Ian Jackson <ian@davenant.greenend.org.uk>
*
* It is part of adns, which is
- * Copyright (C) 1997-1999 Ian Jackson <ian@davenant.greenend.org.uk>
- * Copyright (C) 1999 Tony Finch <dot@dotat.at>
+ * Copyright (C) 1997-2000 Ian Jackson <ian@davenant.greenend.org.uk>
+ * Copyright (C) 1999-2000 Tony Finch <dot@dotat.at>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
void adns__tcp_broken(adns_state ads, const char *what, const char *why) {
int serv;
+ adns_query qu;
assert(ads->tcpstate == 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;
switch (ads->tcpstate) {
case server_disconnected:
+ case server_broken:
case server_connecting:
break;
case server_ok:
if (fd != ads->tcpsocket) break;
assert(!ads->tcprecv_skip);
- for (;;) {
+ do {
if (ads->tcprecv.used >= ads->tcprecv_skip+2) {
dgramlen= ((ads->tcprecv.buf[ads->tcprecv_skip]<<8) |
ads->tcprecv.buf[ads->tcprecv_skip+1]);
if (errno_resources(errno)) { r= errno; goto xit; }
}
adns__tcp_broken(ads,"read",r?strerror(errno):"closed");
- r= 0; goto xit;
}
- } /* never reached */
+ } while (ads->tcpstate == server_ok);
+ r= 0; goto xit;
default:
abort();
}
}
if (udpaddrlen != sizeof(udpaddr)) {
adns__diag(ads,-1,0,"datagram received with wrong address length %d"
- " (expected %d)", udpaddrlen,sizeof(udpaddr));
+ " (expected %lu)", udpaddrlen,
+ (unsigned long)sizeof(udpaddr));
continue;
}
if (udpaddr.sin_family != AF_INET) {
switch (ads->tcpstate) {
case server_disconnected:
+ case server_broken:
break;
case server_connecting:
if (fd != ads->tcpsocket) break;
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);
ads->tcpsend.used -= r;
memmove(ads->tcpsend.buf,ads->tcpsend.buf+r,ads->tcpsend.used);
}
- } /* not reached */
+ }
+ r= 0;
+ goto xit;
default:
abort();
}
adns__consistency(ads,0,cc_entex);
switch (ads->tcpstate) {
case server_disconnected:
+ case server_broken:
break;
case server_connecting:
case server_ok:
adns__tcp_broken(ads,0,0);
break;
case server_disconnected:
+ case server_broken:
break;
default:
abort();
* likely just to want to do a read on one or two fds anyway.
*/
npollfds= adns__pollfds(ads,pollfds);
- for (i=0; i<npollfds; i++) pollfds[i].revents= pollfds[i].events;
+ for (i=0; i<npollfds; i++) pollfds[i].revents= pollfds[i].events & ~POLLPRI;
adns__fdevents(ads,
pollfds,npollfds,
0,0,0,0,
if (r != EAGAIN) break;
maxfd= 0; tvp= 0;
FD_ZERO(&readfds); FD_ZERO(&writefds); FD_ZERO(&exceptfds);
- ads->bug_if_query_done_now= 1;
adns_beforeselect(ads,&maxfd,&readfds,&writefds,&exceptfds,&tvp,&tvbuf,0);
- ads->bug_if_query_done_now= 0;
assert(tvp);
rsel= select(maxfd,&readfds,&writefds,&exceptfds,tvp);
if (rsel==-1) {