Show
Ignore:
Timestamp:
09/22/09 12:14:43 (10 months ago)
Author:
ahu
Message:

implement timeouts with millisecond resolution, and raise the default timeout to 1500 msec.
In addition, the previous code may not actually have been delivering the "1 second" timeout accurately, this is now fixed

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/pdns/pdns/pdns_recursor.cc

    r1354 r1402  
    6767FDMultiplexer* g_fdm; 
    6868unsigned int g_maxTCPPerClient; 
     69unsigned int g_networkTimeoutMsec; 
    6970bool g_logCommonErrors; 
    7071shared_ptr<PowerDNSLua> g_pdl; 
     
    8586g_tcpListenSockets_t g_tcpListenSockets; 
    8687int g_tcpTimeout; 
     88 
    8789map<int, ComboAddress> g_listenSocketsAddresses; 
    8890struct DNSComboWriter { 
     
    152154  string packet; 
    153155 
    154   int ret=MT->waitEvent(pident, &packet, 1); 
     156  int ret=MT->waitEvent(pident, &packet, g_networkTimeoutMsec); 
    155157 
    156158  if(!ret || ret==-1) { // timeout 
     
    174176  g_fdm->addReadFD(sock->getHandle(), handleTCPClientReadable, pident); 
    175177 
    176   int ret=MT->waitEvent(pident,&data,1); 
     178  int ret=MT->waitEvent(pident, &data, g_networkTimeoutMsec); 
    177179  if(!ret || ret==-1) { // timeout 
    178180    g_fdm->removeReadFD(sock->getHandle()); 
     
    340342  g_fdm->addReadFD(*fd, handleUDPServerResponse, pident); 
    341343  ret=send(*fd, data, len, 0); 
     344  int tmp = errno; 
    342345  if(ret < 0) 
    343346    g_udpclientsocks.returnSocket(*fd); 
     347  errno = tmp; // this is for logging purposes only 
    344348  return ret; 
    345349} 
     
    347351// -1 is error, 0 is timeout, 1 is success 
    348352int 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 int now) 
     353              uint16_t id, const string& domain, uint16_t qtype, int fd, struct timeval* now) 
    350354{ 
    351355  static optional<unsigned int> nearMissLimit; 
     
    361365 
    362366  string packet; 
    363   int ret=MT->waitEvent(pident, &packet, 1, now); 
     367  int ret=MT->waitEvent(pident, &packet, g_networkTimeoutMsec, now); 
    364368 
    365369  if(ret > 0) { 
     
    18111815  } 
    18121816   
     1817  g_networkTimeoutMsec = ::arg().asNum("network-timeout"); 
    18131818  parseAuthAndForwards(); 
    18141819 
     
    18951900   
    18961901  for(;;) { 
    1897     while(MT->schedule(g_now.tv_sec)); // housekeeping, let threads do their thing 
     1902    while(MT->schedule(&g_now)); // housekeeping, let threads do their thing 
    18981903       
    18991904    if(!(counter%500)) { 
     
    19931998    ::arg().set("setgid","If set, change group id to this gid for more security")=""; 
    19941999    ::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"; 
    19952001#ifdef WIN32 
    19962002    ::arg().set("quiet","Suppress logging of questions and answers")="off";