From 67d74e4952f18d53e1bd570457c6d44309fb1ffc Mon Sep 17 00:00:00 2001 From: Bert Hubert Date: Fri, 25 Jul 2008 20:19:30 +0000 Subject: [PATCH] make tcp network errors not lead to cycling of backends git-svn-id: svn://svn.powerdns.com/pdns/trunk/pdns@1241 d19b8d6e-7fed-0310-83ef-9ca221ded41b --- pdns/tcpreceiver.cc | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/pdns/tcpreceiver.cc b/pdns/tcpreceiver.cc index e7a323791..8f240e8ef 100644 --- a/pdns/tcpreceiver.cc +++ b/pdns/tcpreceiver.cc @@ -24,6 +24,7 @@ #include #include #include "tcpreceiver.hh" +#include "sstuff.hh" #include #include @@ -88,19 +89,19 @@ int readnWithTimeout(int fd, void* buffer, unsigned int n, bool throwOnEOF=true) if(errno==EAGAIN) { ret=waitForData(fd, 5); if(ret < 0) - throw runtime_error("Waiting for data read"); + throw NetworkError("Waiting for data read"); if(!ret) - throw runtime_error("Timeout reading data"); + throw NetworkError("Timeout reading data"); continue; } else - throw AhuException("Reading data: "+stringerror()); + throw NetworkError("Reading data: "+stringerror()); } if(!ret) { if(!throwOnEOF && n == bytes) return 0; else - throw AhuException("Did not fulfill read from TCP due to EOF"); + throw NetworkError("Did not fulfill read from TCP due to EOF"); } ptr += ret; @@ -121,16 +122,16 @@ void writenWithTimeout(int fd, const void *buffer, unsigned int n) if(errno==EAGAIN) { ret=waitForRWData(fd, false, 5, 0); if(ret < 0) - throw runtime_error("Waiting for data write"); + throw NetworkError("Waiting for data write"); if(!ret) - throw runtime_error("Timeout writing data"); + throw NetworkError("Timeout writing data"); continue; } else - throw AhuException("Writing data: "+stringerror()); + throw NetworkError("Writing data: "+stringerror()); } if(!ret) { - throw AhuException("Did not fulfill TCP write due to EOF"); + throw NetworkError("Did not fulfill TCP write due to EOF"); } ptr += ret; @@ -148,22 +149,22 @@ void connectWithTimeout(int fd, struct sockaddr* remote, size_t socklen) #else if((err=connect(clisock, remote, socklen))<0 && WSAGetLastError() != WSAEWOULDBLOCK ) #endif // WIN32 - throw AhuException("connect: "+stringerror()); + throw NetworkError("connect: "+stringerror()); if(!err) goto done; err=waitForRWData(fd, false, 5, 0); if(err == 0) - throw AhuException("Timeout connecting to remote"); + throw NetworkError("Timeout connecting to remote"); if(err < 0) - throw AhuException("Error connecting to remote"); + throw NetworkError("Error connecting to remote"); if(getsockopt(fd, SOL_SOCKET,SO_ERROR,(char *)&err,&len)<0) - throw AhuException("Error connecting to remote: "+stringerror()); // Solaris + throw NetworkError("Error connecting to remote: "+stringerror()); // Solaris if(err) - throw AhuException("Error connecting to remote: "+string(strerror(err))); + throw NetworkError("Error connecting to remote: "+string(strerror(err))); done: ; @@ -183,15 +184,15 @@ try { readnWithTimeout(fd, mesg, pktlen); } -catch(AhuException& ae) { - throw AhuException("Error reading DNS data from TCP client "+remote.toString()+": "+ae.reason); +catch(NetworkError& ae) { + throw NetworkError("Error reading DNS data from TCP client "+remote.toString()+": "+ae.what()); } static void proxyQuestion(shared_ptr packet) { int sock=socket(AF_INET, SOCK_STREAM, 0); if(sock < 0) - throw AhuException("Error making TCP connection socket to recursor: "+stringerror()); + throw NetworkError("Error making TCP connection socket to recursor: "+stringerror()); Utility::setNonBlocking(sock); ServiceTuple st; @@ -221,9 +222,9 @@ static void proxyQuestion(shared_ptr packet) writenWithTimeout(packet->getSocket(), answer, len); } - catch(AhuException& ae) { + catch(NetworkError& ae) { close(sock); - throw AhuException("While proxying a question to recursor "+st.host+": " +ae.reason); + throw NetworkError("While proxying a question to recursor "+st.host+": " +ae.what()); } close(sock); return; -- 2.50.0