@ammarfaizi2@gnuweeb.org @Suiseiseki@freesoftwareextremist.com @marcelschmall@infosec.exchange the retval from poll can help optimize the traversal as it indicates the number of ready file descriptors.
I know it is still not as efficient as epoll, but if you find all ready fds earlier, you can break the iteration earlier too:
ready_fds = poll(fds, 10000, -1);
if (ready_fds < 0) {
handle_error(ready_fds);
return;
}
for (i = 0; i < 10000; i++) {
if (ready_fds == 0) {
// All ready fds have been handled.
// Break out of the loop early to
// avoid unnecessary iterations.
break;
}
if (fds[i].revents & (POLLIN|POLLOUT)) {
handle_events(i, fds[i]);
ready_fds--;
}
}
If you are lucky: that one client is not in the last index, you can break earlier.