Boost logo

Boost Users :

Subject: Re: [Boost-users] Why does async_connect() call listen()?
From: Niklas Angare (li51ckf02_at_[hidden])
Date: 2014-07-01 18:33:52


"Nathaniel Fries" <nfries88_at_[hidden]> wrote:
>>
>> Niklas Angare <li51ckf02_at_[hidden]> wrote:
>>
>>> "Soren Dreijer" <dreijer_at_[hidden]> 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
 


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net