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.
This commit is contained in:
James Turner 2012-12-15 15:09:33 +00:00
parent 50688e1159
commit e9c70f8b1c
2 changed files with 16 additions and 4 deletions

View File

@ -4,6 +4,7 @@
#include <cassert> #include <cassert>
#include <list> #include <list>
#include <iostream> #include <iostream>
#include <errno.h>
#include <boost/foreach.hpp> #include <boost/foreach.hpp>
#include <boost/algorithm/string/case_conv.hpp> #include <boost/algorithm/string/case_conv.hpp>
@ -86,6 +87,12 @@ public:
// socket-level errors // socket-level errors
virtual void handleError(int error) virtual void handleError(int error)
{ {
if (error == ENOENT) {
// name lookup failure, abandon all requests on this connection
sentRequests.clear();
queuedRequests.clear();
}
NetChat::handleError(error); NetChat::handleError(error);
if (activeRequest) { if (activeRequest) {
SG_LOG(SG_IO, SG_INFO, "HTTP socket error"); SG_LOG(SG_IO, SG_INFO, "HTTP socket error");

View File

@ -211,7 +211,7 @@ NetChannel::handleResolve()
if (!addr.isValid()) { if (!addr.isValid()) {
SG_LOG(SG_IO, SG_WARN, "Network: host lookup failed:" << host); SG_LOG(SG_IO, SG_WARN, "Network: host lookup failed:" << host);
handleError (0); handleError (ENOENT);
close(); close();
return -1; return -1;
} }
@ -327,8 +327,13 @@ void NetChannel::handleAccept (void) {
SG_LOG(SG_IO, SG_WARN, "Network:" << getHandle() << ": unhandled accept"); SG_LOG(SG_IO, SG_WARN, "Network:" << getHandle() << ": unhandled accept");
} }
void NetChannel::handleError (int error) { 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 << ")"); SG_LOG(SG_IO, SG_WARN,"Network:" << getHandle() << ": errno: " << strerror(errno) <<"(" << errno << ")");
} }
}
} // of namespace simgear } // of namespace simgear