HP Rp7410 BSD Sockets Interface Programmer's Guide - Page 72
Synchronous I/O Multiplexing with, Select
View all HP Rp7410 manuals
Add to My Manuals
Save this manual to your list of manuals |
Page 72 highlights
Advanced Topics for Stream Sockets Synchronous I/O Multiplexing with Select Synchronous 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 connected socket, because it determines when data have arrived and are ready to be read without blocking; use the FIONREAD parameter to the ioctl system call to determine exactly how much data are available. • A listening socket, because it determines when you can accept a connection without blocking. • Any socket to detect if an error has occurred on the socket. A select of a socket descriptor for writing is useful on: • A connecting socket, because it determines when a connection is complete. • A connected socket, because it determines when more data can be sent without blocking. This implies that at least one byte can be sent; there is no way, however, to determine exactly how many bytes can be sent. • Any socket to detect if an error has occurred on the socket. 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. 72 Chapter 3