Using BOOST 1.89 with BOOST_ASIO_HAS_IO_URING on Linux

Added the following to the common section of CMake:

add_definitions("-DBOOST_ASIO_HAS_IO_URING")

and the following to the project section:

find_library(URING_LIB uring)
target_link_libraries(${TEST_TARGET} PRIVATE ${URING_LIB})

and the following to C++ code:

#ifndef BOOST_ASIO_HAS_IO_URING
#error "boost::asio::stream_file does not compile without BOOST_ASIO_HAS_IO_URING."
#endif

and the following code started to compile:

#include <boost/asio/stream_file.hpp>

namespace asio = boost::asio;

awaitable<void> read(const std::string& file_path)
{
    print(std::format("Thread {}. read() has started.", std::this_thread::get_id()));

    asio::any_io_executor exec = co_await asio::this_coro::executor;

    asio::stream_file source(exec);
    source.open(file_path, asio::stream_file::read_only);

    co_return;
}

Leave a Reply

Your email address will not be published. Required fields are marked *