networking · beginner · ~15 min
Bound the epoll_wait maxevents.
Clamp a requested maxevents value into a safe range for epoll_wait.
Implement int cap_maxevents(int requested, int cap).
requested: the caller's desired maxevents.cap: the maximum allowed value.Return requested clamped to the range [1, cap]: at least 1, never more than cap.
cap_maxevents(16, 64) -> 16
cap_maxevents(100, 64) -> 64 (capped)
cap_maxevents(0, 64) -> 1 (floored at 1)
requested below 1 returns 1.requested: the desired maxevents; cap: the maximum allowed.
requested clamped to [1, cap].
Floor at 1, cap at cap.
int cap_maxevents(int requested, int cap) {
/* TODO */
return 1;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.