Menu

#32 Waiting on system sockets with epoll_wait is not working on OS X

v1.0_(example)
open
nobody
None
5
2013-06-13
2013-06-13
GuidoV
No

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

Discussion


Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.