De-dup {read,write}-all code#221
Merged
jserv merged 1 commit intoJul 19, 2026
Merged
Conversation
jserv
reviewed
Jul 17, 2026
jserv
left a comment
Contributor
There was a problem hiding this comment.
Enforce https://cbea.ms/git-commit/
Subject: De-dup {read,write}-all code
henrybear327
force-pushed
the
refactor/write_all_and_read_all
branch
from
July 18, 2026 14:27
03b675f to
cc2c2be
Compare
Contributor
Cubic summarizes as below, that can be appended to git commit messages.
|
Contributor
|
Avoid single-line git commit messages. |
henrybear327
force-pushed
the
refactor/write_all_and_read_all
branch
from
July 18, 2026 18:29
cc2c2be to
46026a2
Compare
jserv
requested changes
Jul 18, 2026
jserv
left a comment
Contributor
There was a problem hiding this comment.
Rebase and resolve conflicts.
rosetta.c, gdbstub-rsp.c, and fork-state.c each open-coded their own short-write/EINTR-tolerant loop for reading or writing a fixed buffer to a blocking fd. The copies diverged on the edge cases: some spun on a zero write return, some treated EOF as a hard error, some swallowed it. Centralize the behavior in two helpers in src/utils.h: write_all(fd, buf, len) writes exactly len bytes, resuming across short writes and EINTR, and turns an unexpected zero return into EIO so a blocking fd can never spin with a stuck offset. read_all(fd, buf, len, eof_is_error) reads exactly len bytes with the same loop discipline, but takes an eof_is_error flag so a clean EOF can either fail (protocol framing in fork-state.c) or return the partial count (the rosetta digest read). The call sites are rewritten to the helpers. Behavior is unchanged except that the formerly divergent zero-return and EOF handling now follows the single helper definition.
henrybear327
force-pushed
the
refactor/write_all_and_read_all
branch
from
July 18, 2026 21:39
46026a2 to
0dec58a
Compare
Collaborator
Author
Done. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary by cubic
Consolidates read/write loops into
write_allandread_allinsrc/utils.hand adopts them across the codebase for consistent blocking I/O. Unifies EINTR, short I/O, zero-write, and EOF handling.write_all/read_all: resumes on EINTR/short I/O;write_alltreats zero write as EIO;read_allreturns -1 on EOF wheneof_is_error=true, else returns bytes read.src/core/rosetta.c(digest read usesread_all(..., false)),src/debug/gdbstub-rsp.c(byte send useswrite_all), andsrc/runtime/fork-state.c(IPC read usesread_all(..., true)); write paths now usewrite_all.rosettad_*_full); behavior stays the same with unified zero-write and EOF semantics.Written for commit 0dec58a. Summary will update on new commits.