]> granicus.if.org Git - pdns/commitdiff
Use NetworkError, remove redundant code
authorAki Tuomi <cmouse@desteem.org>
Wed, 14 Jan 2015 09:57:45 +0000 (11:57 +0200)
committerAki Tuomi <cmouse@desteem.org>
Wed, 14 Jan 2015 09:57:45 +0000 (11:57 +0200)
modules/remotebackend/httpconnector.cc

index 9befb8bef90626f2430cd1a8a1e600e8afa8bfe6..efef0123b7a41a331c3904e94568255e430e743b 100644 (file)
@@ -389,23 +389,13 @@ int HTTPConnector::recv_message(rapidjson::Document &output) {
     try {
       t0 = time((time_t*)NULL);
       while(arl.ready() == false && (labs(time((time_t*)NULL) - t0) <= timeout/1000)) {
-        rd = d_socket->readWithTimeout(buffer, sizeof(buffer), timeout);
-        if (rd<0) {
-          delete d_socket;
-          d_socket = NULL;
-          fail = true;
-          break;
-        }
+        rd = d_socket->readWithTimeout(buffer, sizeof(buffer), timeout); // if rd<=0 this will throw
         buffer[rd] = 0;
         arl.feed(std::string(buffer, rd));
       }
       // timeout occured.
-      if (arl.ready() == false) {
-        L<<Logger::Error<<"While reading from HTTP endpoint "<<d_addr.toStringWithPort()<<": timeout"<<std::endl;
-        delete d_socket;
-        d_socket = NULL;
-        fail = true;
-      }     
+      if (arl.ready() == false)
+        throw NetworkError("timeout");
     } catch (NetworkError &ne) {
       L<<Logger::Error<<"While reading from HTTP endpoint "<<d_addr.toStringWithPort()<<": "<<ne.what()<<std::endl; 
       delete d_socket;