O'Reilly logo

Advanced Mac OS X Programming: The Big Nerd Ranch Guide by Mark Dalrymple

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required