My client application uses a boost::asio::ip::tcp::socket to connect to a remote server.
If the app loses connection to this server (e.g. due to the server cras
Since C++11 you can write:
decltype(socket)(std::move(socket));
// reconnect socket.
The above creates a local instance of socket's type move constructing it from socket.
Before the next line, the unnamed local instance is destructed, leaving socket in a "freshly constructed from io_service" state.
See: https://www.boost.org/doc/libs/1_63_0/doc/html/boost_asio/reference.html#boost_asio.reference.basic_stream_socket.basic_stream_socket.overload5