Skip to content

refactor: add make_*/async_* co_await-able I/O API for files and networking#14

Closed
Copilot wants to merge 2 commits into
mainfrom
copilot/refactor-io-api
Closed

refactor: add make_*/async_* co_await-able I/O API for files and networking#14
Copilot wants to merge 2 commits into
mainfrom
copilot/refactor-io-api

Conversation

Copilot AI commented May 19, 2026

Copy link
Copy Markdown
Contributor

Summary

Exposes a coroutine-friendly async I/O surface over the existing file and networking primitives, enabling co_await-based usage without blocking task threads.

Changes

New public headers

  • include/net.hpp — canonical replacement for networking.hpp (which becomes a backward-compat #include shim). Adds:
    • virtual make_read(uint32_t) / make_write(const char*, uint32_t) to tcp_network_stream and tcp_network_blocking
    • non-virtual make_accept(bool) to tcp_network_server
    • #include "future.hpp" so callers get future_ptr<T> in scope
  • include/coroutine/net.hpp — thin async_read, async_write, async_accept wrappers returning future_ptr<T> that can be directly co_awaited
  • include/coroutine/file.hppasync_read, async_read_at, async_read_fixed, async_read_fixed_at, async_write, async_write_at, async_append wrappers over file_handle

Modified files

  • include/networking.hpp — reduced to #include "net.hpp" shim for backward compatibility
  • include/files.hpp — added make_read, make_read_at, make_read_fixed, make_read_fixed_at, make_write, make_write_at, make_append declarations on file_handle
  • src/files.cpp — thin delegating implementations of all file_handle::make_*
  • src/networking.cppmake_read/make_write implemented in all four concrete classes (Windows stream, Windows blocking, Linux stream, Linux blocking); tcp_network_server::make_accept wraps accept_blocking in a future

Usage example

#include <coroutine/net.hpp>
#include <coroutine/file.hpp>

fast_task::task_auto_start_coro<void> handle(fast_task::networking::tcp_network_blocking& conn) {
    auto data = co_await fast_task::async_read(conn, 1024);
    co_await fast_task::async_write(conn, data.data(), (uint32_t)data.size());
}

fast_task::task_auto_start_coro<void> server_loop(fast_task::networking::tcp_network_server& srv) {
    auto* client = co_await fast_task::async_accept(srv);
    // client is tcp_network_blocking*, caller owns it
}

fast_task::task_auto_start_coro<void> read_file(fast_task::files::file_handle& f) {
    auto bytes = co_await fast_task::async_read(f, 4096);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants