@@ -69,10 +69,10 @@ std::vector<unsigned char> readFile(const char* filename)
6969}
7070
7171#include < boost/asio.hpp>
72+ #include < boost/asio/steady_timer.hpp>
7273
7374boost::asio::io_service io_service;
74- boost::posix_time::seconds interval (15 ); // 1 second
75- std::shared_ptr<boost::asio::deadline_timer> timer;
75+ std::shared_ptr<boost::asio::steady_timer> timer;
7676void *hbclient;
7777
7878void heartbeat_tick (const boost::system::error_code& /* e*/ ) {
@@ -81,19 +81,25 @@ void heartbeat_tick(const boost::system::error_code& /*e*/) {
8181 if (!intervalSec) {
8282 return ;
8383 }
84- interval = boost::posix_time::seconds (intervalSec);
8584 // Reschedule the timer for 1 second in the future:
86- timer->expires_at (timer-> expires_at () + interval );
85+ // timer->expires_from_now(boost::posix_time::seconds(4) );
8786 // Posts the timer event
88- timer->async_wait (heartbeat_tick);
87+ // timer->async_wait(heartbeat_tick);
88+
89+ auto &ioService = crossplat::threadpool::shared_instance ().service ();
90+ boost::asio::steady_timer t (ioService, std::chrono::seconds (4 ));
91+ t.async_wait (heartbeat_tick);
8992}
9093
9194int setupHeartbeatTimer () {
9295 auto &ioService = crossplat::threadpool::shared_instance ().service ();
9396
94- timer = std::make_shared<boost::asio::deadline_timer>(ioService);
95- timer->expires_from_now (boost::posix_time::seconds (1 ));
96- timer->async_wait (heartbeat_tick);
97+ // timer = std::make_shared<boost::asio::steady_timer>(ioService);
98+ // timer->expires_from_now(boost::posix_time::seconds(1));
99+ // timer->async_wait(heartbeat_tick);
100+
101+ boost::system::error_code err;
102+ heartbeat_tick (err);
97103 return 1 ;
98104}
99105
0 commit comments