]> git.mxchange.org Git - simgear.git/blobdiff - simgear/io/HTTPClient.cxx
Lots of (mostly) doxygen fixes/cleanup.
[simgear.git] / simgear / io / HTTPClient.cxx
index ed21f284be0183b016a4f5fb9ddd3021826b08be..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();
         }
@@ -214,8 +215,12 @@ public:
         assert(state == STATE_WAITING_FOR_RESPONSE);
         
         activeRequest = sentRequests.front();
+        try {
+            activeRequest->responseStart(buffer);
+        } catch (sg_exception& e) {
+            handleError(EIO);
+        }
         
-      activeRequest->responseStart(buffer);
       state = STATE_GETTING_HEADERS;
       buffer.clear();
       if (activeRequest->responseCode() == 204) {
@@ -248,6 +253,7 @@ public:
       
       if (state == STATE_CLOSED) {
           if (!connectToHost()) {
+            
               return;
           }
           
@@ -645,9 +651,13 @@ void Client::setMaxConnections(unsigned int maxCon)
 
 void Client::update(int waitTimeout)
 {
-    d->poller.poll(waitTimeout);
-    bool waitingRequests = !d->pendingRequests.empty();
+    if (!d->poller.hasChannels() && (waitTimeout > 0)) {
+        SGTimeStamp::sleepForMSec(waitTimeout);
+    } else {
+        d->poller.poll(waitTimeout);
+    }
     
+    bool waitingRequests = !d->pendingRequests.empty();
     ConnectionDict::iterator it = d->connections.begin();
     for (; it != d->connections.end(); ) {
         Connection* con = it->second;