Replace deadline_timer with steady_timer.
This commit is contained in:
+10
-10
@@ -1,7 +1,5 @@
|
||||
#include "webcc/client.h"
|
||||
|
||||
#include "boost/date_time/posix_time/posix_time.hpp"
|
||||
|
||||
#include "webcc/logger.h"
|
||||
#include "webcc/utility.h"
|
||||
|
||||
@@ -18,6 +16,8 @@ Client::Client()
|
||||
timer_canceled_(false),
|
||||
timed_out_(false),
|
||||
error_(kNoError) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
bool Client::Request(RequestPtr request, bool connect) {
|
||||
@@ -144,7 +144,8 @@ Error Client::WriteReqeust(RequestPtr request) {
|
||||
Error Client::ReadResponse() {
|
||||
LOG_VERB("Read response (timeout: %ds)...", timeout_);
|
||||
|
||||
timer_.expires_from_now(boost::posix_time::seconds(timeout_));
|
||||
timer_.expires_after(std::chrono::seconds(timeout_));
|
||||
|
||||
DoWaitTimer();
|
||||
|
||||
Error error = kNoError;
|
||||
@@ -223,11 +224,11 @@ void Client::DoWaitTimer() {
|
||||
}
|
||||
|
||||
void Client::OnTimer(boost::system::error_code ec) {
|
||||
LOG_VERB("On deadline timer.");
|
||||
LOG_VERB("On timer.");
|
||||
|
||||
// timer_.cancel() was called.
|
||||
if (ec == boost::asio::error::operation_aborted) {
|
||||
LOG_VERB("Deadline timer canceled.");
|
||||
LOG_VERB("Timer canceled.");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -236,10 +237,9 @@ void Client::OnTimer(boost::system::error_code ec) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (timer_.expires_at() <= boost::asio::deadline_timer::traits_type::now()) {
|
||||
// The deadline has passed.
|
||||
// The socket is closed so that any outstanding asynchronous operations
|
||||
// are canceled.
|
||||
if (timer_.expiry() <= boost::asio::steady_timer::clock_type::now()) {
|
||||
// The deadline has passed. The socket is closed so that any outstanding
|
||||
// asynchronous operations are canceled.
|
||||
LOG_WARN("HTTP client timed out.");
|
||||
timed_out_ = true;
|
||||
Close();
|
||||
@@ -255,7 +255,7 @@ void Client::CancelTimer() {
|
||||
return;
|
||||
}
|
||||
|
||||
LOG_INFO("Cancel deadline timer...");
|
||||
LOG_INFO("Cancel timer...");
|
||||
timer_.cancel();
|
||||
|
||||
timer_canceled_ = true;
|
||||
|
||||
+2
-2
@@ -6,9 +6,9 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "boost/asio/deadline_timer.hpp"
|
||||
#include "boost/asio/io_context.hpp"
|
||||
#include "boost/asio/ip/tcp.hpp"
|
||||
#include "boost/asio/steady_timer.hpp"
|
||||
|
||||
#include "webcc/globals.h"
|
||||
#include "webcc/request.h"
|
||||
@@ -92,7 +92,7 @@ private:
|
||||
ResponseParser response_parser_;
|
||||
|
||||
// Timer for the timeout control.
|
||||
boost::asio::deadline_timer timer_;
|
||||
boost::asio::steady_timer timer_;
|
||||
|
||||
// The buffer for reading response.
|
||||
std::vector<char> buffer_;
|
||||
|
||||
Reference in New Issue
Block a user