From 510488c6575c9bd05aeee4f8b4448a91bbaf2538 Mon Sep 17 00:00:00 2001 From: wokron Date: Fri, 21 Aug 2026 14:06:12 +0800 Subject: [PATCH 1/2] async_{read,write} support flags --- include/condy/async_operations.hpp | 26 ++++++++++++----------- include/condy/detail/async_operations.hpp | 26 +++++++++++++++++++++++ 2 files changed, 40 insertions(+), 12 deletions(-) diff --git a/include/condy/async_operations.hpp b/include/condy/async_operations.hpp index 58341cf6..f2f23baa 100644 --- a/include/condy/async_operations.hpp +++ b/include/condy/async_operations.hpp @@ -350,9 +350,9 @@ inline auto async_close(detail::FixedFd fd) { * @brief See io_uring_prep_read */ template -inline auto async_read(Fd fd, const Buffer &buf, __u64 offset) { - auto op = detail::make_op_awaiter(io_uring_prep_read, fd, buf.data(), - buf.size(), offset); +inline auto async_read(Fd fd, const Buffer &buf, __u64 offset, int flags = 0) { + auto op = detail::make_op_awaiter(detail::prep_read, fd, buf.data(), + buf.size(), offset, flags); return detail::maybe_flag_fixed_fd(std::move(op), fd); } @@ -360,10 +360,11 @@ inline auto async_read(Fd fd, const Buffer &buf, __u64 offset) { * @brief See io_uring_prep_read_fixed */ template -inline auto async_read(Fd fd, detail::FixedBuffer buf, __u64 offset) { +inline auto async_read(Fd fd, detail::FixedBuffer buf, __u64 offset, + int flags = 0) { auto op = - detail::make_op_awaiter(io_uring_prep_read_fixed, fd, buf.value.data(), - buf.value.size(), offset, buf.buf_index); + detail::make_op_awaiter(detail::prep_read_fixed, fd, buf.value.data(), + buf.value.size(), offset, flags, buf.buf_index); return detail::maybe_flag_fixed_fd(std::move(op), fd); } @@ -396,9 +397,9 @@ inline auto async_read_multishot(Fd fd, Buffer &buf, __u64 offset, * @brief See io_uring_prep_write */ template -inline auto async_write(Fd fd, const Buffer &buf, __u64 offset) { - auto op = detail::make_op_awaiter(io_uring_prep_write, fd, buf.data(), - buf.size(), offset); +inline auto async_write(Fd fd, const Buffer &buf, __u64 offset, int flags = 0) { + auto op = detail::make_op_awaiter(detail::prep_write, fd, buf.data(), + buf.size(), offset, flags); return detail::maybe_flag_fixed_fd(std::move(op), fd); } @@ -406,10 +407,11 @@ inline auto async_write(Fd fd, const Buffer &buf, __u64 offset) { * @brief See io_uring_prep_write_fixed */ template -inline auto async_write(Fd fd, detail::FixedBuffer buf, __u64 offset) { +inline auto async_write(Fd fd, detail::FixedBuffer buf, __u64 offset, + int flags = 0) { auto op = - detail::make_op_awaiter(io_uring_prep_write_fixed, fd, buf.value.data(), - buf.value.size(), offset, buf.buf_index); + detail::make_op_awaiter(detail::prep_write_fixed, fd, buf.value.data(), + buf.value.size(), offset, flags, buf.buf_index); return detail::maybe_flag_fixed_fd(std::move(op), fd); } diff --git a/include/condy/detail/async_operations.hpp b/include/condy/detail/async_operations.hpp index 4151939b..62badd52 100644 --- a/include/condy/detail/async_operations.hpp +++ b/include/condy/detail/async_operations.hpp @@ -221,5 +221,31 @@ inline void prep_recv_zc_multishot(io_uring_sqe *sqe, int fd, } #endif +inline void prep_read(io_uring_sqe *sqe, int fd, void *buf, unsigned nbytes, + __u64 offset, int flags) noexcept { + io_uring_prep_read(sqe, fd, buf, nbytes, offset); + sqe->rw_flags = flags; +} + +inline void prep_read_fixed(io_uring_sqe *sqe, int fd, void *buf, + unsigned nbytes, __u64 offset, int flags, + int buf_index) noexcept { + io_uring_prep_read_fixed(sqe, fd, buf, nbytes, offset, buf_index); + sqe->rw_flags = flags; +} + +inline void prep_write(io_uring_sqe *sqe, int fd, const void *buf, + unsigned nbytes, __u64 offset, int flags) noexcept { + io_uring_prep_write(sqe, fd, buf, nbytes, offset); + sqe->rw_flags = flags; +} + +inline void prep_write_fixed(io_uring_sqe *sqe, int fd, const void *buf, + unsigned nbytes, __u64 offset, int flags, + int buf_index) noexcept { + io_uring_prep_write_fixed(sqe, fd, buf, nbytes, offset, buf_index); + sqe->rw_flags = flags; +} + } // namespace detail } // namespace condy \ No newline at end of file From 940d5d86dce61a111bdf5f555db99e9bccba7dc8 Mon Sep 17 00:00:00 2001 From: wokron Date: Fri, 21 Aug 2026 14:06:20 +0800 Subject: [PATCH 2/2] add rw_flags test --- tests/test_async_operations.1.cpp | 43 +++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/tests/test_async_operations.1.cpp b/tests/test_async_operations.1.cpp index 718fe25a..4367ba94 100644 --- a/tests/test_async_operations.1.cpp +++ b/tests/test_async_operations.1.cpp @@ -251,6 +251,26 @@ TEST_CASE("test async_operations - read incr provided buffer") { } #endif +TEST_CASE("test async_operations - test read - rw_flags") { + int pipe_fds[2]; + REQUIRE(pipe(pipe_fds) == 0); + + int fl = fcntl(pipe_fds[0], F_GETFL, 0); + REQUIRE(fl >= 0); + REQUIRE(fcntl(pipe_fds[0], F_SETFL, fl | O_NONBLOCK) == 0); + + auto func = [&]() -> condy::Coro { + char buf[64] = {0}; + ssize_t n = co_await condy::async_read( + pipe_fds[0], condy::buffer(buf, 64), 0, RWF_NOWAIT); + REQUIRE(n == -EAGAIN); + }; + condy::sync_wait(func()); + + close(pipe_fds[0]); + close(pipe_fds[1]); +} + #if CONDY_URING_VERSION_GE(2, 8) // >= 2.8 TEST_CASE("test async_operations - provided buffer queue check - incr") { int sv[2]; @@ -723,6 +743,29 @@ TEST_CASE("test async_operations - writev fixed buffer") { } #endif +TEST_CASE("test async_operations - test write - rw_flags") { + int pipe_fds[2]; + REQUIRE(pipe(pipe_fds) == 0); + + const char *msg = "Hello, condy write dsync!"; + size_t msg_len = std::strlen(msg); + + auto func = [&]() -> condy::Coro { + ssize_t n = co_await condy::async_write( + pipe_fds[1], condy::buffer(msg, msg_len), 0, RWF_DSYNC); + REQUIRE(n == static_cast(msg_len)); + }; + condy::sync_wait(func()); + + char read_buf[64]; + ssize_t n = ::read(pipe_fds[0], read_buf, sizeof(read_buf)); + REQUIRE(n == static_cast(msg_len)); + REQUIRE(std::memcmp(read_buf, msg, msg_len) == 0); + + close(pipe_fds[0]); + close(pipe_fds[1]); +} + #if CONDY_URING_VERSION_GE(2, 7) // >= 2.7 TEST_CASE("test async_operations - send provided buffer") { int sv[2];