chiark / gitweb /
Only accept a reply from the subset of servers we sent the query.
[adns.git] / src / event.c
index d54d8479c38151b36e914f298b99e99af1922491..481fb73eb8762c184d4989e983143c0dc3c2a208 100644 (file)
@@ -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<<serv);
@@ -77,7 +77,7 @@ static void tcp_connected(adns_state ads, struct timeval now) {
   ads->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);
   }
@@ -173,16 +173,16 @@ void adns__timeouts(adns_state ads, int act,
 
   for (qu= ads->timew.head; qu; qu= nqu) {
     nqu= qu->next;
-    if (timercmp(&now,&qu->timeout,<=)) {
+    if (!timercmp(&now,&qu->timeout,>)) {
       if (!tv_io) continue;
       inter_maxtoabs(tv_io,tvbuf,now,qu->timeout);
     } 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;
     }
@@ -228,7 +228,6 @@ int adns__pollfds(adns_state ads, struct pollfd pollfds_buf[MAX_POLLFDS]) {
     abort();
   }
   pollfds_buf[1].fd= ads->tcpsocket;
-  pollfds_buf[1].revents= 0;
   return 2;
 }
 
@@ -252,7 +251,7 @@ int adns_processreadable(adns_state ads, int fd, const struct timeval *now) {
        if (ads->tcprecv.used<skip+2+dgramlen) {
          want= 2+dgramlen;
        } else {
-         adns__procdgram(ads,ads->tcprecv.buf+skip+2,dgramlen,ads->tcpserver,*now);
+         adns__procdgram(ads,ads->tcprecv.buf+skip+2,dgramlen,ads->tcpserver,1,*now);
          skip+= 2+dgramlen; continue;
        }
       }
@@ -316,7 +315,7 @@ int adns_processreadable(adns_state ads, int fd, const struct timeval *now) {
                   inet_ntoa(udpaddr.sin_addr));
        continue;
       }
-      adns__procdgram(ads,udpbuf,r,serv,*now);
+      adns__procdgram(ads,udpbuf,r,serv,0,*now);
     }
   }
   return 0;
@@ -454,12 +453,16 @@ void adns_beforeselect(adns_state ads, int *maxfd_io, fd_set *readfds_io,
 void adns_afterselect(adns_state ads, int maxfd, const fd_set *readfds,
                      const fd_set *writefds, const fd_set *exceptfds,
                      const struct timeval *now) {
+  struct timeval tv_buf;
   struct pollfd pollfds[MAX_POLLFDS];
-  int npollfds;
+  int npollfds, i;
 
+  adns__must_gettimeofday(ads,&now,&tv_buf);
+  if (!now) return;
   adns_processtimeouts(ads,now);
 
   npollfds= adns__pollfds(ads,pollfds);
+  for (i=0; i<npollfds; i++) pollfds[i].revents= POLLIN|POLLOUT|POLLPRI;
   adns__fdevents(ads,
                 pollfds,npollfds,
                 maxfd,readfds,writefds,exceptfds,
@@ -523,6 +526,7 @@ static int internal_check(adns_state ads,
   LIST_UNLINK(ads->output,qu);
   *answer= qu->answer;
   if (context_r) *context_r= qu->ctx.ext;
+  *query_io= qu;
   free(qu);
   return 0;
 }