More Advanced Issues

Multiplexing connections

A one-connection-at-a-time server like simpleserver is OK for some applications, but to truly leverage the power of networking, it is better to have a single server support many connections simultaneously. To do this, you need a way to multiplex multiple input and output streams and only block when there is no work to be done.

The select() call is the Berkeley sockets way of doing this multiplexing. You will see in Chapter 16: kqueue and FSEvents an alternate way of multiplexing connections, which is superior to select() in many ways, but it is not available on many platforms. Grand Central Dispatch also gives you a way to multiplex sockets.

For select(), you give it a set of file descriptors. If ...

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.