>On Sun, Sep 24, 2017 at 1:15 AM, martin doc via Boost-users <boost-users@lists.boost.org> wrote:
> As boost::asio::connect() closes an open socket passed to it before making
> the remote connection, it's not possible to pass connect() a prebaked
> socket.
What makes you think that? My reading of the implementation is that
the socket is only closed when:
1. The range of addresses passed to connect() has more than one element, and
2. The connection attempt for the first address fails.
See:
<https://github.com/boostorg/asio/blob/ b002097359f246b7b1478775251dfb 153ab3ff4b/include/boost/asio/ impl/connect.hpp#L108
You can avoid the socket closure by only attempting to connect to one address.