Changeset 945

Show
Ignore:
Timestamp:
01/14/07 14:37:08 (2 years ago)
Author:
ahu
Message:

make rec_control not block indefinitely

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/pdns/pdns/misc.cc

    r928 r945  
    265265} 
    266266 
     267// returns -1 in case if error, 0 if no data is available, 1 if there is. In the first two cases, errno is set 
    267268int waitForData(int fd, int seconds, int useconds) 
    268269{ 
  • trunk/pdns/pdns/rec_channel.cc

    r820 r945  
    121121} 
    122122 
     123// returns -1 in case if error, 0 if no data is available, 1 if there is. In the first two cases, errno is set 
     124static int waitForData(int fd, int seconds, int useconds) 
     125{ 
     126  struct timeval tv; 
     127  int ret; 
     128 
     129  tv.tv_sec   = seconds; 
     130  tv.tv_usec  = useconds; 
     131 
     132  fd_set readfds; 
     133  FD_ZERO( &readfds ); 
     134  FD_SET( fd, &readfds ); 
     135 
     136  ret = select( fd + 1, &readfds, NULL, NULL, &tv ); 
     137  if ( ret == 0 ) 
     138    errno = ETIMEDOUT; 
     139 
     140  return ret; 
     141} 
     142 
     143 
    123144string RecursorControlChannel::recv(std::string* remote) 
    124145{ 
     
    127148  struct sockaddr_un remoteaddr; 
    128149  socklen_t addrlen=sizeof(remoteaddr); 
    129  
    130   if((len=::recvfrom(d_fd, buffer, sizeof(buffer), 0, (struct sockaddr*)&remoteaddr, &addrlen)) < 0) 
     150     
     151  if((waitForData(d_fd, 5, 0 ) != 1) || (len=::recvfrom(d_fd, buffer, sizeof(buffer), 0, (struct sockaddr*)&remoteaddr, &addrlen)) < 0) 
    131152    throw AhuException("Unable to receive message over control channel: "+string(strerror(errno))); 
    132153