10

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?

Tanner Sansbury
  • 51,153
  • 9
  • 112
  • 169
Victor Dyachenko
  • 1,363
  • 8
  • 18

3 Answers3

7

You can use get_executor().context():

socket newSocket(existingSocket.get_executor().context()));
m.s.
  • 16,063
  • 7
  • 53
  • 88
3

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

socket new_socket{existing_socket.get_executor()};
Victor Dyachenko
  • 1,363
  • 8
  • 18
1

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)

tropappar
  • 141
  • 1
  • 5