boost::asio get_io_service() boost 1.70+ 中的替代方案

E. *_*ili 4 c++ boost boost-asio

我想使用一个库(https://github.com/onlinecity/cpp-smpp),它基于 boost 1.41。但在我们的项目中,我们使用的是 1.72。

那里有一段代码可以从 TCP 套接字获取 io_service(socket->get_io_service()此处)。然后在代码的以下部分中使用该对象:

deadline_timer timer(ioService);
Run Code Online (Sandbox Code Playgroud)

ioService.run_one();
ioService.reset();
Run Code Online (Sandbox Code Playgroud)

get_io_service()已从 boost 1.70+ 中删除。在这种情况下我应该使用哪些函数和对象来代替这些函数和对象?

更新

还有另一个问题(替代已弃用的 get_io_service())与我的类似,但该问题中的答案在本场景中不起作用。

小智 9

看看这个提交:https://github.com/mavlink/mavros/commit/3da41d770ca0e021f597bef30ffe6fcefe3e6959

它定义了一个宏

#if BOOST_VERSION >= 107000
#define GET_IO_SERVICE(s) ((boost::asio::io_context&)(s).get_executor().context())
#else
#define GET_IO_SERVICE(s) ((s).get_io_service())
#endif
Run Code Online (Sandbox Code Playgroud)

并取代呼叫

socket.get_io_service()
Run Code Online (Sandbox Code Playgroud)

GET_IO_SERVICE(socket)
Run Code Online (Sandbox Code Playgroud)