Boost::asio get_io_service() alternative in boost 1.70+
Asked Answered
E

1

4

I want to use a library (https://github.com/onlinecity/cpp-smpp) and it's based on boost 1.41. But in our project, we are using 1.72.

There is a code there that gets io_service from a TCP socket (socket->get_io_service()here). Then this object is used in the following parts of the code:

deadline_timer timer(ioService);

and

ioService.run_one();
ioService.reset();

But get_io_service() is removed from boost 1.70+. What functions and objects I should use instead of those in such situations?

UPDATE

There is another question (Alternative to deprecated get_io_service()) that is similar to mine, but the answers in that question do not work in the scenario of this one.

Estonian answered 27/4, 2021 at 10:40 Comment(2)
How did those answers not work in your case? What have you tried and what was the error?Pah
I tried answers in #39446136. The output of get_executor().context() is null.Estonian
Y
9

Have a look at this commit: https://github.com/mavlink/mavros/commit/3da41d770ca0e021f597bef30ffe6fcefe3e6959

It defines a macro

#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

and replaces the calls

socket.get_io_service()

with

GET_IO_SERVICE(socket)
Yt answered 31/5, 2021 at 12:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.