Skip to content

De-dup {read,write}-all code#221

Merged
jserv merged 1 commit into
sysprog21:mainfrom
henrybear327:refactor/write_all_and_read_all
Jul 19, 2026
Merged

De-dup {read,write}-all code#221
jserv merged 1 commit into
sysprog21:mainfrom
henrybear327:refactor/write_all_and_read_all

Conversation

@henrybear327

@henrybear327 henrybear327 commented Jul 17, 2026

Copy link
Copy Markdown
Collaborator

Summary by cubic

Consolidates read/write loops into write_all and read_all in src/utils.h and adopts them across the codebase for consistent blocking I/O. Unifies EINTR, short I/O, zero-write, and EOF handling.

  • Refactors
    • Added write_all/read_all: resumes on EINTR/short I/O; write_all treats zero write as EIO; read_all returns -1 on EOF when eof_is_error=true, else returns bytes read.
    • Replaced custom loops in src/core/rosetta.c (digest read uses read_all(..., false)), src/debug/gdbstub-rsp.c (byte send uses write_all), and src/runtime/fork-state.c (IPC read uses read_all(..., true)); write paths now use write_all.
    • Removed duplicated helpers (rosettad_*_full); behavior stays the same with unified zero-write and EOF semantics.

Written for commit 0dec58a. Summary will update on new commits.

Review in cubic

@henrybear327
henrybear327 requested a review from jserv July 17, 2026 21:18

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

No issues found across 4 files

Re-trigger cubic

@jserv jserv 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.

Enforce https://cbea.ms/git-commit/

Subject: De-dup {read,write}-all code

@henrybear327 henrybear327 changed the title Refactor duplicated read-all/write-all code De-dup {read,write}-all code Jul 18, 2026
@henrybear327
henrybear327 force-pushed the refactor/write_all_and_read_all branch from 03b675f to cc2c2be Compare July 18, 2026 14:27
@jserv

jserv commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

Enforce https://cbea.ms/git-commit/

Cubic summarizes as below, that can be appended to git commit messages.

Consolidates read/write loops into write_all and read_all helpers in src/utils.h and adopts them across the codebase for consistent, robust blocking I/O. Removes duplicated code and standardizes EINTR, short I/O, zero-write, and EOF handling.

@henrybear327
henrybear327 requested a review from jserv July 18, 2026 14:31
@jserv

jserv commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

Avoid single-line git commit messages.

@henrybear327
henrybear327 force-pushed the refactor/write_all_and_read_all branch from cc2c2be to 46026a2 Compare July 18, 2026 18:29

@jserv jserv 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.

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
henrybear327 force-pushed the refactor/write_all_and_read_all branch from 46026a2 to 0dec58a Compare July 18, 2026 21:39
@henrybear327
henrybear327 requested a review from jserv July 18, 2026 21:40
@henrybear327

Copy link
Copy Markdown
Collaborator Author

Rebase and resolve conflicts.

Done.

@jserv
jserv merged commit b718b09 into sysprog21:main Jul 19, 2026
10 checks passed
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