networking · beginner · ~15 min

Reads needed for a response

Estimate the recv-loop iteration count.

Challenge

If a client reads at most chunk bytes per recv, implement int reads_needed(int total, int chunk) returning how many recv calls are needed (ceiling), 0 if chunk <= 0.

Starter code

int reads_needed(int total, int chunk) {
    /* TODO */
    return 0;
}

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