Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ select(3C) — Reliant UNIX 5.44c4

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

fcntl(2)

poll(2)

read(2)

write(2)

types(5)

select(3C)                                                       select(3C)

NAME
     select, FDCLR, FDISSET, FDSET, FDZERO - synchronous I/O multiplex-
     ing

SYNOPSIS
     #include <sys/time.h>
     #include <sys/types.h>

     int select(int nfds, fdset *readfds, fdset *writefds,
                fdset *errorfds, struct timeval *timeout);

     void FDCLR(int fd, fdset *fdset);

     int FDISSET(int fd, fdset *fdset);

     void FDSET(int fd, fdset *fdset);

     void FDZERO(fdset *fdset);

DESCRIPTION
     The select() function indicates which of the specified file descrip-
     tors is ready for reading, ready for writing, or has an error condi-
     tion pending. If the specified condition is false for all of the
     specified file descriptors, select() blocks, up to the specified
     timeout interval, until the specified condition is true for at least
     one of the specified file descriptors.

     The select() function supports regular files, terminal and pseudo-
     terminal devices, STREAMS-based files, FIFOs and pipes. The behavior
     of select() on file descriptors that refer to other types of file is
     unspecified.

     The nfds argument specifies the range of file descriptors to be
     tested. The select() function tests file descriptors in the range of 0
     to nfds-1.

     If the readfs argument is not a null pointer, it points to an object
     of type fdset that on input specifies the file descriptors to be
     checked for being ready to read, and on output indicates which file
     descriptors are ready to read.

     If the writefs argument is not a null pointer, it points to an object
     of type fdset that on input specifies the file descriptors to be
     checked for being ready to write, and on output indicates which file
     descriptors are ready to write.

     If the errorfds argument is not a null pointer, it points to an object
     of type fdset that on input specifies the file descriptors to be
     checked for error conditions pending, and on output indicates which
     file descriptors have error conditions pending.





Page 1                       Reliant UNIX 5.44                Printed 11/98

select(3C)                                                       select(3C)

     On successful completion, the objects pointed to by the readfs,
     writefs, and errorfds arguments are modified to indicate which file
     descriptors are ready for reading, ready for writing, or have an error
     condition pending, respectively. For each file descriptor less than
     nfds, the corresponding bit will be set on successful completion if it
     was set on input and the associated condition is true for that file
     descriptor.

     If the timeout argument is not a null pointer, it points to an object
     of type struct timeval that specifies a maximum interval to wait for
     the selection to complete. If the timeout argument points to an object
     of type struct timeval whose members are 0, select() does not block.
     If the timeout argument is a null pointer, select() blocks until an
     event causes one of the masks to be returned with a valid (non-zero)
     value. If the time limit expires before any event occurs that would
     cause one of the masks to be set to a non-zero value, select() com-
     pletes successfully and returns 0.

     Implementations may place limitations on the maximum timeout interval
     supported. On all implementations, the maximum timeout interval sup-
     ported will be at least 31 days. If the timeout argument specifies a
     timeout interval greater than the implementation-dependent maximum
     value, the maximum value will be used as the actual timeout value.
     Implementations may also place limitations on the granularity of
     timeout intervals. If the requested timeout interval requires a finer
     granularity than the implementation supports, the actual timeout
     interval will be rounded up to the next supported value.

     If the readfs, writefs, and errorfds arguments are all null pointers
     and the timeout argument is not a null pointer, select() blocks for
     the time specified, or until interrupted by a signal. If the readfs,
     writefs, and errorfds arguments are all null pointers and the timeout
     argument is a null pointer, select() blocks until interrupted by a
     signal.

     File descriptors associated with regular files always select true for
     ready to read, ready to write, and error conditions.

     On failure, the objects pointed to by the readfs, writefs, and
     errorfds arguments are not modified. If the timeout interval expires
     without the specified condition being true for any of the specified
     file descriptors, the objects pointed to by the readfs, writefs, and
     errorfds arguments have all bits set to 0.

     File descriptor masks of type fdset can be initialized. It is
     unspecified whether each of these is a macro or a function. If a macro
     definition is suppressed in order to access an actual function, or a
     program defines an external identifier with any of these names, the
     behavior is undefined.





Page 2                       Reliant UNIX 5.44                Printed 11/98

select(3C)                                                       select(3C)

     FDCLR(fd, &fdset)
          Clears the bit for the file descriptor fd in the file descriptor
          set fdset.

     FDISSET(fd, &fdset)
          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 other-
          wise.

     FDSET(fd, &fdset)
          Sets the bit for the file descriptor fd in the file descriptor
          set fdset.

     FDZERO(&fdset)
          Initializes the file descriptor set fdset to have zero bits for
          all file descriptors.

     The behavior of these macros is undefined if the fd argument is less
     than 0 or greater than or equal to FDSETSIZE.

RETURN VALUE
     fd is set in the file descriptor set pointed to by fdset, and 0 other-
     wise.

     On successful completion, select() returns the total number of bits
     set in the bit masks. Otherwise, -1 is returned, and errno is set to
     indicate the error.

ERRORS
     The following error code descriptions are function-specific. You will
     find a general description in introprm2(2) or in errno(5).

     Under the following conditions, select() fails and sets errno to:

     EBADF     One or more of the file descriptor sets specified a file
               descriptor that is not a valid open file descriptor.

     EINTR     The select() function was interrupted before any of the
               selected events occurred and before the timeout interval
               expired.

     If SARESTART has been set for the interrupting signal, it is
     implementation-dependent whether select() restarts or returns with
     EINTR.

     EINVAL    An invalid timeout interval was specified.

     EINVAL    The nfds argument is less than 0, or greater than or equal
               to FDSETSIZE.





Page 3                       Reliant UNIX 5.44                Printed 11/98

select(3C)                                                       select(3C)

     EINVAL    One of the specified file descriptors refers to a STREAM or
               multiplexer that is linked (directly or indirectly) down-
               stream from a multiplexer.

APPLICATION USAGE
     The use of a timeout does not affect any pending timers set up by
     alarm(), ualarm() or settimer().

     On successful completion, the object pointed to by the timeout argu-
     ment may be modified.

SEE ALSO
     fcntl(2), poll(2), read(2), write(2), systime(5), types(5).









































Page 4                       Reliant UNIX 5.44                Printed 11/98

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026