networking · beginner · ~15 min
Filter the epoll event array by a mask.
Count how many epoll event words carry a flag you care about.
Implement int count_matching(const unsigned *events, int n, unsigned mask).
events: array of n event bitmasks (as epoll_wait would fill).n: number of entries.mask: the bits of interest.Return how many entries have at least one bit of mask set (events[i] & mask is non-zero).
events = {1, 2, 1, 4}, mask = 1 -> 2
events = {1, 2, 1, 4}, mask = 8 -> 0
events: an array of n event bitmasks; mask: the bits of interest.
The number of entries where (events[i] & mask) is non-zero.
An entry matches if it shares any bit with mask.
int count_matching(const unsigned *events, int n, unsigned mask) {
/* TODO */
return 0;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.