@@ -69,10 +69,10 @@ std::vector<unsigned char> readFile(const char* filename)
69
69
}
70
70
71
71
#include < boost/asio.hpp>
72
+ #include < boost/asio/steady_timer.hpp>
72
73
73
74
boost::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;
76
76
void *hbclient;
77
77
78
78
void heartbeat_tick (const boost::system::error_code& /* e*/ ) {
@@ -81,19 +81,25 @@ void heartbeat_tick(const boost::system::error_code& /*e*/) {
81
81
if (!intervalSec) {
82
82
return ;
83
83
}
84
- interval = boost::posix_time::seconds (intervalSec);
85
84
// 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) );
87
86
// 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);
89
92
}
90
93
91
94
int setupHeartbeatTimer () {
92
95
auto &ioService = crossplat::threadpool::shared_instance ().service ();
93
96
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);
97
103
return 1 ;
98
104
}
99
105
0 commit comments