Suppose we have ip::tcp::socket
and asynchronous operations, and at some point we call ip::tcp::socket::cancel
. Is it guaranteed that all asynchronous operations will be cancelled? The documentation for cancel
says that
When running on Windows Vista, Windows Server 2008, and later, the CancelIoEx function is always used. https://www.boost.org/doc/libs/1_66_0/doc/html/boost_asio/reference/basic_stream_socket/cancel/overload1.html
However, in the book "Windows 10 System Programming, Part 1" in the section I/O Cancellation
it says the following
In any case, canceling an I/O operation is not guaranteed to succeed.
The thing is that in the documentation of CancelIoEx
I don't find that cancellation is not guaranteed, but the book says so. So I'm not sure.
So is cancellation guaranteed when calling ip::tcp::socket::cancel
on Windows 10+ or not? If not, what solution can you recommend?
UPDATE
I'm also wondering, if I've already put data into the socket buffer and then call CancelIoEx
, will it cancel the sending?
This seems to me to be a confusion of semantics.
Of course, whether "cancellation succeeds" depends on whether the operation was still pending (e.g. in kernel/driver).
Regarding your Asio question, cancellation always works in the sense that
asio::error::operation_aborted