Systems-Level Programming: Worked Examples
Work through each trace before reading the explanation. Then solve the transfer task without the page open.
Example 1: One write need not finish the buffer
A caller wants to send ten bytes; the first write reports four. Retrying the full buffer duplicates the first four bytes. Advance an offset by the completed count and request the six remaining bytes.
Handle interruptions and nonblocking readiness according to the API contract. A zero-progress result must not create an infinite busy loop. “Write returned successfully” means the reported count completed; it is not a universal promise that the entire logical message was delivered or persisted.
Example 2: Descriptor leaks become load failures
A service opens a file per request and closes it only on success. A parsing error takes an early return and leaks the descriptor. The happy path passes, but enough malformed requests exhaust the process limit.
Give every acquired resource one cleanup path or structured lifetime owner. Test the failure immediately after acquisition. Ownership must survive all exits, not merely the last line of the function.
Transfer and self-check
Does successful write alone prove that bytes survived a power loss? Check: no; buffering and durability contracts are separate from completed byte transfer.
Evidence to keep
Save your first attempt, corrected reasoning, and transfer result as checkpoint evidence. A matching final answer without an explanation is insufficient. Continue with the guided lab and use the reading guide to repair a specific gap.