networking · beginner · ~15 min
Scan poll results for ready fds.
After a poll() call, each watched fd has a revents value where 0 means "nothing happened". Count how many fds are ready.
Implement int count_ready(const int *revents, int n) that returns how many of the first n entries in revents are non-zero.
revents: array of per-fd result masks.n: number of entries.Returns the count of non-zero entries.
count_ready({0,1,0,4,0}, 5) -> 2
count_ready({0,0}, 2) -> 0
An int array revents and its length n.
The number of non-zero entries in revents[0..n-1].
A non-zero revents value means that fd is ready.
int count_ready(const int *revents, int n) {
/* TODO */
return 0;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.