Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
qicosmos committed Dec 1, 2023
1 parent 082da96 commit 487b2a8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
8 changes: 4 additions & 4 deletions include/ylt/coro_io/coro_file.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,14 +306,14 @@ class coro_file {
co_return std::make_pair(ec, op_size);
}

async_simple::coro::Lazy<std::pair<std::error_code, size_t>> async_read(
async_simple::coro::Lazy<std::pair<std::error_code, size_t>> async_pread(
size_t offset, char* data, size_t size) {
co_return co_await async_prw(pread, true, offset, data, size);
}

async_simple::coro::Lazy<std::error_code> async_write(size_t offset,
const char* data,
size_t size) {
async_simple::coro::Lazy<std::error_code> async_pwrite(size_t offset,
const char* data,
size_t size) {
auto result = co_await async_prw(pwrite, false, offset, (char*)data, size);
co_return result.first;
}
Expand Down
16 changes: 8 additions & 8 deletions src/coro_io/tests/test_corofile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,20 +80,20 @@ 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(0, buf, 10));
auto pair = async_simple::coro::syncAwait(file.async_pread(0, buf, 10));
CHECK(std::string_view(buf, pair.second) == "AAAAAAAAAA");
CHECK(!file.eof());

pair = async_simple::coro::syncAwait(file.async_read(10, buf, 100));
pair = async_simple::coro::syncAwait(file.async_pread(10, buf, 100));
CHECK(!file.eof());
CHECK(pair.second == 100);

pair = async_simple::coro::syncAwait(file.async_read(110, buf, 100));
pair = async_simple::coro::syncAwait(file.async_pread(110, buf, 100));
CHECK(!file.eof());
CHECK(pair.second == 80);

// only read size equal 0 is eof.
pair = async_simple::coro::syncAwait(file.async_read(200, buf, 100));
pair = async_simple::coro::syncAwait(file.async_pread(200, buf, 100));
CHECK(file.eof());
CHECK(pair.second == 0);
}
Expand All @@ -107,20 +107,20 @@ TEST_CASE("coro_file pread and pwrite basic test") {

std::string buf = "cccccccccc";
auto ec = async_simple::coro::syncAwait(
file.async_write(0, buf.data(), buf.size()));
file.async_pwrite(0, buf.data(), buf.size()));
CHECK(!ec);

std::string buf1 = "dddddddddd";
ec = async_simple::coro::syncAwait(
file.async_write(10, buf1.data(), buf1.size()));
file.async_pwrite(10, buf1.data(), buf1.size()));
CHECK(!ec);

char buf2[100];
auto pair = async_simple::coro::syncAwait(file.async_read(0, buf2, 10));
auto pair = async_simple::coro::syncAwait(file.async_pread(0, buf2, 10));
CHECK(!file.eof());
CHECK(std::string_view(buf2, pair.second) == "cccccccccc");

pair = async_simple::coro::syncAwait(file.async_read(10, buf2, 10));
pair = async_simple::coro::syncAwait(file.async_pread(10, buf2, 10));
CHECK(!file.eof());
CHECK(std::string_view(buf2, pair.second) == "dddddddddd");
}
Expand Down

0 comments on commit 487b2a8

Please sign in to comment.