diff --git a/include/ylt/coro_io/coro_file.hpp b/include/ylt/coro_io/coro_file.hpp index 50d0634fa..99ac4d4b1 100644 --- a/include/ylt/coro_io/coro_file.hpp +++ b/include/ylt/coro_io/coro_file.hpp @@ -267,11 +267,11 @@ class coro_file { return true; } - async_simple::coro::Lazy> - async_read_some_at(uint64_t offset, char* data, size_t size) { + async_simple::coro::Lazy> async_read_at( + uint64_t offset, char* data, size_t size) { assert(stream_file_); - auto [ec, read_size] = co_await coro_io::async_read_some_at( + auto [ec, read_size] = co_await coro_io::async_read_at( offset, *reinterpret_cast(stream_file_.get()), asio::buffer(data, size)); @@ -284,11 +284,12 @@ class coro_file { co_return std::make_pair(std::error_code{}, read_size); } - async_simple::coro::Lazy async_write_some_at( - uint64_t offset, const char* data, size_t size) { + async_simple::coro::Lazy async_write_at(uint64_t offset, + const char* data, + size_t size) { assert(stream_file_); - auto [ec, write_size] = co_await coro_io::async_write_some_at( + auto [ec, write_size] = co_await coro_io::async_write_at( offset, *reinterpret_cast(stream_file_.get()), asio::buffer(data, size)); @@ -299,7 +300,7 @@ class coro_file { char* data, size_t size) { assert(stream_file_); - auto [ec, read_size] = co_await coro_io::async_read_some( + auto [ec, read_size] = co_await coro_io::async_read( *reinterpret_cast(stream_file_.get()), asio::buffer(data, size)); if (ec == asio::error::eof) { @@ -314,7 +315,7 @@ class coro_file { size_t size) { assert(stream_file_); - auto [ec, write_size] = co_await coro_io::async_write_some( + auto [ec, write_size] = co_await coro_io::async_write( *reinterpret_cast(stream_file_.get()), asio::buffer(data, size)); diff --git a/include/ylt/coro_io/coro_io.hpp b/include/ylt/coro_io/coro_io.hpp index 054b8377e..a7e4302f3 100644 --- a/include/ylt/coro_io/coro_io.hpp +++ b/include/ylt/coro_io/coro_io.hpp @@ -28,8 +28,10 @@ #include #include #include +#include #include #include +#include #include #include @@ -137,14 +139,13 @@ async_read_some(Socket &socket, AsioBuffer &&buffer) noexcept { template inline async_simple::coro::Lazy> -async_read_some_at(uint64_t offset, Socket &socket, - AsioBuffer &&buffer) noexcept { +async_read_at(uint64_t offset, Socket &socket, AsioBuffer &&buffer) noexcept { callback_awaitor> awaitor; co_return co_await awaitor.await_resume([&](auto handler) { - socket.async_read_some_at(offset, buffer, - [&, handler](const auto &ec, auto size) { - handler.set_value_then_resume(ec, size); - }); + asio::async_read_at(socket, offset, buffer, + [&, handler](const auto &ec, auto size) { + handler.set_value_then_resume(ec, size); + }); }); } @@ -208,14 +209,13 @@ async_write_some(Socket &socket, AsioBuffer &&buffer) noexcept { template inline async_simple::coro::Lazy> -async_write_some_at(uint64_t offset, Socket &socket, - AsioBuffer &&buffer) noexcept { +async_write_at(uint64_t offset, Socket &socket, AsioBuffer &&buffer) noexcept { callback_awaitor> awaitor; co_return co_await awaitor.await_resume([&](auto handler) { - socket.async_write_some_at(offset, buffer, - [&, handler](const auto &ec, auto size) { - handler.set_value_then_resume(ec, size); - }); + asio::async_write_at(socket, offset, buffer, + [&, handler](const auto &ec, auto size) { + handler.set_value_then_resume(ec, size); + }); }); } diff --git a/src/coro_io/tests/test_corofile.cpp b/src/coro_io/tests/test_corofile.cpp index 80a58147e..d6fea1264 100644 --- a/src/coro_io/tests/test_corofile.cpp +++ b/src/coro_io/tests/test_corofile.cpp @@ -107,23 +107,19 @@ TEST_CASE("coro_file pread and pwrite basic test") { CHECK(file.is_open()); char buf[100]; - auto pair = - async_simple::coro::syncAwait(file.async_read_some_at(0, buf, 10)); + auto pair = async_simple::coro::syncAwait(file.async_read_at(0, buf, 10)); CHECK(std::string_view(buf, pair.second) == "AAAAAAAAAA"); CHECK(!file.eof()); - pair = async_simple::coro::syncAwait(file.async_read_some_at(10, buf, 100)); + pair = async_simple::coro::syncAwait(file.async_read_at(10, buf, 100)); CHECK(!file.eof()); CHECK(pair.second == 100); - pair = - async_simple::coro::syncAwait(file.async_read_some_at(110, buf, 100)); - CHECK(!file.eof()); + pair = async_simple::coro::syncAwait(file.async_read_at(110, buf, 100)); CHECK(pair.second == 80); // only read size equal 0 is eof. - pair = - async_simple::coro::syncAwait(file.async_read_some_at(200, buf, 100)); + pair = async_simple::coro::syncAwait(file.async_read_at(200, buf, 100)); CHECK(file.eof()); CHECK(pair.second == 0); } @@ -137,21 +133,20 @@ TEST_CASE("coro_file pread and pwrite basic test") { std::string buf = "cccccccccc"; auto ec = async_simple::coro::syncAwait( - file.async_write_some_at(0, buf.data(), buf.size())); + file.async_write_at(0, buf.data(), buf.size())); CHECK(!ec); std::string buf1 = "dddddddddd"; ec = async_simple::coro::syncAwait( - file.async_write_some_at(10, buf1.data(), buf1.size())); + file.async_write_at(10, buf1.data(), buf1.size())); CHECK(!ec); char buf2[100]; - auto pair = - async_simple::coro::syncAwait(file.async_read_some_at(0, buf2, 10)); + auto pair = async_simple::coro::syncAwait(file.async_read_at(0, buf2, 10)); CHECK(!file.eof()); CHECK(std::string_view(buf2, pair.second) == "cccccccccc"); - pair = async_simple::coro::syncAwait(file.async_read_some_at(10, buf2, 10)); + pair = async_simple::coro::syncAwait(file.async_read_at(10, buf2, 10)); CHECK(!file.eof()); CHECK(std::string_view(buf2, pair.second) == "dddddddddd"); }