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 <list>
#include <iostream>
#include <errno.h>
#include <boost/foreach.hpp>
#include <boost/algorithm/string/case_conv.hpp>
@ -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");

View File

@ -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