.\" This manpage is copyright (C) 2001 Paul Sheer.
.\"
+.\" %%%LICENSE_START(VERBATIM)
.\" Permission is granted to make and distribute verbatim copies of this
.\" manual provided the copyright notice and this permission notice are
.\" preserved on all copies.
.\"
.\" Formatted or processed versions of this manual, if unaccompanied by
.\" the source, must acknowledge the copyright and authors of this work.
+.\" %%%LICENSE_END
.\"
.\" very minor changes, aeb
.\"
.\" various other changes
.\" 2008-01-26, mtk, substantial changes and rewrites
.\"
-.TH SELECT_TUT 2 2010-06-10 "Linux" "Linux Programmer's Manual"
+.TH SELECT_TUT 2 2013-12-30 "Linux" "Linux Programmer's Manual"
.SH NAME
select, pselect, FD_CLR, FD_ISSET, FD_SET, FD_ZERO \-
synchronous I/O multiplexing
for more details about OOB data.
(One other less common case where
.BR select (2)
-indicates an exceptional condition occurs with pseudo-terminals
+indicates an exceptional condition occurs with pseudoterminals
in packet mode; see
.BR tty_ioctl (4).)
After
.BR pselect ()
will then behave just like
.BR select ().
-.SS Combining Signal and Data Events
+.SS Combining signal and data events
.BR pselect ()
is useful if you are waiting for a signal as well as
for file descriptor(s) to become ready for I/O.
.BR pselect ()
call.
This call can be used to set the signal mask to a set of signals
-that are only to be received within the
+that are to be received only within the
.BR pselect ()
call.
For instance, let us say that the event in question
is that it watches
multiple descriptors at the same time and properly puts the process to
sleep if there is no activity.
-Unix programmers often find
+UNIX programmers often find
themselves in a position where they have to handle I/O from more than one
file descriptor where the data flow may be intermittent.
If you were to merely create a sequence of
descriptor, while another file descriptor is unused though ready for I/O.
.BR select ()
efficiently copes with this situation.
-.SS Select Law
+.SS Select law
Many people who try to use
.BR select ()
come across behavior that is
because you have a low traffic load and a fast stream.
This is not always going to be the case.
You should cope with the case of your
-functions only managing to send or receive a single byte.
+functions managing to send or receive only a single byte.
.TP
6.
Never read/write only in single bytes at a time unless you are really
.\" Having no file descriptors set is a useful
.\" way to sleep the process with subsecond precision by using the timeout.
.\" (See further on.)
-.SS Usleep Emulation
+.SS Usleep emulation
On systems that do not have a
.BR usleep (3)
function, you can call
select(0, NULL, NULL, NULL, &tv);
.fi
.PP
-This is only guaranteed to work on Unix systems, however.
+This is guaranteed to work only on UNIX systems, however.
.SH RETURN VALUE
On success,
.BR select ()
int s;
int yes;
- if ((s = socket(AF_INET, SOCK_STREAM, 0)) == \-1) {
+ s = socket(AF_INET, SOCK_STREAM, 0);
+ if (s == \-1) {
perror("socket");
return \-1;
}
yes = 1;
if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR,
- (char *) &yes, sizeof(yes)) == \-1) {
+ &yes, sizeof(yes)) == \-1) {
perror("setsockopt");
close(s);
return \-1;
struct sockaddr_in a;
int s;
- if ((s = socket(AF_INET, SOCK_STREAM, 0)) == \-1) {
+ s = socket(AF_INET, SOCK_STREAM, 0);
+ if (s == \-1) {
perror("socket");
close(s);
return \-1;
int buf2_avail, buf2_written;
if (argc != 4) {
- fprintf(stderr, "Usage\\n\\tfwd <listen-port> "
- "<forward-to-port> <forward-to-ip-address>\\n");
+ fprintf(stderr, "Usage\\n\\tfwd <listen\-port> "
+ "<forward\-to\-port> <forward\-to\-ip\-address>\\n");
exit(EXIT_FAILURE);
}
The program does not handle more than one simultaneous connection at a
time, although it could easily be extended to do this with a linked list
-of buffers \(em one for each connection.
+of buffers\(emone for each connection.
At the moment, new
connections cause the current connection to be dropped.
.SH SEE ALSO
.BR epoll (7)
.\" .SH AUTHORS
.\" This man page was written by Paul Sheer.
+.SH COLOPHON
+This page is part of release 3.79 of the Linux
+.I man-pages
+project.
+A description of the project,
+information about reporting bugs,
+and the latest version of this page,
+can be found at
+\%http://www.kernel.org/doc/man\-pages/.