Fixes a use-after destroy when shutdown() is called from the base class
execution_context destructor, and this in turns triggers the destruction
of outstanding work objects.
The value of user_data in a submission queue entry is only initialized
with with the ring itself, remaining unchanged after use and even
through calls to io_uring_get_sqe(3). Many submission paths apply
io_uring_sqe_set_data(3) but the remainder are submitted with stale
values that can apply completion operations on the wrong queues with the
wrong results, causing obscure bugs.
The _buf literal suffix, defined in namespace asio::buffer_literals, may
be used to create const_buffer objects from string, binary integer, and
hexadecimal integer literals. These buffer literals may be arbitrarily
long. For example:
using namespace asio::buffer_literals;
asio::const_buffer b1 = "hello"_buf;
asio::const_buffer b2 = 0xdeadbeef_buf;
asio::const_buffer b3 = 0x01234567'89abcdef'01234567'89abcdef_buf;
asio::const_buffer b4 = 0b1010101011001100_buf;
The memory associated with a buffer literal is valid for the lifetime of
the program. This means that the buffer can be safely used with
asynchronous operations:
async_write(my_socket, "hello"_buf, my_handler);
When a completion handler for spawn() or co_spawn() uses a specified
(i.e. non-default) associated executor, cancellation handlers need to
be dispatched to the executor that was passed to spawn() or co_spawn().
This means that use_coro does not return a coro object, just like
use_awaitable does, i.e. it's an overhead that buys us type erasure.
Allocators can now be set for coro by including allocator_arg in the
coro signature.
When calling handle->release(), Asio uses kernel-provided
NtSetInformationFile() routine to remove IOCP for the specific handle.
Since this routine is not part of SDK, Asio retrieves the address of
that function from NTDLL.DLL and caches it into nt_set_info_ class
member. The fact that address is cached is checked by comparing it to 0.
The bug is that class member is not initialized and contains undefined
value, so Asio assumes that the address is already retrieved and uses
undefined value, which leads to acces violation.
Fix by initializing nt_set_info_ to zero, as it is done for sockets in
win_iocp_socket_service_base.ipp.
Added new overloads of experimental::make_parallel_group that may be used
to launch a dynamically-sized set of asynchronous operations, where all
operations are the same type. For example:
using op_type = decltype(
socket1.async_read_some(
boost::asio::buffer(data1),
boost::asio::deferred
)
);
std::vector<op_type> ops;
ops.push_back(
socket1.async_read_some(
boost::asio::buffer(data1),
boost::asio::deferred
)
);
ops.push_back(
socket2.async_read_some(
boost::asio::buffer(data2),
boost::asio::deferred
)
);
boost::asio::experimental::make_parallel_group(ops).async_wait(
boost::asio::experimental::wait_for_all(),
[](
std::vector<std::size_t> completion_order,
std::vector<boost::system::error_code> e,
std::vector<std::size_t> n
)
{
for (std::size_t i = 0; i < completion_order.size(); ++i)
{
std::size_t idx = completion_order[i];
std::cout << "socket " << idx << " finished: ";
std::cout << e[idx] << ", " << n[idx] << "\n";
}
}
);
Thanks go to Klemens Morgenstern for supplying part of this implementation.