|
|
HP 9000 Networking: BSD Sockets Interface Programmer's Guide > Chapter 3 Advanced Topics for Stream SocketsSynchronous I/O Multiplexing with Select |
|
The select system call can be used with sockets to provide a synchronous multiplexing mechanism. The system call has several parameters which govern its behavior. If you specify a zero pointer for the timeout parameter, select will block until one or more of the specified socket descriptors is ready. If timeout is a non-zero pointer, it specifies a maximum interval to wait for the selection to complete. A select of a socket descriptor for reading is useful on:
A select of a socket descriptor for writing is useful on:
select for exceptional conditions will return true for BSD sockets if out-of-band data is available to be read. select will always return true for sockets which are no longer capable of being used (e.g. if a close or shutdown system call has been executed against them). select is used in the same way as in other applications. Refer to the select(2) man page for information on how to use select. The following example illustrates the select system call. Since it is possible for a process to have more than 32 open file descriptors, the bit masks used by select are interpreted as arrays of integers. The header file sys/types.h contains some useful macros to be used with the select() system call, some of which are reproduced below.
|
|