+ nqu= queue->head;
+ }
+ }
+}
+
+static void tcp_events(adns_state ads, int act,
+ struct timeval **tv_io, struct timeval *tvbuf,
+ struct timeval now) {
+ for (;;) {
+ switch (ads->tcpstate) {
+ case server_broken:
+ if (!act) { inter_immed(tv_io,tvbuf); return; }
+ tcp_broken_events(ads);
+ case server_disconnected: /* fall through */
+ if (!ads->tcpw.head) return;
+ if (!act) { inter_immed(tv_io,tvbuf); return; }
+ adns__tcp_tryconnect(ads,now);
+ break;
+ case server_ok:
+ if (ads->tcpw.head) return;
+ if (!ads->tcptimeout.tv_sec) {
+ assert(!ads->tcptimeout.tv_usec);
+ ads->tcptimeout= now;
+ timevaladd(&ads->tcptimeout,TCPIDLEMS);
+ }
+ case server_connecting: /* fall through */
+ if (!act || !timercmp(&now,&ads->tcptimeout,>)) {
+ inter_maxtoabs(tv_io,tvbuf,now,ads->tcptimeout);
+ return;
+ } {
+ /* TCP timeout has happened */
+ switch (ads->tcpstate) {
+ case server_connecting: /* failed to connect */
+ adns__tcp_broken(ads,"unable to make connection","timed out");
+ break;
+ case server_ok: /* idle timeout */
+ tcp_close(ads);
+ ads->tcpstate= server_disconnected;
+ return;
+ default:
+ abort();
+ }
+ }
+ break;
+ default:
+ abort();