* - user-visible check/wait and event-loop-related functions
*/
/*
- * This file is
- * Copyright (C) 1997-2000 Ian Jackson <ian@davenant.greenend.org.uk>
- *
- * It is part of adns, which is
- * Copyright (C) 1997-2000 Ian Jackson <ian@davenant.greenend.org.uk>
- * Copyright (C) 1999-2000 Tony Finch <dot@dotat.at>
+ * This file is part of adns, which is
+ * Copyright (C) 1997-2000,2003,2006 Ian Jackson
+ * Copyright (C) 1999-2000,2003,2006 Tony Finch
+ * Copyright (C) 1991 Massachusetts Institute of Technology
+ * (See the file INSTALL for full details.)
*
* 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
/* TCP connection management. */
static void tcp_close(adns_state ads) {
- int serv;
-
- serv= ads->tcpserver;
close(ads->tcpsocket);
ads->tcpsocket= -1;
ads->tcprecv.used= ads->tcprecv_skip= ads->tcpsend.used= 0;
}
}
+static void tcp_broken_events(adns_state ads) {
+ adns_query qu, nqu;
+
+ assert(ads->tcpstate == server_broken);
+ for (qu= ads->tcpw.head; qu; qu= nqu) {
+ nqu= qu->next;
+ assert(qu->state == query_tcpw);
+ if (qu->retries > ads->nservers) {
+ LIST_UNLINK(ads->tcpw,qu);
+ adns__query_fail(qu,adns_s_allservfail);
+ }
+ }
+ ads->tcpstate= server_disconnected;
+}
+
void adns__tcp_tryconnect(adns_state ads, struct timeval now) {
int r, fd, tries;
struct sockaddr_in addr;
return;
}
adns__tcp_broken(ads,"connect",strerror(errno));
- ads->tcpstate= server_disconnected;
+ tcp_broken_events(ads);
}
}
static void tcp_events(adns_state ads, int act,
struct timeval **tv_io, struct timeval *tvbuf,
struct timeval now) {
- adns_query qu, nqu;
-
for (;;) {
switch (ads->tcpstate) {
case server_broken:
if (!act) { inter_immed(tv_io,tvbuf); return; }
- for (qu= ads->tcpw.head; qu; qu= nqu) {
- nqu= qu->next;
- assert(qu->state == query_tcpw);
- if (qu->retries > ads->nservers) {
- LIST_UNLINK(ads->tcpw,qu);
- adns__query_fail(qu,adns_s_allservfail);
- }
- }
- ads->tcpstate= server_disconnected;
+ tcp_broken_events(ads);
case server_disconnected: /* fall through */
if (!ads->tcpw.head) return;
if (!act) { inter_immed(tv_io,tvbuf); return; }