From 94436798148b6859a335d1e7c35c432904165e6d Mon Sep 17 00:00:00 2001 From: ian Date: Sun, 4 Oct 1998 16:38:52 +0000 Subject: [PATCH] Retransmission and timeout work now ! --- src/event.c | 26 ++++++++++++++++++-------- src/internal.h | 6 +++--- src/query.c | 4 ++-- src/setup.c | 13 ++++++++----- src/submit.c | 4 ++-- 5 files changed, 33 insertions(+), 20 deletions(-) diff --git a/src/event.c b/src/event.c index 14ce1b0..7ed12f6 100644 --- a/src/event.c +++ b/src/event.c @@ -98,20 +98,28 @@ static void inter_maxto(struct timeval **tv_io, struct timeval *tvbuf, 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); } @@ -147,7 +155,9 @@ void adns_interest(adns_state ads, int *maxfd, 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); @@ -352,7 +362,7 @@ int adns_wait(adns_state ads, 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); diff --git a/src/internal.h b/src/internal.h index b652f23..5b5097b 100644 --- a/src/internal.h +++ b/src/internal.h @@ -17,7 +17,7 @@ typedef unsigned char byte; /* Configuration and constants */ #define MAXSERVERS 5 -#define MAXUDPRETRIES 15 +#define MAXUDPRETRIES /*15*/5 #define UDPRETRYMS 2000 #define TCPMS 30000 #define LOCALRESOURCEMS 20 @@ -175,9 +175,9 @@ static inline void timevaladd(struct timeval *tv_io, long ms) { struct timeval tmp; assert(ms>=0); tmp= *tv_io; - tmp.tv_usec += (ms%1000)*1000; + tmp.tv_usec += (ms%1000)*1000000; tmp.tv_sec += ms/1000; - if (tmp.tv_usec >= 1000) { tmp.tv_sec++; tmp.tv_usec -= 1000; } + if (tmp.tv_usec >= 1000000) { tmp.tv_sec++; tmp.tv_usec -= 1000; } *tv_io= tmp; } diff --git a/src/query.c b/src/query.c index 8aef532..35269e9 100644 --- a/src/query.c +++ b/src/query.c @@ -17,7 +17,7 @@ adns_status adns__mkquery(adns_state ads, const char *owner, int ol, int id, #define MKQUERY_ADDB(b) *rqp++= (b) #define MKQUERY_ADDW(w) (MKQUERY_ADDB(((w)>>8)&0x0ff), MKQUERY_ADDB((w)&0x0ff)) - if (!adns__vbuf_ensure(&ads->rqbuf,12+strlen(owner)+3)) return adns_s_nolocalmem; + if (!adns__vbuf_ensure(&ads->rqbuf,12+strlen(owner)+1+5)) return adns_s_nolocalmem; rqp= ads->rqbuf.buf; MKQUERY_ADDW(id); @@ -67,7 +67,7 @@ adns_status adns__mkquery(adns_state ads, const char *owner, int ol, int id, MKQUERY_ADDW(1); /* QCLASS=IN */ ads->rqbuf.used= rqp - ads->rqbuf.buf; - assert(ads->rqbuf.used < ads->rqbuf.avail); + assert(ads->rqbuf.used <= ads->rqbuf.avail); return adns_s_ok; } diff --git a/src/setup.c b/src/setup.c index 463779d..a83b97a 100644 --- a/src/setup.c +++ b/src/setup.c @@ -132,16 +132,16 @@ static void ccf_nameserver(adns_state ads, const char *fn, int lno, const char * static void ccf_search(adns_state ads, const char *fn, int lno, const char *buf) { if (!buf) return; - adns__diag(ads,-1,"warning - `search' ignored FIXME"); + adns__diag(ads,-1,"warning - `search' ignored fixme"); } static void ccf_sortlist(adns_state ads, const char *fn, int lno, const char *buf) { - adns__diag(ads,-1,"warning - `sortlist' ignored FIXME"); + adns__diag(ads,-1,"warning - `sortlist' ignored fixme"); } static void ccf_options(adns_state ads, const char *fn, int lno, const char *buf) { if (!buf) return; - adns__diag(ads,-1,"warning - `options' ignored FIXME"); + adns__diag(ads,-1,"warning - `options' ignored fixme"); } static void ccf_clearnss(adns_state ads, const char *fn, int lno, const char *buf) { @@ -289,16 +289,19 @@ int adns_init(adns_state *ads_r, adns_initflags flags, FILE *diagfile) { ads->udpsocket= socket(AF_INET,SOCK_DGRAM,proto->p_proto); if (ads->udpsocket<0) { r= errno; goto x_free; } - /*fixme: nonblock */ + r= adns__setnonblock(ads,ads->udpsocket); + if (r) { r= errno; goto x_closeudp; } *ads_r= ads; return 0; + x_closeudp: + close(ads->udpsocket); x_free: free(ads); return r; } int adns_finish(adns_state ads) { - abort(); /* FIXME */ + abort(); /* fixme */ } diff --git a/src/submit.c b/src/submit.c index ea10ab8..d0867de 100644 --- a/src/submit.c +++ b/src/submit.c @@ -72,7 +72,7 @@ int adns_submit(adns_state ads, stat= adns__mkquery(ads,owner,ol,id,type,flags); if (stat) return failsubmit(ads,context,query_r,type,flags,id,stat); - qu= allocquery(ads,owner,ol,id,type,flags,context); if (!qu) return errno; + qu= allocquery(ads,owner,ol,id,type,flags,&ctx); if (!qu) return errno; adns__query_udp(ads,qu,now); adns__autosys(ads,now); @@ -99,5 +99,5 @@ int adns_synchronous(adns_state ads, } void adns_cancel(adns_state ads, adns_query query) { - abort(); /* FIXME */ + abort(); /* fixme */ } -- 2.30.2