Synchronous I/O Multiplexing With Select - HP Rp3440-4 - 9000 - 0 MB RAM Programmer's Manual

Bsd sockets interface programmer’s guide
Hide thumbs Also See for Rp3440-4 - 9000 - 0 MB RAM:
Table of Contents

Advertisement

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

Advertisement

Table of Contents
loading

Table of Contents