]> git.mxchange.org Git - simgear.git/commitdiff
Improve HTTP behaviour when name lookup fails.
authorJames Turner <zakalawe@mac.com>
Sat, 15 Dec 2012 15:09:33 +0000 (15:09 +0000)
committerJames Turner <zakalawe@mac.com>
Sat, 15 Dec 2012 15:09:33 +0000 (15:09 +0000)
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
simgear/io/sg_netChannel.cxx

index 2eff7439ba3e1adaada1edb1c40c2012a89822a5..ec25011f49ae1aa36624ed452499f21f2d6a5b6f 100644 (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");
index b903a98082f4c31d6f853c168140c1d98f985dfa..817650ac482b04c5da9b835d3809e15530f65e8d 100644 (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