From e9c70f8b1cb12e4beb9cc854e3891a58d20b61d4 Mon Sep 17 00:00:00 2001 From: James Turner Date: Sat, 15 Dec 2012 15:09:33 +0000 Subject: [PATCH] Improve HTTP behaviour when name lookup fails. Don't endlessly re-send requests when name lookup fails; inform the next layer up so it can decide whether to retry. --- simgear/io/HTTPClient.cxx | 9 ++++++++- simgear/io/sg_netChannel.cxx | 11 ++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/simgear/io/HTTPClient.cxx b/simgear/io/HTTPClient.cxx index 2eff7439..ec25011f 100644 --- a/simgear/io/HTTPClient.cxx +++ b/simgear/io/HTTPClient.cxx @@ -4,6 +4,7 @@ #include #include #include +#include #include #include @@ -85,7 +86,13 @@ public: // socket-level errors virtual void handleError(int error) - { + { + if (error == ENOENT) { + // name lookup failure, abandon all requests on this connection + sentRequests.clear(); + queuedRequests.clear(); + } + NetChat::handleError(error); if (activeRequest) { SG_LOG(SG_IO, SG_INFO, "HTTP socket error"); diff --git a/simgear/io/sg_netChannel.cxx b/simgear/io/sg_netChannel.cxx index b903a980..817650ac 100644 --- a/simgear/io/sg_netChannel.cxx +++ b/simgear/io/sg_netChannel.cxx @@ -211,7 +211,7 @@ NetChannel::handleResolve() if (!addr.isValid()) { SG_LOG(SG_IO, SG_WARN, "Network: host lookup failed:" << host); - handleError (0); + handleError (ENOENT); close(); return -1; } @@ -327,8 +327,13 @@ void NetChannel::handleAccept (void) { SG_LOG(SG_IO, SG_WARN, "Network:" << getHandle() << ": unhandled accept"); } -void NetChannel::handleError (int error) { - SG_LOG(SG_IO, SG_WARN,"Network:" << getHandle() << ": errno: " << strerror(errno) <<"(" << errno << ")"); +void NetChannel::handleError (int error) +{ + // warn about address lookup failures seperately, don't warn again. + // (and we (ab-)use ENOENT to mean 'name not found'. + if (error != ENOENT) { + SG_LOG(SG_IO, SG_WARN,"Network:" << getHandle() << ": errno: " << strerror(errno) <<"(" << errno << ")"); + } } } // of namespace simgear