Skip to content

std.Io: implement file_read_streaming and file_write_streaming - #363

Merged
lalinsky merged 3 commits into
mainfrom
file-read-write-streaming
Apr 20, 2026
Merged

lalinsky merged 3 commits into
mainfrom
file-read-write-streaming

Conversation

@lalinsky

Copy link
Copy Markdown
Owner

Summary

  • Wire up the .file_read_streaming and .file_write_streaming arms of operateImpl via new fileReadStreamingImpl / fileWriteStreamingImpl helpers.
  • Both reuse the existing ev.PipeRead / ev.PipeWrite completions, which already perform readv/writev at the fd's current position (prep_readv/prep_writev with offset -1 on io_uring, plain readv/writev elsewhere) — no new backend ops needed.
  • Streaming reads convert a 0-byte OS result to error.EndOfStream, and remap BrokenPipe (not part of FileReadStreaming.Error) to Unexpected. Write error sets match up without remapping.

Test plan

  • ./check.sh --full — 425 tests pass on Linux.
  • ./check.sh --target x86_64-windows --wine --filter "file streaming" — tests skip cleanly on Windows (regular files can't do current-position I/O via the OVERLAPPED/IOCP path).
  • New test io: file streaming read advances position and reports EOF — three sequential reads returning 5, 5, then error.EndOfStream.
  • New test io: file streaming write advances position and appends — exercises header-only, multi-slice, and splat>1 writes, read back positionally.

…aming

Reuses the existing ev.PipeRead / ev.PipeWrite completions, which already
perform readv / writev at the fd's current position (prep_readv/prep_writev
with offset=-1 on io_uring, plain readv/writev elsewhere). For streaming
reads a 0-byte result is mapped to error.EndOfStream, and BrokenPipe (not in
FileReadStreaming.Error) is mapped to Unexpected.

Tests skip on Windows: regular files there can't do streaming I/O through
the OVERLAPPED/IOCP path without an explicit offset.
@coderabbitai

coderabbitai Bot commented Apr 20, 2026 •

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: c5fef1ca-873f-4afa-b240-8154325ab451

📥 Commits

Reviewing files that changed from the base of the PR and between 5fbf19c and b0c7373.

📒 Files selected for processing (1)
  • src/ev/backends/common.zig
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/ev/backends/common.zig

📝 Walkthrough

Walkthrough

Adds vectored streaming file I/O: new completion types and ops for FileReadStreaming/FileWriteStreaming, io_uring native support, thread-pool fallbacks wired across backends and blocking/pathways, and user-facing streaming read/write implementations and tests.

Changes

Cohort / File(s) Summary
Core completion types
src/ev/completion.zig, src/ev/root.zig
Added FileReadStreaming/FileWriteStreaming completion structs, new Op variants, backend capability flags, and re-exports from root. Updated mappings and non-blocking support checks.
Common handlers & blocking dispatch
src/ev/backends/common.zig, src/ev/blocking.zig
Implemented handleFileReadStreaming / handleFileWriteStreaming and fileReadStreamingWork / fileWriteStreamingWork; blocking mode dispatch now routes streaming ops to these handlers.
io_uring backend
src/ev/backends/io_uring.zig
Native support for streaming ops: advertise capabilities, prepare SQEs for readv/writev with offset -1, submit user_data, and convert results/errors into streaming completion results.
Other backends (thread-pool fallback classification)
src/ev/backends/epoll.zig, src/ev/backends/kqueue.zig, src/ev/backends/poll.zig, src/ev/backends/iocp.zig
Marked .file_read_streaming/.file_write_streaming as unreachable in these backends' submit switch so they fall back to the loop thread pool (no change to runtime behavior beyond classification).
Event loop integration
src/ev/loop.zig
Added cases in submitFileOpToThreadPool to submit streaming work via common.fileReadStreamingWork / common.fileWriteStreamingWork.
Public I/O implementation & tests
src/io.zig
Added fileReadStreamingImpl and fileWriteStreamingImpl to build iovecs, submit streaming completions, interpret EOF/broken-pipe semantics, and new tests for position advancement and EOF behavior (Windows skipped).

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

Poem

💧 Vectors march in iovecs wide,
SQEs hum where uring can ride,
If not, the pool will do the chore,
Bytes gather, scatter, then restore,
Small change — big paths open wide.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and accurately describes the main change: implementing file_read_streaming and file_write_streaming in std.Io, which matches the core objective across all modified files.
Description check ✅ Passed The description directly explains the implementation approach (wiring up operateImpl arms, reusing existing completions), key design decisions (no new backend ops), error handling specifics, and includes concrete test results with Windows compatibility notes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch file-read-write-streaming

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Streaming file I/O (reads/writes using the current file position) can't
use the pollable PipeRead/PipeWrite path, because regular files aren't
registerable with epoll/kqueue (EPERM). Dispatch dedicated ops that use
native io_uring prep_readv/prep_writev with offset=-1 on Linux and fall
back to the thread pool on other backends.

@coderabbitai coderabbitai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/ev/backends/common.zig`:
- Around line 150-168: The streaming handlers handleFileReadStreaming and
handleFileWriteStreaming must guard against using current-position I/O on
Windows: detect the Windows target (e.g., via comptime or
std.os.identifier/Windows build tag) at the start of each function and
immediately set the completion error to error.Unexpected
(c.setError(error.Unexpected)) and return, instead of calling
fs.readv/fs.writev; otherwise the code should continue to call
fs.readv/fs.writev as before. Update both functions to perform that OS check and
early-return error.Unexpected on Windows-only paths.
🪄 Autofix (Beta)

✅ Autofix completed


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: c6d7a71d-86db-4eff-b2e0-39f8ff670e04

📥 Commits

Reviewing files that changed from the base of the PR and between 6119a2e and 5fbf19c.

📒 Files selected for processing (11)
  • src/ev/backends/common.zig
  • src/ev/backends/epoll.zig
  • src/ev/backends/io_uring.zig
  • src/ev/backends/iocp.zig
  • src/ev/backends/kqueue.zig
  • src/ev/backends/poll.zig
  • src/ev/blocking.zig
  • src/ev/completion.zig
  • src/ev/loop.zig
  • src/ev/root.zig
  • src/io.zig

Comment thread src/ev/backends/common.zig Resolved
@coderabbitai

coderabbitai Bot commented Apr 20, 2026 •

Copy link
Copy Markdown
Contributor

Note

Autofix is a beta feature. Expect some limitations and changes as we gather feedback and continue to improve it.

Fixes Applied Successfully

Fixed 1 file(s) based on 1 unresolved review comment.

Files modified:

  • src/ev/backends/common.zig

Commit: b0c7373d27df7e476f928a5f1db4803506bf9f44

The changes have been pushed to the file-read-write-streaming branch.

Time taken: 2m 1s

Fixed 1 file(s) based on 1 unresolved review comment.

Co-authored-by: CodeRabbit <[email protected]>
@lalinsky
lalinsky merged commit be632e7 into main Apr 20, 2026
25 of 27 checks passed
@lalinsky
lalinsky deleted the file-read-write-streaming branch April 20, 2026 16:36
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.

1 participant