"Nathaniel Fries"
Niklas Angare
wrote: "Soren Dreijer"
wrote: 1. Asio calls listen() under the hood. Why does it do that when I'm just trying to make an outbound TCP connection?
The call is made by the class socket_select_interrupter. The socket it is calling listen() on is an internal one bound to 127.0.0.1. I believe the socket is set up so that a thread that is blocking on a call to ::select() (for example in io_service::run()), can be interrupted from another thread. This interruption is probably used when io_service::stop() is called for example.
I don't see why it is necessary in this case, since the calling thread is not doing work that needs to be interrupted in case of calling io_service::stop.
Soren said only that he calls async_connect(). Imagine he then calls io_service::run(). That thread is now blocked in a call to ::select() waiting for the connect to finish. If another thread then did anything with that io_service, such as another async call or indeed stop(), the original thread would have to be interrupted somehow. Regards, Niklas Angare