select.2 (2010 09)
s
select(2) select(2)
The use of a timeout does not affect any pending timers set up by
alarm(), ualarm(),orsetiti-
mer().
On successful completion, the object pointed to by the timeout argument of
select() may be modified.
The
FD_SETSIZE is used in the definition of
fd_set structure. It is set to a value of 2048 to accommo-
date 2048 file descriptors. Any user code that uses
FD_SETSIZE or the structure fd_set should
redefine
FD_SETSIZE to a smaller value (greater than or equal to the number of open files the process
will have) in order to save space and execution time. Similarly, any user code that wants to test more
than 2048 file descriptors should redefine
FD_SETSIZE to the required higher value.
The user can also allocate the space for
fd_set structure dynamically, depending upon the number of
file descriptors to be tested. The following code segment illustrates the basic concepts.
int num_of_fds,s;
struct fd_set *f;
/*
* Set num_of_fds to the required value.
* User can set it to the maximum possible value the kernel is
* configured for, by using sysconf(_SC_OPEN_MAX).
* Note that, if you are not using this many files, you are
* wasting too much space.
*/
num_of_fds = sysconf(_SC_OPEN_MAX);
s = sizeof(long);
/*
* howmany is a macro defined in sys/types.h
*/
f = (struct fd_set *)malloc(s*howmany(num_of_fds, s*8);
/*
* Use f wherever struct fd_set * is used.
* It can be used to test num_of_fds file descriptors.
*/
RETURN VALUE
FD_CLR(), FD_SET(), and FD_ZERO() return no value. FD_ISSET() returns a non-zero value if
the bit for the file descriptor fd is set in the file descriptor set pointed to by fdset , and 0 otherwise.
On successful completion,
pselect() and select() return the total number of bits set in the bit
masks. Otherwise, −1 is returned, and errno is set to indicate the error.
ERRORS
Under the following conditions,
pselect() and select() fail and set errno to:
[EBADF] One or more of the file descriptor sets specified a file descriptor that is not a valid open
file descriptor. This could happen either if the file descriptor sets are not initialized or
nfds argument is greater than
FD_SETSIZE.
[EINTR] The function was interrupted before any of the selected events occurred and before the
timeout interval expired. If
SA_RESTART has been set for the interrupting signal, it is
implementation-dependent whether the function restarts or returns with [EINTR].
[EFAULT] One or more of the pointers was invalid. The reliable detection of this error is implemen-
tation dependent.
[EINVAL] An invalid timeout interval was specified. Valid values for the number of nanoseconds
(in
struct timespec) should be a non-negative integer less than 1,000,000,000. For
the number of microseconds (in struct timeval), a non-negative integer less than
1,000,000 should be used. Seconds should be specified using a non-negative integer.
[EINVAL] The nfds argument is less than 0, or is greater than or equal to the value of
MAXFUPLIM,
which specifies the absolute maximum number of files a process can have open at one
time. If the resource limit RLIMIT_NOFILE for a process is less than or equal to 2048,
MAXFUPLIM is considered to be 2048.
[EINVAL] One of the specified file descriptors refers to a STREAM or multiplexer that is linked
(directly or indirectly) downstream from a multiplexer.
HP-UX 11i Version 3: September 2010 − 3 − Hewlett-Packard Company 3