kqueues for Socket Monitoring
Like the signal handling API, the API for monitoring sockets and other file descriptors can be awkward and inefficient. select() is the function used most often on Mac OS X to determine the liveness of a socket (is it still connected?) and to see if there is any activity on a socket (can I read from it without blocking?)
The problem with select(), and its functionally equivalent counterpart poll(), is that it is a stateless call. Every time you call select() or poll() you have to tell the kernel what file descriptors you are interested in. The kernel then copies this list of descriptors into its own memory space, does whatever work it does to test for liveness and activity, and then copies stuff back to the program’s ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access