Changeset 1402
- Timestamp:
- 09/22/09 12:14:43 (6 months ago)
- Location:
- trunk/pdns/pdns
- Files:
-
- 7 modified
-
dnsreplay.cc (modified) (1 diff)
-
lwres.cc (modified) (1 diff)
-
lwres.hh (modified) (1 diff)
-
misc.hh (modified) (1 diff)
-
mtasker.cc (modified) (6 diffs)
-
mtasker.hh (modified) (4 diffs)
-
pdns_recursor.cc (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/pdns/pdns/dnsreplay.cc
r1287 r1402 100 100 101 101 102 bool operator<(const struct timeval& lhs, const struct timeval& rhs)103 {104 return make_pair(lhs.tv_sec, lhs.tv_usec) < make_pair(rhs.tv_sec, rhs.tv_usec);105 }106 102 107 103 -
trunk/pdns/pdns/lwres.cc
r1349 r1402 106 106 107 107 ret=arecvfrom(reinterpret_cast<char *>(buf.get()), bufsize-1,0, ip, &len, pw.getHeader()->id, 108 domain, type, queryfd, now ->tv_sec);108 domain, type, queryfd, now); 109 109 } 110 110 else { -
trunk/pdns/pdns/lwres.hh
r1349 r1402 44 44 const string& domain, uint16_t qtype, int* fd); 45 45 int arecvfrom(char *data, int len, int flags, const ComboAddress& ip, int *d_len, uint16_t id, 46 const string& domain, uint16_t, int fd, unsigned intnow);46 const string& domain, uint16_t, int fd, struct timeval* now); 47 47 48 48 class LWResException : public AhuException -
trunk/pdns/pdns/misc.hh
r1345 r1402 304 304 return tv.tv_sec + tv.tv_usec/1000000.0f; 305 305 } 306 307 inline bool operator<(const struct timeval& lhs, const struct timeval& rhs) 308 { 309 return make_pair(lhs.tv_sec, lhs.tv_usec) < make_pair(rhs.tv_sec, rhs.tv_usec); 310 } 311 306 312 struct CIStringCompare: public binary_function<string, string, bool> 307 313 { -
trunk/pdns/pdns/mtasker.cc
r1260 r1402 159 159 */ 160 160 161 template<class EventKey, class EventVal>int MTasker<EventKey,EventVal>::waitEvent(EventKey &key, EventVal *val, unsigned int timeout , unsigned intnow)161 template<class EventKey, class EventVal>int MTasker<EventKey,EventVal>::waitEvent(EventKey &key, EventVal *val, unsigned int timeoutMsec, struct timeval* now) 162 162 { 163 163 if(d_waiters.count(key)) { // there was already an exact same waiter … … 167 167 Waiter w; 168 168 w.context=new ucontext_t; 169 w.ttd=0; 170 if(timeout) 171 w.ttd= timeout + (now ? now : time(0)); 169 w.ttd.tv_sec = 0; w.ttd.tv_usec = 0; 170 if(timeoutMsec) { 171 struct timeval increment; 172 increment.tv_sec = timeoutMsec / 1000; 173 increment.tv_usec = 1000 * (timeoutMsec % 1000); 174 if(now) 175 w.ttd = increment + *now; 176 else { 177 struct timeval realnow; 178 gettimeofday(&realnow, 0); 179 w.ttd = increment + realnow; 180 } 181 } 172 182 173 183 w.tid=d_tid; 174 175 184 w.key=key; 176 185 … … 268 277 269 278 */ 270 template<class Key, class Val>bool MTasker<Key,Val>::schedule( unsigned intnow)279 template<class Key, class Val>bool MTasker<Key,Val>::schedule(struct timeval* now) 271 280 { 272 281 if(!d_runQueue.empty()) { … … 292 301 } 293 302 if(!d_waiters.empty()) { 303 struct timeval rnow; 294 304 if(!now) 295 now=time(0); 305 gettimeofday(&rnow, 0); 306 else 307 rnow = *now; 296 308 297 309 typedef typename waiters_t::template index<KeyTag>::type waiters_by_ttd_index_t; … … 300 312 301 313 for(typename waiters_by_ttd_index_t::iterator i=ttdindex.begin(); i != ttdindex.end(); ) { 302 if(i->ttd && (unsigned int)i->ttd <now) {314 if(i->ttd.tv_sec && i->ttd < rnow) { 303 315 d_waitstatus=TimeOut; 304 316 d_eventkey=i->key; // pass waitEvent the exact key it was woken for … … 312 324 delete uc; 313 325 } 314 else if(i->ttd )326 else if(i->ttd.tv_sec) 315 327 break; 316 328 } -
trunk/pdns/pdns/mtasker.hh
r853 r1402 1 1 /* 2 2 PowerDNS Versatile Database Driven Nameserver 3 Copyright (C) 2002 - 200 6PowerDNS.COM BV3 Copyright (C) 2002 - 2009 PowerDNS.COM BV 4 4 5 5 This program is free software; you can redistribute it and/or modify … … 66 66 EventKey key; 67 67 ucontext_t *context; 68 time_tttd;68 struct timeval ttd; 69 69 int tid; 70 70 }; … … 74 74 indexed_by < 75 75 ordered_unique<member<Waiter,EventKey,&Waiter::key> >, 76 ordered_non_unique<tag<KeyTag>, member<Waiter, time_t,&Waiter::ttd> >76 ordered_non_unique<tag<KeyTag>, member<Waiter,struct timeval,&Waiter::ttd> > 77 77 > 78 78 > waiters_t; … … 91 91 92 92 typedef void tfunc_t(void *); //!< type of the pointer that starts a thread 93 int waitEvent(EventKey &key, EventVal *val=0, unsigned int timeout =0, unsigned intnow=0);93 int waitEvent(EventKey &key, EventVal *val=0, unsigned int timeoutMsec=0, struct timeval* now=0); 94 94 void yield(); 95 95 int sendEvent(const EventKey& key, const EventVal* val=0); 96 96 void getEvents(std::vector<EventKey>& events); 97 97 void makeThread(tfunc_t *start, void* val); 98 bool schedule( unsigned intnow=0);98 bool schedule(struct timeval* now=0); 99 99 bool noProcesses(); 100 100 unsigned int numProcesses(); -
trunk/pdns/pdns/pdns_recursor.cc
r1354 r1402 67 67 FDMultiplexer* g_fdm; 68 68 unsigned int g_maxTCPPerClient; 69 unsigned int g_networkTimeoutMsec; 69 70 bool g_logCommonErrors; 70 71 shared_ptr<PowerDNSLua> g_pdl; … … 85 86 g_tcpListenSockets_t g_tcpListenSockets; 86 87 int g_tcpTimeout; 88 87 89 map<int, ComboAddress> g_listenSocketsAddresses; 88 90 struct DNSComboWriter { … … 152 154 string packet; 153 155 154 int ret=MT->waitEvent(pident, &packet, 1);156 int ret=MT->waitEvent(pident, &packet, g_networkTimeoutMsec); 155 157 156 158 if(!ret || ret==-1) { // timeout … … 174 176 g_fdm->addReadFD(sock->getHandle(), handleTCPClientReadable, pident); 175 177 176 int ret=MT->waitEvent(pident, &data,1);178 int ret=MT->waitEvent(pident, &data, g_networkTimeoutMsec); 177 179 if(!ret || ret==-1) { // timeout 178 180 g_fdm->removeReadFD(sock->getHandle()); … … 340 342 g_fdm->addReadFD(*fd, handleUDPServerResponse, pident); 341 343 ret=send(*fd, data, len, 0); 344 int tmp = errno; 342 345 if(ret < 0) 343 346 g_udpclientsocks.returnSocket(*fd); 347 errno = tmp; // this is for logging purposes only 344 348 return ret; 345 349 } … … 347 351 // -1 is error, 0 is timeout, 1 is success 348 352 int arecvfrom(char *data, int len, int flags, const ComboAddress& fromaddr, int *d_len, 349 uint16_t id, const string& domain, uint16_t qtype, int fd, unsigned intnow)353 uint16_t id, const string& domain, uint16_t qtype, int fd, struct timeval* now) 350 354 { 351 355 static optional<unsigned int> nearMissLimit; … … 361 365 362 366 string packet; 363 int ret=MT->waitEvent(pident, &packet, 1, now);367 int ret=MT->waitEvent(pident, &packet, g_networkTimeoutMsec, now); 364 368 365 369 if(ret > 0) { … … 1811 1815 } 1812 1816 1817 g_networkTimeoutMsec = ::arg().asNum("network-timeout"); 1813 1818 parseAuthAndForwards(); 1814 1819 … … 1895 1900 1896 1901 for(;;) { 1897 while(MT->schedule( g_now.tv_sec)); // housekeeping, let threads do their thing1902 while(MT->schedule(&g_now)); // housekeeping, let threads do their thing 1898 1903 1899 1904 if(!(counter%500)) { … … 1993 1998 ::arg().set("setgid","If set, change group id to this gid for more security")=""; 1994 1999 ::arg().set("setuid","If set, change user id to this uid for more security")=""; 2000 ::arg().set("network-timeout", "Wait this nummer of milliseconds for network i/o")="1500"; 1995 2001 #ifdef WIN32 1996 2002 ::arg().set("quiet","Suppress logging of questions and answers")="off";