Chapter 3 Terminal Specific Function Library
157
select
Purpose
To synchronize I/O multiplexing.
Syntax
int select (int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct
timeval *timeout);
domain
Protocol family; this should always be PF_INET or AF_INET.
type
Socket type, either SOCK_STREAM or SOCK_DGRAM.
protocol
Depending on the
type
parameter specified, the protocol to be
used can be TCP, UDP, or ICMP.
Example
(?)
Description
This routine 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,
respectively. The only exceptional condition detectable is out-of-band data
received on a socket.
The first
nfds
descriptors are checked in each set; i.e. the descriptors from
0 through
nfds
-1 in the descriptor sets are examined.
On return, this routine replaces the given descriptor sets with subsets
consisting of those descriptors that are ready for the requested operation. It
returns the total number of ready descriptors in all the sets.
The descriptor sets are stored as bit fields in arrays of integers. The
following are provided for manipulating such descriptor sets. Their
behavior is undefined if a descriptor value is less than zero or greater than
or equal to FD_SETSIZE, which is normally at least equal to the
maximum number of descriptors supported by the system.
FD_SETSIZE 8
The maximum number of descriptors is 8.
FD_SET (n, p)
((p) -> fds_bits [(n) >>3 ] |= (1 << ((n) & 7)))
FD_CLR (n, p)
((p) -> fds_bits [(n) >>3 ] &= ~(1 << ((n) & 7)))
FD_ISSET (n, p)
((p) -> fds_bits [(n) >>3 ] & (1 << ((n) & 7)))
FD_ZERO (p)
memset ((void *) (p), 0, sizeof (*(p)))
The
timeout
argument, pointing to a zero-valued timeval structure,
specifies the maximum interval to wait for the selection to complete.
System activity can lengthen the interval by an indeterminate amount. If it
is a null pointer, the select blocks indefinitely.
Any of
readfds
,
writefds
, and
exceptfds
may be given as null pointers if no
descriptors are of interest.
Return
If successful, it returns the number of ready descriptors.
If the time limit expires, it returns 0.
On error, it returns -1.
The global variable
errno
is set to indicate the error condition encountered.
See Also
accept, connect, recv, send
Summary of Contents for Optimus R
Page 1: ...Printed on 20 March 2006 C Programming Guide Version 3 04 02 Optimus S Optimus R...
Page 6: ......
Page 8: ...2 C Programming Guide For Optimus S R...
Page 12: ...6 C Programming Guide For Optimus S R The flow is illustrated as shown below...
Page 23: ...Chapter 2 Development Environment 17 Different types signed unsigned Different types same size...
Page 24: ...18 C Programming Guide For Optimus S R...
Page 220: ...214 C Programming Guide For Optimus S R See Also FlashSize free_memory...