networking · beginner · ~15 min
Verify the assembled message length.
After a recv loop, you have a list of how many bytes each recv returned. Confirm you reassembled the full message by summing those counts and comparing to the expected length.
Implement int all_received(const int *per_read, int n, int expected) that returns 1 if the sum of the first n entries of per_read equals expected, otherwise 0.
per_read: the per-recv byte counts.n: number of entries.expected: the expected total length.Returns 1 if the counts sum to expected, else 0.
all_received({256,256,256,232}, 4, 1000) -> 1
all_received({100,100}, 2, 300) -> 0
An int array per_read of per-recv counts, its length n, and the expected total.
1 if the per_read counts sum to expected, else 0.
Sum per_read[0..n-1] and compare to expected.
int all_received(const int *per_read, int n, int expected) {
/* TODO */
return 0;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.