From d8c062faeda8147546f1e709171f7f0767331954 Mon Sep 17 00:00:00 2001 From: ian Date: Thu, 29 Jul 1999 22:16:10 +0000 Subject: [PATCH] Restarting a TCP-using query doesn't abort. --- changelog | 1 + src/event.c | 8 ++++---- src/internal.h | 15 +++++++++------ src/query.c | 6 +++--- src/reply.c | 4 ++-- src/transmit.c | 4 ++-- 6 files changed, 21 insertions(+), 17 deletions(-) diff --git a/changelog b/changelog index 1f1162f..d5ad12d 100644 --- a/changelog +++ b/changelog @@ -7,6 +7,7 @@ adns (0.4) unstable; urgency=low * adns_s_systemfail is in table of errors (for eg adns_strerror). * Improvements to install instructions, TODO, etc. * Changed memory semantics of internal queries to fix bugs. + * Restarting a TCP-using query doesn't abort. -- diff --git a/src/event.c b/src/event.c index adb808b..9e87429 100644 --- a/src/event.c +++ b/src/event.c @@ -59,7 +59,7 @@ void adns__tcp_broken(adns_state ads, const char *what, const char *why) { for (qu= ads->timew.head; qu; qu= nqu) { nqu= qu->next; - if (qu->state == query_udp) continue; + if (qu->state == query_tosend) continue; assert(qu->state == query_tcpwait || qu->state == query_tcpsent); qu->state= query_tcpwait; qu->tcpfailed |= (1<tcpstate= server_ok; for (qu= ads->timew.head; qu; qu= nqu) { nqu= qu->next; - if (qu->state == query_udp) continue; + if (qu->state == query_tosend) continue; assert (qu->state == query_tcpwait); adns__query_tcp(qu,now); } @@ -179,10 +179,10 @@ void adns__timeouts(adns_state ads, int act, } else { if (!act) continue; LIST_UNLINK(ads->timew,qu); - if (qu->state != query_udp) { + if (qu->state != query_tosend) { adns__query_fail(qu,adns_s_timeout); } else { - adns__query_udp(qu,now); + adns__query_send(qu,now); } nqu= ads->timew.head; } diff --git a/src/internal.h b/src/internal.h index fc4fe85..7ee8671 100644 --- a/src/internal.h +++ b/src/internal.h @@ -151,7 +151,7 @@ typedef struct { struct adns__query { adns_state ads; - enum { query_udp, query_tcpwait, query_tcpsent, query_child, query_done } state; + enum { query_tosend, query_tcpwait, query_tcpsent, query_child, query_done } state; adns_query back, next, parent; struct { adns_query head, tail; } children; struct { adns_query back, next; } siblings; @@ -207,9 +207,9 @@ struct adns__query { * * state Queue child id nextudpserver sentudp failedtcp * - * udp NONE null >=0 0 zero zero - * udp timew null >=0 any nonzero zero - * udp NONE null >=0 any nonzero zero + * tosend NONE null >=0 0 zero zero + * tosend timew null >=0 any nonzero zero + * tosend NONE null >=0 any nonzero zero * * tcpwait timew null >=0 irrelevant zero any * tcpsent timew null >=0 irrelevant zero any @@ -364,11 +364,14 @@ void adns__query_tcp(adns_query qu, struct timeval now); * reestablishment and retry. */ -void adns__query_udp(adns_query qu, struct timeval now); -/* Query must be in state udp/NONE; it will be moved to a new state, +void adns__query_send(adns_query qu, struct timeval now); +/* Query must be in state tosend/NONE; it will be moved to a new state, * and no further processing can be done on it for now. * (Resulting state is one of udp/timew, tcpwait/timew (if server not connected), * tcpsent/timew, child/childw or done/output.) + * __query_send may decide to use either UDP or TCP depending whether + * _qf_usevc is set (or has become set) and whether the query is too + * large. */ /* From query.c: */ diff --git a/src/query.c b/src/query.c index 12bd6ad..3fab80c 100644 --- a/src/query.c +++ b/src/query.c @@ -42,7 +42,7 @@ static adns_query query_alloc(adns_state ads, const typeinfo *typei, qu->answer= malloc(sizeof(*qu->answer)); if (!qu->answer) { free(qu); return 0; } qu->ads= ads; - qu->state= query_udp; + qu->state= query_tosend; qu->back= qu->next= qu->parent= 0; LIST_INIT(qu->children); LINK_INIT(qu->siblings); @@ -100,7 +100,7 @@ static void query_submit(adns_state ads, adns_query qu, qu->query_dglen= qu->vb.used; memcpy(qu->query_dgram,qu->vb.buf,qu->vb.used); - adns__query_udp(qu,now); + adns__query_send(qu,now); adns__autosys(ads,now); } @@ -363,7 +363,7 @@ static void free_query_allocs(adns_query qu) { void adns_cancel(adns_query qu) { switch (qu->state) { - case query_udp: case query_tcpwait: case query_tcpsent: + case query_tosend: case query_tcpwait: case query_tcpsent: LIST_UNLINK(qu->ads->timew,qu); break; case query_child: diff --git a/src/reply.c b/src/reply.c index fbc2c83..96e43ed 100644 --- a/src/reply.c +++ b/src/reply.c @@ -320,7 +320,6 @@ void adns__procdgram(adns_state ads, const byte *dgram, int dglen, qu->flags |= adns_qf_usevc; x_restartquery: - if (qu->cname_dgram) { st= adns__mkquery_frdgram(qu->ads,&qu->vb,&qu->id, qu->cname_dgram, qu->cname_dglen, qu->cname_begin, @@ -335,6 +334,7 @@ void adns__procdgram(adns_state ads, const byte *dgram, int dglen, memcpy(newquery,qu->vb.buf,qu->vb.used); } + if (qu->state == query_tcpsent) qu->state= query_tosend; adns__reset_preserved(qu); - adns__query_udp(qu,now); + adns__query_send(qu,now); } diff --git a/src/transmit.c b/src/transmit.c index e373b48..33a8cc2 100644 --- a/src/transmit.c +++ b/src/transmit.c @@ -211,12 +211,12 @@ static void query_usetcp(adns_query qu, struct timeval now) { adns__tcp_tryconnect(qu->ads,now); } -void adns__query_udp(adns_query qu, struct timeval now) { +void adns__query_send(adns_query qu, struct timeval now) { struct sockaddr_in servaddr; int serv, r; adns_state ads; - assert(qu->state == query_udp); + assert(qu->state == query_tosend); if ((qu->flags & adns_qf_usevc) || (qu->query_dglen > DNS_MAXUDP)) { query_usetcp(qu,now); return; -- 2.30.2