Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

fcntl(2)

read(2)

write(2)

SELECT(2)  —  HP-UX

NAME

select − synchronous I/O multiplexing

SYNOPSIS

#include <time.h>

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

DESCRIPTION

Select examines the file descriptors specified by the bit masks readfds, writefds and exceptfds. The bits from 0 through nfds-1 are examined. File descriptor f is represented by the bit “1<<f” in the masks.  More formally, a file descriptor is represented by:

fds[(f / BITS_PER_INT)] & (1 << (f % BITS_PER_INT))

When select completes successfully it returns the three bit masks modified as follows: For each file descriptor less than nfds, the corresponding bit in each mask is set if the bit was set upon entry and the file descriptor is ready for reading, writing or has an exceptional condition pending. 

If timeout is a non-zero pointer, it specifies a maximum interval to wait for the selection to complete.  If timeout is a zero pointer, the select waits until an event causes one of the masks to be returned with a valid (non-zero) value.  To poll, the timeout argument should be non-zero, pointing to a zero valued timeval structure.  Specific implementations may place limitations on the maximum timeout interval supported.  The constant MAX_ALARM defined in <sys/param.h> specifies the implementation-specific maximum (in seconds).  Whenever timeout specifies a value greater than this maximum, it is silently rounded down to this maximum.  On all implementations, MAX_ALARM is guaranteed to be at least 31 days (in seconds).  Note that the use of a timeout does not affect any pending timers set up by alarm(2) or setitimer(2).

Any or all of readfds, writefds, and exceptfds may be given as 0 if no descriptors are of interest. 

Ordinary files always select true whenever selecting on reads, writes, and/or exceptions. 

EXAMPLES

The following call to select checks if any of 4 terminals are ready for reading.  Select will time out after 5 seconds if no terminals are ready for reading.  Note that the code for opening the terminals or reading from the terminals is not shown in this example.  Also, note that this example must be modified if the calling process has more than 32 file descriptors open:

#define MASK(f)(1 << (f))
#define NTTYS4 int tty[NTTYS];
int ttymask[NTTYS];
int readmask = 0;
int readfds;
int nfound, i;
struct timeval timeout;

/* First open each terminal for reading and put the
* file descriptors into array tty[NTTYS].  The code
* for opening the terminals is not shown here.
*/ for (i=0; i < NTTYS; i++) {

ttymask[i] = MASK(tty[i]);
readmask |= ttymask[i];

} timeout.tv_sec  = 5;
timeout.tv_usec = 0;
readfds = readmask; /* select on NTTYS+3 file descriptors if stdin, stdout
* and stderr are also open
*/
if ((nfound = select (NTTYS+3, &readfds, 0, 0, &timeout)) == -1)

perror ("select failed");

else if (nfound == 0)

printf ("select timed out \n");

else for (i=0; i < NTTYS; i++)

if (ttymask[i] & readfds)

/* Read from tty[i].  The code for reading
* is not shown here.
*/

else printf ("tty[%d] is not ready for reading \n",i);

RETURN VALUE

Select returns the number of descriptors contained in the bit masks, or −1 if an error occurred.  If the time limit expires then select returns 0 and all the masks are cleared. 

ERRORS

An error return from select indicates:

[EBADF] One or more of the bit masks specified an invalid descriptor. 

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

[EFAULT] One or more of the pointers was invalid.  The reliable detection of this error will be implementation dependent. 

[EINVAL] Invalid timeval passed for timeout. 

[EINVAL] nfds < 0

WARNINGS

Check all references to signal(2) for appropriateness on systems that support sigvector(2). Sigvector(2) can affect the behavior described on this page.

The file descriptor masks are always modified on return, even if the call returns as the result of a timeout. 

HARDWARE DEPENDENCIES

Series 200, 300
Select(2) supports the following devices and file types:

pipes
fifo special files (named pipes)
All serial interfaces
All ITEs and HP-HIL input devices
pty(7) special files
HP 98643 LAN interface card driver

File types not supporting select(2) always return true.

Series 500
Select(2) supports the following devices and file types:

pipes
fifo special files (named pipes)
pty(7) special files
Model 520 Internal Terminal Emulator (ITE)
HP 98700H ITE and HP-HIL input devices
(such as HP 46020A Keyboard and HP 46086A Button Box)
HP 27128A ASI tty driver
HP 27125A LAN interface card driver (LLA)
HP 27130A/B port MUX (with appropriate firmware revision)

Device files that do not support select(2) always return true for those conditions the user is selecting on.

Series 800
Select(2) supports the following devices and file types:

pipes
fifo special files (named pipes)
all serial devices
hpib(7) special files
gpio(7) special files
lan(7) special files
pty(7) special files

The convention for device files that do not support select(2) is to always return true for those conditions the user is selecting on. 

Consult the individual device manual pages to determine the extent to which any particular driver supports select(2). 

AUTHOR

Select was developed by HP and the University of California, Berkeley. 

SEE ALSO

fcntl(2), read(2), write(2). 

Hewlett-Packard Company  —  Version B.1,  May 11, 2021

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