Changeset 1241

Show
Ignore:
Timestamp:
07/25/08 22:19:30 (4 months ago)
Author:
ahu
Message:

make tcp network errors not lead to cycling of backends

Files:

Legend:

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

    r1215 r1241  
    2525#include <string> 
    2626#include "tcpreceiver.hh" 
     27#include "sstuff.hh" 
    2728 
    2829#include <errno.h> 
     
    8990        ret=waitForData(fd, 5); 
    9091        if(ret < 0) 
    91           throw runtime_error("Waiting for data read"); 
     92          throw NetworkError("Waiting for data read"); 
    9293        if(!ret) 
    93           throw runtime_error("Timeout reading data"); 
     94          throw NetworkError("Timeout reading data"); 
    9495        continue; 
    9596      } 
    9697      else 
    97         throw AhuException("Reading data: "+stringerror()); 
     98        throw NetworkError("Reading data: "+stringerror()); 
    9899    } 
    99100    if(!ret) { 
     
    101102        return 0; 
    102103      else 
    103         throw AhuException("Did not fulfill read from TCP due to EOF"); 
     104        throw NetworkError("Did not fulfill read from TCP due to EOF"); 
    104105    } 
    105106     
     
    122123        ret=waitForRWData(fd, false, 5, 0); 
    123124        if(ret < 0) 
    124           throw runtime_error("Waiting for data write"); 
     125          throw NetworkError("Waiting for data write"); 
    125126        if(!ret) 
    126           throw runtime_error("Timeout writing data"); 
     127          throw NetworkError("Timeout writing data"); 
    127128        continue; 
    128129      } 
    129130      else 
    130         throw AhuException("Writing data: "+stringerror()); 
     131        throw NetworkError("Writing data: "+stringerror()); 
    131132    } 
    132133    if(!ret) { 
    133       throw AhuException("Did not fulfill TCP write due to EOF"); 
     134      throw NetworkError("Did not fulfill TCP write due to EOF"); 
    134135    } 
    135136     
     
    149150  if((err=connect(clisock, remote, socklen))<0 && WSAGetLastError() != WSAEWOULDBLOCK )  
    150151#endif // WIN32 
    151     throw AhuException("connect: "+stringerror()); 
     152    throw NetworkError("connect: "+stringerror()); 
    152153 
    153154  if(!err) 
     
    156157  err=waitForRWData(fd, false, 5, 0); 
    157158  if(err == 0) 
    158     throw AhuException("Timeout connecting to remote"); 
     159    throw NetworkError("Timeout connecting to remote"); 
    159160  if(err < 0) 
    160     throw AhuException("Error connecting to remote"); 
     161    throw NetworkError("Error connecting to remote"); 
    161162 
    162163  if(getsockopt(fd, SOL_SOCKET,SO_ERROR,(char *)&err,&len)<0) 
    163     throw AhuException("Error connecting to remote: "+stringerror()); // Solaris 
     164    throw NetworkError("Error connecting to remote: "+stringerror()); // Solaris 
    164165 
    165166  if(err) 
    166     throw AhuException("Error connecting to remote: "+string(strerror(err))); 
     167    throw NetworkError("Error connecting to remote: "+string(strerror(err))); 
    167168 
    168169 done: 
     
    184185  readnWithTimeout(fd, mesg, pktlen); 
    185186} 
    186 catch(AhuException& ae) { 
    187     throw AhuException("Error reading DNS data from TCP client "+remote.toString()+": "+ae.reason); 
     187catch(NetworkError& ae) { 
     188  throw NetworkError("Error reading DNS data from TCP client "+remote.toString()+": "+ae.what()); 
    188189} 
    189190 
     
    192193  int sock=socket(AF_INET, SOCK_STREAM, 0); 
    193194  if(sock < 0) 
    194     throw AhuException("Error making TCP connection socket to recursor: "+stringerror()); 
     195    throw NetworkError("Error making TCP connection socket to recursor: "+stringerror()); 
    195196 
    196197  Utility::setNonBlocking(sock); 
     
    222223    writenWithTimeout(packet->getSocket(), answer, len); 
    223224  } 
    224   catch(AhuException& ae) { 
     225  catch(NetworkError& ae) { 
    225226    close(sock); 
    226     throw AhuException("While proxying a question to recursor "+st.host+": " +ae.reason); 
     227    throw NetworkError("While proxying a question to recursor "+st.host+": " +ae.what()); 
    227228  } 
    228229  close(sock);