Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Boost::asio get_io_service() alternative in boost 1.70+

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.

like image 315
E. Vakili Avatar asked Nov 15 '25 07:11

E. Vakili


1 Answers

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)
like image 136
tropappar Avatar answered Nov 17 '25 20:11

tropappar