Skip to main content

Practice ยท 2 of 3

Read Exactly N Bytes

CHALLENGE
Difficulty: advanced+25 XP

POSIX. Implement ssize_t read_exact(int fd, void *buf, size_t n) โ€” loop recv until exactly n bytes are accumulated; return n, or -1 on EOF-before-complete (peer closed mid-message), error, or NULL/zero-argument misuse (n==0 returns 0 immediately). Partial data stays in buf on failure โ€” the tests only check return values.

Back to lesson: Practice: Socket Drills on Loopback