networking · intermediate · ~15 min

Would the call have blocked?

Detect the would-block condition.

Challenge

On a non-blocking socket, a not-ready operation returns -1 with errno EAGAIN/EWOULDBLOCK. Implement int would_block(int rc, int err, int eagain) returning 1 if rc < 0 && err == eagain, else 0.

Starter code

int would_block(int rc, int err, int eagain) {
    /* TODO */
    return 0;
}

Solve this exercise in the browser editor — compile and run against the test harness, no setup required.