]> git.mxchange.org Git - simgear.git/blobdiff - simgear/io/HTTPClient.cxx
Lots of (mostly) doxygen fixes/cleanup.
[simgear.git] / simgear / io / HTTPClient.cxx
index ecc63f844054154a5a99230658848f2d46da05fb..4d1f2c0e757292a8cb37e7ed81a8130882a9d65f 100644 (file)
@@ -65,12 +65,6 @@ class Connection;
 typedef std::multimap<std::string, Connection*> ConnectionDict;
 typedef std::list<Request_ptr> RequestList;
 
-static bool isFailureStatus(int httpStatus)
-{
-  int majorCode = httpStatus / 100;
-  return (majorCode != 2);
-}
-
 class Client::ClientPrivate
 {
 public:
@@ -128,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();
         }
@@ -220,12 +215,12 @@ public:
         assert(state == STATE_WAITING_FOR_RESPONSE);
         
         activeRequest = sentRequests.front();
-       activeRequest->responseStart(buffer);
-       if (isFailureStatus(activeRequest->responseCode())) {
-         handleError(EIO);
-         return;
-       }
-      
+        try {
+            activeRequest->responseStart(buffer);
+        } catch (sg_exception& e) {
+            handleError(EIO);
+        }
+        
       state = STATE_GETTING_HEADERS;
       buffer.clear();
       if (activeRequest->responseCode() == 204) {
@@ -258,6 +253,7 @@ public:
       
       if (state == STATE_CLOSED) {
           if (!connectToHost()) {
+            
               return;
           }