Reputation: 317
I've two classes (Negotiator, Client), both has their own boost::asio::ip::tcp::socket. Is there a way to transfer socket object to Client after negotiation is finished. I'm looking forward to do something like that:
boost::asio::ip::tcp::socket sock1(io);
//...
boost::asio::ip::tcp::socket sock2;
sock2.assign(sock1);
This operation must guarantee that the connection won't be closed when sock1 is destroyed.
Upvotes: 3
Views: 1503
Reputation: 16706
As of the current version of Boost, you would now get the handle with
boost::asio::ip::tcp::socket::my_socket;
auto my_handle = my_socket.native_handle();
instead of the old native()
member function.
Upvotes: 0
Reputation: 14148
I think that you could:
However:
Upvotes: 2
Reputation: 3635
Create the socket on the heap (new), and pass the pointer from the negotiator to the client.
Upvotes: 2