bug_if_query_done backported abandon.2000-03-26.infotodebug-0.7 privaterel-1999-03-26-infto-debug
authorian <ian>
Sun, 26 Mar 2000 15:13:02 +0000 (15:13 +0000)
committerian <ian>
Sun, 26 Mar 2000 15:13:02 +0000 (15:13 +0000)
src/event.c
src/internal.h
src/query.c
src/setup.c

index 1b679e6..2f0fbb7 100644 (file)
@@ -143,17 +143,6 @@ void adns__must_gettimeofday(adns_state ads, const struct timeval **now_io,
   return;
 }
 
-static void inter_immed(struct timeval **tv_io, struct timeval *tvbuf) {
-  struct timeval *rbuf;
-
-  if (!tv_io) return;
-
-  rbuf= *tv_io;
-  if (!rbuf) { *tv_io= rbuf= tvbuf; }
-
-  timerclear(rbuf);
-}
-    
 static void inter_maxto(struct timeval **tv_io, struct timeval *tvbuf,
                        struct timeval maxto) {
   struct timeval *rbuf;
@@ -196,7 +185,12 @@ static void timeouts_queue(adns_state ads, int act,
     if (!timercmp(&now,&qu->timeout,>)) {
       inter_maxtoabs(tv_io,tvbuf,now,qu->timeout);
     } else {
-      if (!act) { inter_immed(tv_io,tvbuf); return; }
+      if (!act) {
+       tvbuf->tv_sec= 0;
+       tvbuf->tv_usec= 0;
+       *tv_io= tvbuf;
+       return;
+      }
       LIST_UNLINK(*queue,qu);
       if (qu->state != query_tosend) {
        adns__query_fail(qu,adns_s_timeout);
@@ -216,7 +210,6 @@ static void tcp_events(adns_state ads, int act,
   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);
@@ -228,7 +221,6 @@ static void tcp_events(adns_state ads, int act,
       ads->tcpstate= server_disconnected;
     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:
@@ -239,7 +231,7 @@ static void tcp_events(adns_state ads, int act,
        timevaladd(&ads->tcptimeout,TCPIDLEMS);
       }
     case server_connecting: /* fall through */
-      if (!act || !timercmp(&now,&ads->tcptimeout,>)) {
+      if (!timercmp(&now,&ads->tcptimeout,>)) {
        inter_maxtoabs(tv_io,tvbuf,now,ads->tcptimeout);
        return;
       } {
@@ -261,7 +253,6 @@ static void tcp_events(adns_state ads, int act,
       abort();
     }
   }
-  return;
 }
 
 void adns__timeouts(adns_state ads, int act,
@@ -540,7 +531,7 @@ void adns_beforeselect(adns_state ads, int *maxfd_io, fd_set *readfds_io,
   if (tv_mod && (!*tv_mod || (*tv_mod)->tv_sec || (*tv_mod)->tv_usec)) {
     /* The caller is planning to sleep. */
     adns__must_gettimeofday(ads,&now,&tv_nowbuf);
-    if (!now) { inter_immed(tv_mod,tv_tobuf); goto xit; }
+    if (!now) goto xit;
     adns__timeouts(ads, 1, tv_mod,tv_tobuf, *now);
   }
 
@@ -673,7 +664,9 @@ int adns_wait(adns_state ads,
     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) {
index c766738..b21204a 100644 (file)
@@ -282,6 +282,7 @@ struct adns__state {
   struct query_queue udpw, tcpw, childw, output;
   adns_query forallnext;
   int nextid, udpsocket, tcpsocket;
+  int bug_if_query_done_now;
   vbuf tcpsend, tcprecv;
   int nservers, nsortlist, nsearchlist, searchndots, tcpserver, tcprecv_skip;
   enum adns__tcpstate {
@@ -289,10 +290,10 @@ struct adns__state {
     server_ok, server_broken
   } tcpstate;
   struct timeval tcptimeout;
-  /* This will have tv_sec==0 if it is not valid.  It will always be
-   * valid if tcpstate _connecting.  When _ok, it will be nonzero if
-   * we are idle (ie, tcpw queue is empty), in which case it is the
-   * absolute time when we will close the connection.
+  /* This will have tv_sec==0 if it is not valid.
+   * It will always be valid if tcpstate _connecting.
+   * When _ok, it will be nonzero if we are idle
+   * (ie, tcpw queue is empty) and counting down.
    */
   struct sigaction stdsigpipe;
   sigset_t stdsigmask;
index aaadb21..038881e 100644 (file)
@@ -66,7 +66,7 @@ static adns_query query_alloc(adns_state ads, const typeinfo *typei,
   adns__vbuf_init(&qu->search_vb);
   qu->search_origlen= qu->search_pos= qu->search_doneabs= 0;
 
-  qu->id= -2; /* will be overwritten with real id before we leave adns */
+  qu->id= 0;
   qu->flags= flags;
   qu->retries= 0;
   qu->udpnextserver= 0;
@@ -501,6 +501,7 @@ void adns__query_done(adns_query qu) {
   adns_answer *ans;
   adns_query parent;
 
+  assert(!qu->ads->bug_if_query_done_now);
   cancel_children(qu);
 
   qu->id= -1;
@@ -542,6 +543,7 @@ void adns__query_done(adns_query qu) {
 }
 
 void adns__query_fail(adns_query qu, adns_status stat) {
+  assert(!qu->ads->bug_if_query_done_now);
   adns__reset_preserved(qu);
   qu->answer->status= stat;
   adns__query_done(qu);
index ac88c33..211f425 100644 (file)
@@ -474,6 +474,7 @@ static int init_begin(adns_state *ads_r, adns_initflags flags, FILE *diagfile) {
   ads->forallnext= 0;
   ads->nextid= 0x311f;
   ads->udpsocket= ads->tcpsocket= -1;
+  ads->bug_if_query_done_now= 0;
   adns__vbuf_init(&ads->tcpsend);
   adns__vbuf_init(&ads->tcprecv);
   ads->tcprecv_skip= 0;