tompa
tompa

Reputation: 75

How to get the io_context from a strand in Boost 1.68?

I have a boost::asio::strand<boost::asio::io_context::executor_type> object and need to get its io_context. I thought that I could use get_io_context() but that has been deprecated. Then I thought that I could use context() but that one returns a boost::asio::execution_context.
I cannot see how I can convert this into an instance of io_context instead...

So, how can I get a strand's io_context in boost 1.68?

Upvotes: 1

Views: 2105

Answers (1)

rafix07
rafix07

Reputation: 20934

Call get_inner_executor on strand instance then context on executor:

#include <boost/asio.hpp>
int main() {
    boost::asio::io_context io;
    boost::asio::strand<boost::asio::io_context::executor_type> strand{io.get_executor()};

    boost::asio::io_context::executor_type executor = strand.get_inner_executor();
    boost::asio::io_context& refIO = executor.context();
}

Upvotes: 3

Related Questions