- Linux 6.0+
- Asio 1.30.2
- C++ 20 с сопрограммами
- Можно ли подключиться к экземпляру io_uring через asio::stream_file::get_executor()? Если да, то как я могу использовать функции io_uring_prep_* для настройки sqe и заставить службу поддержки возобновить правильную сопрограмму?
- Если экземпляр Asio отключен/ недоступен, можно настроить другое кольцо и eventfd для интеграции с asio::posix::descriptor. Как можно манипулировать несколькими приостановленными сопрограммами, возобновляя нужную при обработке cqe?
Пример кода
#include#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using tcp = asio::ip::tcp;
asio::awaitable handler(tcp::socket s)
{
asio::stream_file f(co_await asio::this_coro::executor);
// auto sqe = ::io_uring_get_sqe(&ring);
// ::io_uring_prep_openat(sqe, AT_FDCWD, "/etc/hostname", O_RDONLY, 0);
// ::io_uring_submit(&ring);
// ::io_uring_wait_cqe(&ring, &cqe);
// f.assign(cqe->res, asio::stream_file::read_only);
// ::io_uring_cqe_seen(&ring, cqe);
// co_await ...
f.open("/etc/hostname", asio::stream_file::read_only); // replace this blocking open with the io_ring stuff above
auto msg = std::format("/etc/hostname is {} bytes\n", f.size());
co_await asio::async_write(s, asio::buffer(msg), asio::use_awaitable);
f.close();
s.close();
}
asio::awaitable listener()
{
auto executor = co_await asio::this_coro::executor;
tcp::acceptor acceptor(executor, {tcp::v6(), 8080});
for (;;)
{
auto socket = co_await acceptor.async_accept(asio::use_awaitable);
asio::co_spawn(executor, handler(std::move(socket)), asio::detached);
}
}
int main()
{
asio::io_context ctx(1);
asio::signal_set signals(ctx, SIGINT, SIGTERM);
signals.async_wait([&](auto, auto){ ctx.stop(); });
asio::co_spawn(ctx, listener(), asio::detached);
ctx.run();
return 0;
}
Подробнее здесь: https://stackoverflow.com/questions/791 ... o-on-linux
Мобильная версия