Waiting on system sockets with epoll_wait is not working on OS X
Brought to you by:
lilyco
Waiting on system sockets with epoll_wait is not working on OS X because the wrong value for nfds is passed to select. On Windows the value for nfds is ignored but on Mac OS X it needs to be the highest socket number + 1, see:
https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man2/select.2.html
I fixed it with the follwing code in CEPoll::wait in epoll.cpp:
fd_set readfds; fd_set writefds; FD_ZERO(&readfds); FD_ZERO(&writefds); int nfds = 0; for (set<SYSSOCKET>::const_iterator i = p->second.m_sLocals.begin(); i != p->second.m_sLocals.end(); ++ i) { if (lrfds) FD_SET(*i, &readfds); if (lwfds) FD_SET(*i, &writefds); nfds = max(nfds, *i); } nfds++; timeval tv; tv.tv_sec = 0; tv.tv_usec = 0; if (::select(nfds, &readfds, &writefds, NULL, &tv) > 0)
Guido