2323#include < xrpl/beast/utility/instrumentation.h>
2424
2525#include < boost/asio/basic_waitable_timer.hpp>
26- #include < boost/asio/io_service.hpp>
26+ #include < boost/asio/io_context.hpp>
27+ #include < boost/asio/post.hpp>
2728
2829#include < chrono>
2930#include < condition_variable>
3233
3334namespace beast {
3435
35- /* * Measures handler latency on an io_service queue. */
36+ /* * Measures handler latency on an io_context queue. */
3637template <class Clock >
3738class io_latency_probe
3839{
@@ -44,12 +45,12 @@ class io_latency_probe
4445 std::condition_variable_any m_cond;
4546 std::size_t m_count;
4647 duration const m_period;
47- boost::asio::io_service & m_ios;
48+ boost::asio::io_context & m_ios;
4849 boost::asio::basic_waitable_timer<std::chrono::steady_clock> m_timer;
4950 bool m_cancel;
5051
5152public:
52- io_latency_probe (duration const & period, boost::asio::io_service & ios)
53+ io_latency_probe (duration const & period, boost::asio::io_context & ios)
5354 : m_count(1 )
5455 , m_period(period)
5556 , m_ios(ios)
@@ -64,16 +65,16 @@ class io_latency_probe
6465 cancel (lock, true );
6566 }
6667
67- /* * Return the io_service associated with the latency probe. */
68+ /* * Return the io_context associated with the latency probe. */
6869 /* * @{ */
69- boost::asio::io_service &
70- get_io_service ()
70+ boost::asio::io_context &
71+ get_io_context ()
7172 {
7273 return m_ios;
7374 }
7475
75- boost::asio::io_service const &
76- get_io_service () const
76+ boost::asio::io_context const &
77+ get_io_context () const
7778 {
7879 return m_ios;
7980 }
@@ -109,8 +110,10 @@ class io_latency_probe
109110 std::lock_guard lock (m_mutex);
110111 if (m_cancel)
111112 throw std::logic_error (" io_latency_probe is canceled" );
112- m_ios.post (sample_op<Handler>(
113- std::forward<Handler>(handler), Clock::now (), false , this ));
113+ boost::asio::post (
114+ m_ios,
115+ sample_op<Handler>(
116+ std::forward<Handler>(handler), Clock::now (), false , this ));
114117 }
115118
116119 /* * Initiate continuous i/o latency sampling.
@@ -124,8 +127,10 @@ class io_latency_probe
124127 std::lock_guard lock (m_mutex);
125128 if (m_cancel)
126129 throw std::logic_error (" io_latency_probe is canceled" );
127- m_ios.post (sample_op<Handler>(
128- std::forward<Handler>(handler), Clock::now (), true , this ));
130+ boost::asio::post (
131+ m_ios,
132+ sample_op<Handler>(
133+ std::forward<Handler>(handler), Clock::now (), true , this ));
129134 }
130135
131136private:
@@ -236,12 +241,13 @@ class io_latency_probe
236241 // The latency is too high to maintain the desired
237242 // period so don't bother with a timer.
238243 //
239- m_probe->m_ios .post (
244+ boost::asio::post (
245+ m_probe->m_ios ,
240246 sample_op<Handler>(m_handler, now, m_repeat, m_probe));
241247 }
242248 else
243249 {
244- m_probe->m_timer .expires_from_now (when - now);
250+ m_probe->m_timer .expires_after (when - now);
245251 m_probe->m_timer .async_wait (
246252 sample_op<Handler>(m_handler, now, m_repeat, m_probe));
247253 }
@@ -254,7 +260,8 @@ class io_latency_probe
254260 if (!m_probe)
255261 return ;
256262 typename Clock::time_point const now (Clock::now ());
257- m_probe->m_ios .post (
263+ boost::asio::post (
264+ m_probe->m_ios ,
258265 sample_op<Handler>(m_handler, now, m_repeat, m_probe));
259266 }
260267 };
0 commit comments