linux
select
C LANGUAGE
Linux man page:
select, pselect, FD_CLR, FD_ISSET, FD_SET, FD_ZERO - synchronous
I/O multiplexing
โโโโ #include <sys/select.h>
โโโโ int select(int nfds, fd_set *restrict readfds,
โโโโ fd_set *restrict writefds, fd_set *restrict exceptfds,
โโโโ struct timeval *restrict timeout);
โโโโ void FD_CLR(int fd, fd_set *set);
โโโโ int FD_ISSET(int fd, fd_set *set);
โโโโ void FD_SET(int fd, fd_set *set);
โโโโ void FD_ZERO(fd_set *set);
โโโโ int pselect(int nfds, fd_set *restrict readfds,
โโโโ fd_set *restrict writefds, fd_set *restrict exceptfds,
โโโโ const struct timespec *restrict timeout,
โโโโ const sigset_t *restrict sigmask);
Feature Test Macro Requirements for glibc (see
feature_test_macros(7)):
โโโโ pselect():
โโโโ _POSIX_C_SOURCE >= 200112L
DESCRIPTION top WARNING: select() can monitor only file descriptors numbers that
are less than FD_SETSIZE (1024)โan unreasonably low limit for
many modern applicationsโand this limitation will not change.
All modern applications should instead use poll(2) or epoll(7),
which do not suffer this limitation.
readfds
The file descriptors in this set are watched to see if
they are ready for reading.
A file descriptor is ready for reading if a read operation will not block; in particular, a file descriptor is also ready on end-of-file.
After select() has returned, readfds will be cleared of
all file descriptors except for those that are ready for
reading.
writefds
The file descriptors in this set are watched to see if they are ready for writing.
A file descriptor is ready for writing if a write operation will not block.
However,
even if a file descriptor indicates as writable, a large
write may still block.
After select() has returned, writefds will be cleared of
all file descriptors except for those that are ready for
writing.
exceptfds
The file descriptors in this set are watched for "exceptional conditions".
For examples of some exceptional conditions, see the discussion of POLLPRI in poll(2). After select() has returned, exceptfds will be cleared of
all file descriptors except for those for which an exceptional condition has occurred.
nfds
This argument should be set to the highest-numbered file descriptor in any of the three sets, plus 1.
The
indicated file descriptors in each set are checked, up to this limit (but see BUGS).
timeout
The timeout argument is a timeval structure (shown below)
that specifies the interval that select() should block
waiting for a file descriptor to become ready. The call
will block until either:
โโโโ โข a file descriptor becomes ready;
โโโโ โข the call is interrupted by a signal handler; or
โโโโ โข the timeout expires.
โโโโ Note that the timeout interval will be rounded up to the
โโโโ system clock granularity, and kernel scheduling delays
โโโโ mean that the blocking interval may overrun by a small
โโโโ amount.
โโโโ If both fields of the timeval structure are zero, then
โโโโ select() returns immediately. (This is useful for
โโโโ polling.)
โโโโ If timeout is specified as NULL, select() blocks
โโโโ indefinitely waiting for a file descriptor to become
โโโโ ready.
RETURN VALUE
On success, select() and pselect() return the number of file
descriptors contained in the three returned descriptor sets (that
is, the total number of bits that are set in readfds, writefds,
exceptfds). The return value may be zero if the timeout expired
before any file descriptors became ready.
โโโโ On error, -1 is returned, and errno is set to indicate the error;
โโโโ the file descriptor sets are unmodified, and timeout becomes
โโโโ undefined.
TCP Client/Server (select) ้ไฝ่งๅฟต
Linux 2.6:
How to use epoll? A complete example in C, by Mukund Sivaraman
่ฆๅจ linux 2.6 ไปฅไธ, ไธ่ฝ็จcygwin
Red-Black Trees:
HOME WORKS: