]> git.mxchange.org Git - simgear.git/commitdiff
HTTP: improve handling of connection errors
authorJames Turner <zakalawe@mac.com>
Mon, 24 Feb 2014 19:41:14 +0000 (19:41 +0000)
committerJames Turner <zakalawe@mac.com>
Mon, 24 Feb 2014 19:41:14 +0000 (19:41 +0000)
- handle 'whole connection' errors consistently, e.g. EUNREACH
which can occur with intermittent connections.

simgear/io/HTTPClient.cxx

index e345c093d66cbd4467e052a86b84dbe363a008e0..4d1f2c0e757292a8cb37e7ed81a8130882a9d65f 100644 (file)
@@ -122,27 +122,28 @@ public:
     // socket-level errors
     virtual void handleError(int error)
     {
-        if (error == ENOENT) {
-        // name lookup failure
-            // we won't have an active request yet, so the logic below won't
-            // fire to actually call setFailure. Let's fail all of the requests
+        const char* errStr = strerror(error);
+        if (!activeRequest)
+        {
+        // connection level failure, eg name lookup or routing
+        // we won't have an active request yet, so let's fail all of the
+        // requests since we presume it's a systematic failure for
+        // the host in question
             BOOST_FOREACH(Request_ptr req, sentRequests) {
-                req->setFailure(error, "hostname lookup failure");
+                req->setFailure(error, errStr);
             }
             
             BOOST_FOREACH(Request_ptr req, queuedRequests) {
-                req->setFailure(error, "hostname lookup failure");
+                req->setFailure(error, errStr);
             }
             
-        // 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");
-            activeRequest->setFailure(error, "socket error");
+            activeRequest->setFailure(error, errStr);
             activeRequest = NULL;
             _contentDecoder.reset();
         }
@@ -252,6 +253,7 @@ public:
       
       if (state == STATE_CLOSED) {
           if (!connectToHost()) {
+            
               return;
           }