linux-sysprog · beginner · ~15 min

Would the write block?

Reason about pipe back-pressure.

Challenge

A pipe has a fixed capacity. Implement int write_would_block(int inflight, int capacity, int n) returning 1 if writing n more bytes would exceed capacity (inflight + n > capacity), else 0.

Starter code

int write_would_block(int inflight, int capacity, int n) {
    /* TODO */
    return 0;
}

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