select

Performs multiplexed socket status queries.

Library:LibC
Standard:BSD
Service:Networking

Syntax

  #include <sys/select.h> 
   
  int select (
     int                     nfds,
     fd_set                 *readfds,
     fd_set                 *writefds,
     fd_set                 *exceptfds,
     const struct timeval   *timeout);
  

Parameters

nfds

(IN) Specifies the number of socket handles to examine. This should be the total number of handles in the fd_set structures plus 1.

readfds

(IN/OUT) Points, on input, to the file descriptors to check for being ready to read. On output, indicates which file descriptors are ready to read. If set to NULL, file descriptors are not checked for read operations.

writefds

(IN/OUT) Points, on input, to the file descriptors to check for being ready to write. On output, indicates which file descriptors are ready to write. If set to NULL, file descriptors are not checked for write operations.

exceptfds

(IN/OUT) Points, on input, to the file descriptors to check for pending error conditions. On output, indicates which file descriptors have pending error conditions. If set to NULL, file descriptors are not checked for error conditions.

timeout

(IN) Points to the timeval structure containing the maximum time to wait. If set to NULL, select blocks indefinitely until at least one descriptor meets the operation criteria.

Return Values

If successful, returns the number of ready handles contained in the handle sets. Otherwise, returns -1 and sets errno to one of the following:

Decimal

Constant

Description

4

EBADF

One of the handle sets specified an invalid handle.

9

EINVAL

The specified time limit is invalid. One of its components is negative or too large.

38

ENOTSOCK

One of the handle sets did not specify a socket handle.

Remarks

The select function works with socket handles only and should not be used for other file types.

NOTE:For pipes, use the pipe_select function.

For more information about the fd_set structure and the macros used for configuration, see fd_set.

The select function examines the socket handle sets to see if any of their handles are ready for reading, are ready for writing, or have an exception condition pending. It replaces the given socket handle sets with subsets consisting of those handles that are ready for the operation.

The socket handles from 0 through ( nfds-1) are examined. Socket handles can be any 32-bit value except 0 or -1. NetWare® sockets define fd_set as an array of 32-bit file handles. You should not work on more than 64 sockets (the value defined by FD_SETSIZE).

If you need to wait simultaneously on sockets and non-socket files, you should create separate threads because NetWare (unlike UNIX) provides multiple threads in the same data space.

If select returns with an error, the handle sets are not modified.

If the client attempts to specify more file handles in fd_set than the handles specified in FD_SETSIZE, the operation silently fails.

If timeout is a NULL pointer, select blocks indefinitely. To poll, timeout can point to a zero-valued timeval structure.

Normally, select should be called with nonblocking sockets. Even when select indicates that a socket handle is ready for an operation, it is possible that select might return EWOULDBLOCK when attempted. For example, when two or more processes share a handle, select also indicates readiness for reading or writing when a socket fails or no longer performs the indicated operation. This nuance assures that a client wakes up and notices the new socket state.

The exceptfds parameter is meaningful for TCP sockets only. When ready, the TCP sockets imply the existence of out-of-band urgent data on the socket.

If conditions correspond to read and write readiness respectively, select can also be called to check for the completion of accept and connect operations on nonblocking sockets

NetWare TCP/IP does not support SIOCSPGRP and SIOCGPGRP. These are used in BSD to manipulate the process group for select and asynchronous I/O signals.

See Also