Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

accept(2)

connect(2)

readv(2)

writev(2)

recv(2)

send(2)



  select(2)                           CLIX                           select(2)



  NAME

    select - Synchronous I/O multiplexing

  LIBRARY

    Berkeley Software Distribution (libbsd.a)

  SYNOPSIS

    #include <sys/types.h>

    #include <sys/socket.h>

    #include <sys/time.h>

    int select(
      int nfds ,
      fd_set *readfds ,
      fd_set *writefds ,
      fd_set *exceptfds ,
      struct timeval *timeout );

  PARAMETERS

    nfds        Specifies the number of descriptors in each mask to check.

    readfds     Represents the set of descriptors that should be checked for
                read conditions.

    writefds    Represents the set of descriptors that should be checked for
                write conditions.

    exceptfds   Represents the set of descriptors that should be checked for
                exceptional conditions.

    timeout     Specifies the amount of time to wait for a condition to occur.

  DESCRIPTION

    The select() function examines the I/O descriptor sets whose addresses are
    passed in readfds, writefds, and exceptfds to see if some of their
    descriptors are ready for reading, are ready for writing, or have an
    exceptional condition pending.  The descriptors from 0 through nfds-1 in
    the descriptor sets are examined.  On return, select() replaces the given
    descriptor sets with subsets consisting of those descriptors that are
    ready for the requested operation.  The total number of ready descriptors
    in all the sets is returned.

    The descriptor sets are stored as bit fields in arrays of integers.  The
    following macros are provided for manipulating such descriptor sets:



  2/94 - Intergraph Corporation                                              1






  select(2)                           CLIX                           select(2)



    FD_SET(
      int fd ,
      fd_set *fdset );

    FD_CLR(
      int fd ,
      fd_set *fdset );

    FD_ISSET(
      int fd ,
      fd_set *fdset );

    FD_ZERO(
      fd_set *fdset );

    The FD_ZERO() macro initializes the descriptor set fdset to the null set.
    FD_SET() includes a particular descriptor fd in fdset.  The FD_CLR() macro
    removes fd from fdset.  The FD_ISSET() macro is nonzero if fd is a member
    of fdset; otherwise, it is 0.  The behavior of these macros is undefined
    if a descriptor value is less than 0 or greater than or equal to
    FD_SETSIZE, which is normally at least equal to the maximum number of
    descriptors supported by the system.

    If timeout is a nonzero pointer, it specifies a maximum interval to wait
    for the selection to complete.  If timeout is a 0 pointer, the select()
    function blocks indefinitely.  To affect a poll, the timeout parameter
    should be nonzero, pointing to a zero-valued timeval structure.

    The values of readfds, writefds, or exceptfds may be given as 0 pointers
    if no descriptors are of interest.

  EXAMPLES

    To select indefinitely for reading on socket descriptor sd:

    FD_SET(sd, readfds);
    if (select(sizeof(readfds), readfds, NULL, NULL, NULL) == -1)
         perror("Select failed");


  CAUTIONS

    The select() function is supported only for sockets, pseudo terminals, and
    STREAMS devices.

  RETURN VALUES

    Upon successful completion, the number of ready descriptors is returned.
    If the time limit expires, a value of 0 is returned.  Otherwise, a value
    of -1 is returned and errno is set to indicate the error.




  2                                              Intergraph Corporation - 2/94






  select(2)                           CLIX                           select(2)



  ERRORS

    The select() function fails if one or more of the following is true:

    [EBADF]    The descriptor is not valid.

    [EINVAL]   The nfds parameter is not a valid number.

    [EFAULT]   The readfds, writefds, exceptfds, or timeout parameters point
               to a nonwritable area of the user address space.

    [EINTR]    A signal was delivered before the time limit expired and before
               any of the selected events occurred.

  RELATED INFORMATION

    Functions:  accept(2), connect(2), readv(2), writev(2), recv(2), send(2)





































  2/94 - Intergraph Corporation                                              3




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