Skip to content

Commit ffc52b2

Browse files
committed
ping: use a monotonic timer
The deadline_timer uses system's UTC clock which is not monotonic (i.e., it jumps when the wall clock is adjusted). Let's switch to a monotonic timer. Given that boost::asio::steady_timer::expires_from_now() is marked as deprecated, use the other function. Change-Id: I40383721ecb0f12bfcb3f638124a32150a29bf48
1 parent fff3429 commit ffc52b2

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

src/http/EventStream.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ void EventStream::enqueue(const std::string& fieldName, const std::string& what)
180180

181181
void EventStream::start_ping()
182182
{
183-
ping.expires_from_now(boost::posix_time::seconds(m_keepAlivePingInterval.count()));
183+
ping.expires_after(m_keepAlivePingInterval);
184184
ping.async_wait([weak = weak_from_this()](const boost::system::error_code& ec) {
185185
auto myself = weak.lock();
186186
if (!myself) {

src/http/EventStream.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
#pragma once
99

10-
#include <boost/asio/deadline_timer.hpp>
10+
#include <boost/asio/steady_timer.hpp>
1111
#include <boost/signals2.hpp>
1212
#include <list>
1313
#include <memory>
@@ -50,7 +50,7 @@ class EventStream : public std::enable_shared_from_this<EventStream> {
5050
};
5151

5252
State state = WaitingForEvents;
53-
boost::asio::deadline_timer ping;
53+
boost::asio::steady_timer ping;
5454
std::list<std::string> queue;
5555
mutable std::mutex mtx; // for `state` and `queue`
5656
boost::signals2::scoped_connection eventSub, terminateSub;

0 commit comments

Comments
 (0)