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 ...

Get Advanced Mac OS X Programming: The Big Nerd Ranch Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.