I have a boost socket doing an async_read_some
:
socket_.async_read_some(boost::asio::buffer(data_, max_length),
boost::bind(&Session::handle_read, this,
boost::asio::placeholders::error,
boost::asio::placeholders::bytes_transferred));
When my Session
class is deleted socket_.close()
is called. I thought this would cancel the async_read_some
and call Session::handle_read
with an error.
However this is not the case and looking at basic_socket.hpp
/// Close the socket.
/**
* This function is used to close the socket. Any asynchronous send, receive
* or connect operations will be cancelled immediately, and will complete
* with the boost::asio::error::operation_aborted error.
*
* @throws boost::system::system_error Thrown on failure. Note that, even if
* the function indicates an error, the underlying descriptor is closed.
*
* @note For portable behaviour with respect to graceful closure of a
* connected socket, call shutdown() before closing the socket.
*/
void close()
there is no mention of reads being cancelled. So my question is, how do I cancel the read so I can close the socket cleanly?