X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=adns.git;a=blobdiff_plain;f=src%2Fevent.c;h=e22a8d1c8c768d06524c7102fee10a42499edfec;hp=d51f9807b0dd9d2f73e1543400866f37acf2ddb6;hb=be4d66dc60264126ba6b3fbd67609ef0b6c0d266;hpb=609133ee3365572c56ffa2ffb14d274ff47eb94b diff --git a/src/event.c b/src/event.c index d51f980..e22a8d1 100644 --- a/src/event.c +++ b/src/event.c @@ -5,12 +5,11 @@ * - user-visible check/wait and event-loop-related functions */ /* - * This file is - * Copyright (C) 1997-2000 Ian Jackson - * - * It is part of adns, which is - * Copyright (C) 1997-2000 Ian Jackson - * Copyright (C) 1999-2000 Tony Finch + * 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 @@ -44,9 +43,6 @@ /* 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; @@ -83,6 +79,21 @@ static void tcp_connected(adns_state ads, struct timeval now) { } } +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; @@ -135,7 +146,7 @@ void adns__tcp_tryconnect(adns_state ads, struct timeval now) { return; } adns__tcp_broken(ads,"connect",strerror(errno)); - ads->tcpstate= server_disconnected; + tcp_broken_events(ads); } } @@ -222,21 +233,11 @@ static void timeouts_queue(adns_state ads, int act, 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; }