我有一个升压插座在做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));
当我的Session
类被删除时socket_.close()
被调用。我认为这会取消async_read_some
and 调用Session::handle_read
并出现错误。
然而事实并非如此,查看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()
没有提到读取被取消。所以我的问题是,如何取消读取以便我可以干净地关闭套接字?