}
memset(&addr,0,sizeof(addr));
addr.sin_family= AF_INET;
- addr.sin_port= htons(NSPORT);
+ addr.sin_port= htons(DNS_PORT);
addr.sin_addr= ads->servers[ads->tcpserver].addr;
r= connect(fd,&addr,sizeof(addr));
ads->tcpsocket= fd;
if (!tv_io) return;
rbuf= *tv_io;
- if (!rbuf) { *tvbuf= maxto; *tv_io= tvbuf; return; }
- if (timercmp(rbuf,&maxto,>)) *rbuf= maxto;
+ if (!rbuf) {
+ *tvbuf= maxto; *tv_io= tvbuf;
+ } else {
+ if (timercmp(rbuf,&maxto,>)) *rbuf= maxto;
+ }
+fprintf(stderr,"inter_maxto maxto=%ld.%06ld result=%ld.%06ld\n",
+ maxto.tv_sec,maxto.tv_usec,(**tv_io).tv_sec,(**tv_io).tv_usec);
}
static void inter_maxtoabs(struct timeval **tv_io, struct timeval *tvbuf,
struct timeval now, struct timeval maxtime) {
ldiv_t dr;
+fprintf(stderr,"inter_maxtoabs now=%ld.%06ld maxtime=%ld.%06ld\n",
+ now.tv_sec,now.tv_usec,maxtime.tv_sec,maxtime.tv_usec);
if (!tv_io) return;
- maxtime.tv_sec -= (now.tv_sec-1);
- maxtime.tv_usec += (1000-now.tv_usec);
- dr= ldiv(maxtime.tv_usec,1000);
+ maxtime.tv_sec -= (now.tv_sec+2);
+ maxtime.tv_usec -= (now.tv_usec-2000000);
+ dr= ldiv(maxtime.tv_usec,1000000);
maxtime.tv_sec += dr.quot;
- maxtime.tv_usec -= dr.rem;
+ maxtime.tv_usec -= dr.quot*1000000;
+ if (maxtime.tv_sec<0) timerclear(&maxtime);
inter_maxto(tv_io,tvbuf,maxtime);
}
struct timeval tvto_lr;
int r;
- r= gettimeofday(&now,0);
+fprintf(stderr,"adns_interest\n");
+
+r= gettimeofday(&now,0);
if (r) {
adns__warn(ads,-1,"gettimeofday failed - will sleep for a bit: %s",strerror(errno));
timerclear(&tvto_lr); timevaladd(&tvto_lr,LOCALRESOURCEMS);
const fd_set *exceptfds,
struct timeval now) {
int skip, want, dgramlen, count, udpaddrlen, r, serv;
- byte udpbuf[MAXUDPDGRAM];
+ byte udpbuf[DNS_MAXUDP];
struct sockaddr_in udpaddr;
count= 0;
if (ads->tcprecv.used<skip+2+dgramlen) {
want= 2+dgramlen;
} else {
- adns__procdgram(ads,ads->tcprecv.buf+skip+2,dgramlen,ads->tcpserver);
+ adns__procdgram(ads,ads->tcprecv.buf+skip+2,dgramlen,ads->tcpserver,now);
skip+= 2+dgramlen; continue;
}
}
" %u (expected %u)",udpaddr.sin_family,AF_INET);
continue;
}
- if (ntohs(udpaddr.sin_port) != NSPORT) {
+ if (ntohs(udpaddr.sin_port) != DNS_PORT) {
adns__diag(ads,-1,"datagram received from wrong port %u (expected %u)",
- ntohs(udpaddr.sin_port),NSPORT);
+ ntohs(udpaddr.sin_port),DNS_PORT);
continue;
}
for (serv= 0;
inet_ntoa(udpaddr.sin_addr));
continue;
}
- adns__procdgram(ads,udpbuf,r,serv);
+ adns__procdgram(ads,udpbuf,r,serv,now);
}
}
return count;
if (qu->id>=0) return EWOULDBLOCK;
}
LIST_UNLINK(ads->output,qu);
- *answer= (adns_answer*)qu->answer.buf;
+#error copy answer *answer= (adns_answer*)qu->ans.buf;
if (context_r) *context_r= qu->context.ext;
free(qu);
return 0;
for (;;) {
r= internal_check(ads,query_io,answer_r,context_r);
- if (r && r != EWOULDBLOCK) return r;
+ if (r != EWOULDBLOCK) return r;
maxfd= 0; tvp= 0;
FD_ZERO(&readfds); FD_ZERO(&writefds); FD_ZERO(&exceptfds);
adns_interest(ads,&maxfd,&readfds,&writefds,&exceptfds,&tvp,&tvbuf);