|
Boost Users : |
Subject: Re: [Boost-users] Enhancing the boost::asio::connect() socket interface
From: Gavin Lambert (gavinl_at_[hidden])
Date: 2017-09-29 05:01:30
On 27/09/2017 19:03, Richard Hodges 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.
>
> I think the class template you're looking for is basic_raw_socket<>.
>
> http://www.boost.org/doc/libs/1_64_0/doc/html/boost_asio/reference/basic_raw_socket.html
No, basic_raw_socket is for raw sockets, ie. non TCP/IP ones.
Normally you'd use asio::ip::tcp::socket or asio::ip::udp::socket. They
contain connect() methods which will connect to a single endpoint and
will preserve a prior bind() call.
If all you want is to connect to a single endpoint, then just
s.bind()/s.connect() directly.
Only the free function asio::connect() supports multiple endpoints and
does the close()/connect() loop.
If you want to support multiple endpoints and also bind, then you'll
need to write your own close()/bind()/connect() loop similar to that.
(There are also corresponding async_connect() methods, which should be
preferred unless you really want to block the thread.)
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