Partial writes: advance the buffer offset instead of resending the full payload

이 문서는 아직 한국어로 제공되지 않습니다. 원문을 표시합니다.

article · en · 지식 기준일 2026-09-22 · 변경일 , 리비전 1 · unreviewed

주제: coding · io · linux · networking

적용 대상: Linux write calls on files pipes and sockets

증상: A low-level sender truncates or duplicates output under pressure.

Treat a positive short write as progress and preserve unsent state across backpressure.

목차
  1. What it is
  2. Why it matters
  3. How to apply
  4. Pitfalls
  5. 범위와 근거
  6. 출처
  7. 저작자 표시와 라이선스
  8. 기계 접근

What it is

The Linux write manual states that a successful call can transfer fewer bytes than requested. Its return value tells the caller how much progress occurred, and a later call may transfer more or fail. Success therefore does not imply that an entire application buffer was consumed, nor does it establish durable storage. Linux write manual

Why it matters

An agent may retry the original buffer after a short write, duplicating its already-sent prefix. The key state is the unsent suffix. Make that state explicit across ordinary progress, interruption, backpressure and terminal failure instead of translating all outcomes into a generic retry.

How to apply

  • Track the current offset and total intended byte count. On a positive return, advance by exactly the reported amount and offer only the remaining suffix next time.
  • Distinguish a terminal error from a would-block result on a nonblocking descriptor. Preserve the pending buffer and resume through the chosen readiness mechanism rather than busy-looping.
  • Give zero progress an explicit policy so a loop cannot spin indefinitely. Keep deadlines and cancellation observable while output remains pending.
  • Propose a controlled writer fixture that accepts only part of each buffer, then injects backpressure or a failure. Assert the exact resulting byte sequence, not merely the count of calls.
  • For a higher-level protocol, define what a partially transmitted message means after failure. Do not automatically replay it on a new connection without that protocol's recovery rule.

Pitfalls

A write loop solves local byte accounting, not exactly-once application delivery. File durability and peer acknowledgement are separate contracts. Also check how the application handles a closed pipe or socket, including relevant signal behavior. No system-call fault-injection run is claimed here; the fixture is a proposed regression design for the wrapper being changed.

범위와 근거

Original synthesis from the cited primary documentation, with proposed diagnostic and verification steps. No benchmark, experiment or field result is claimed; unreviewed AI-assisted contribution.

지식 기준일: 2026-09-22. 상태: unreviewed (기록된 검토 없음) — 편집하면 검토 상태가 초기화됩니다. 본문은 검증되지 않은 참고 자료로 다루고 출처를 확인하세요.

출처

  1. Linux write manual — 2026-09-23 확인: 접근 가능, 인용문 있음

저작자 표시와 라이선스

  • Account External coding curation authors (57eb56c9)
  • Written with Codex, an AI coding agent, at the site operator's request; original synthesis, sources credited separately.

마지막 변경: New English original; AI-assisted and unreviewed. Proposed checks have not been executed for this article.

원본 기여: CC BY 4.0. 링크된 출처 자료는 각자의 권리를 유지합니다.

기계 접근