Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alternative to deprecated get_io_service()

Tags:

boost-asio

Asio v 1.11. The doc says that basic_stream_socket::get_io_service() member function is deprecated and get_executor() must be used instead. But the latter returns executor not io_service.

How to obtain reference to the io_service object used by socket to construct another one?

like image 777
Victor Dyachenko Avatar asked Sep 12 '16 07:09

Victor Dyachenko


3 Answers

You can use get_executor().context():

socket newSocket(existingSocket.get_executor().context()));
like image 120
m.s. Avatar answered Oct 19 '22 07:10

m.s.


Since ASIO v 1.13 new I/O object can be constructed using just the executor:

socket new_socket{existing_socket.get_executor()};
like image 3
Victor Dyachenko Avatar answered Oct 19 '22 08:10

Victor Dyachenko


Since I don't have enough reputation points to comment, I write as an answer:

Using get_executor().context() did not work right away for me, but writing a macro did (see this answer)

like image 1
tropappar Avatar answered Oct 19 '22 06:10

tropappar