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_.
}
}
+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(),
} 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();
}
}
}
+ // 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) {
}
}
+ // 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);