]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[5649] Manage HTTP client connection timeout.
authorMarcin Siodelski <marcin@isc.org>
Wed, 13 Jun 2018 21:03:18 +0000 (23:03 +0200)
committerMarcin Siodelski <marcin@isc.org>
Wed, 13 Jun 2018 21:03:18 +0000 (23:03 +0200)
src/lib/http/client.cc

index dec4378eb297844665f9d21c577c867984749d22..bde07f09a59d8e2778161dedd506ffc7df2a9efd 100644 (file)
@@ -153,6 +153,11 @@ private:
     void terminate(const boost::system::error_code& ec,
                    const std::string& parsing_error = "");
 
+    /// @brief This method schedules timer or reschedules existing timer.
+    ///
+    /// @param request_timeout New timer interval in milliseconds.
+    void scheduleTimer(const long request_timeout);
+
     /// @brief Asynchronously sends data over the socket.
     ///
     /// The data sent over the socket are stored in the @c buf_.
@@ -559,6 +564,14 @@ Connection::terminate(const boost::system::error_code& ec,
     }
 }
 
+void
+Connection::scheduleTimer(const long request_timeout) {
+    if (request_timeout > 0) {
+        timer_.setup(boost::bind(&Connection::timerCallback, this), request_timeout,
+                     IntervalTimer::ONE_SHOT);
+    }
+}
+
 void
 Connection::doSend() {
     SocketCallback socket_cb(boost::bind(&Connection::sendCallback, shared_from_this(),
@@ -598,8 +611,8 @@ Connection::connectCallback(const long request_timeout, const boost::system::err
 
     } else {
         // Setup request timer.
-        timer_.setup(boost::bind(&Connection::timerCallback, this), request_timeout,
-                     IntervalTimer::ONE_SHOT);
+        scheduleTimer(request_timeout);
+
         // Start sending the request asynchronously.
         doSend();
     }
@@ -621,6 +634,9 @@ Connection::sendCallback(const boost::system::error_code& ec, size_t length) {
         }
     }
 
+    // Sending is in progress, so push back the timeout.
+    scheduleTimer(timer_.getInterval());
+
     // If any data have been sent, remove it from the buffer and only leave the
     // portion that still has to be sent.
     if (length > 0) {
@@ -654,6 +670,9 @@ Connection::receiveCallback(const boost::system::error_code& ec, size_t length)
         }
     }
 
+    // Receiving is in progress, so push back the timeout.
+    scheduleTimer(timer_.getInterval());
+
     // If we have received any data, let's feed the parser with it.
     if (length != 0) {
         parser_->postBuffer(static_cast<void*>(input_buf_.data()), length);