Allows the user to poll or check a group of sockets for I/O
activity. It can check what sockets are ready to be read or written,
or what sockets have a pending exception.
As of OpenVMS Version 7.0, this routine can operate on any number
of sockets up to the limit of open files supported by the DEC C RTL
(65535 on OpenVMS Alpha; 2047 on OpenVMS VAX). However, for select
to use more than 32 sockets, the DEC TCP/IP Services for OpenVMS
used with the DEC C RTL must offer the same support.
Format
#include <socket.h>
int select (int nfds, int *readfds, int
*writefds, int *execptfds, struct
timeval *timeout);
Arguments
- nfds
- The highest numbered socket descriptor to search for. That is,
the highest numbered bit +1 in readfds, writefds,
and exceptfds that should be examined. Descriptor
s is represented by 1<< s (1 shifted to the left
s number of times).
- readfds
- A pointer to an array of bits, organized as integers (each
integer describing 32 descriptors), that should be examined for
read readiness. If bit n of the longword is set, socket
descriptor n will be checked to see if it is ready to
be read. All bits set in the bit mask must correspond to the file
descriptors of sockets. The select routine cannot be used on normal
files.
On return, the array of bits to which readfds points
contains a bit mask of the sockets that are ready for reading.
Only bits that are set on entry to select will be set on exit.
- writefds
- A pointer to a longword bit mask of the socket descriptors that
should be examined for write readiness. If bit n of the
longword is set, socket descriptor n will be checked to see
if it is ready to be written to. All bits set in the bit mask must
correspond to socket descriptors.
On return, the array of bits that writefds points to
contains a bit mask of the sockets that are ready for writing.
Only bits that are set on entry to select will be set on exit.
- exceptfds
- A pointer to a longword bit mask of the socket descriptors
that should be examined for exceptions. If bit n of the
longword is set, socket descriptor n will be checked to see
if it has any pending exceptions. All bits set in the bit mask must
correspond to the file descriptors of sockets.
On return, the array of bits pointer exceptfds contains a
bit mask of the sockets that have exceptions pending. Only bits that
are set on entry to select will be set on exit.
- timeout
- The length of time that select should examine the sockets
before returning. If one of the sockets specified in the
readfds, writefds, and exceptfds bit
masks is ready for I/O, select will return before the timeout period
has expired.
The timeout structure points to a timeval structure. See
<socket.h> for a description of the timeval structure.
Description
This routine determines the I/O status of the sockets
specified in the various mask arguments. It returns either when a
socket is ready to be read or written, or when the timeout
period expires. If timeout is a nonzero integer, it
specifies a maximum interval to wait for the selection to complete.
If the timeout argument is NULL, select will block
indefinitely. In order to effect a poll, timeout should
be non-NULL, and should point to a zero-valued structure.
If a process is blocked on a select while waiting for input from a
socket and the sending process closes the socket, the select notes
this as an event and will unblock the process. The descriptors
are always modified on return if select returns because of the
timeout.
- Note
- When the socket option SO_
OOBINLINE is set on the device_socket, a select on both read and
exception events returns the socket mask set on both the read and
exception mask. Otherwise, only the exception mask is set.
See also accept, connect, read, recv, recvfrom, recvmsg, send,
sendmsg, sendto, and write in this section.
Return Values
n | The number of sockets that were
ready for I/O or that had pending exceptions. This value matches the
number of returned bits that are set in all output masks. |
0 | Indicates that select timed out
before any socket became ready for I/O. |
-
1 | Indicates an error; errno is set to one of the
following values:
- EBADF - One of the bit masks specified an invalid
descriptor.
- EINVAL - The specified time limit is unacceptable. One of
its components is negative or too large.
|
Previous Page | Next Page | Table of Contents | Index