summaryrefslogtreecommitdiff
path: root/static/v10/man2/select.2
diff options
context:
space:
mode:
authorJacob McDonnell <jacob@jacobmcdonnell.com>2026-04-25 21:07:28 -0400
committerJacob McDonnell <jacob@jacobmcdonnell.com>2026-04-25 21:07:28 -0400
commit711594636704defae873be1a355a292505585afd (patch)
tree59ee13f863830d8beba6cfd02bbe813dd486c26f /static/v10/man2/select.2
parent3258a063c1f189d7b019e40e525b46bef9b9a7b1 (diff)
docs: Added UNIX V10 Manuals
Diffstat (limited to 'static/v10/man2/select.2')
-rw-r--r--static/v10/man2/select.2130
1 files changed, 130 insertions, 0 deletions
diff --git a/static/v10/man2/select.2 b/static/v10/man2/select.2
new file mode 100644
index 00000000..e6e38230
--- /dev/null
+++ b/static/v10/man2/select.2
@@ -0,0 +1,130 @@
+.TH SELECT 2
+.CT 2 file_io comm_proc
+.SH NAME
+select \(mi synchronous input/output multiplexing
+.SH SYNOPSIS
+.nf
+.B #include <sys/types.h>
+.PP
+.B int select(nfds, readfds, writefds, milli);
+.B fd_set *readfds, *writefds;
+.fi
+.SH DESCRIPTION
+.I Select
+examines a set of file descriptors
+to see if they will block if read or written.
+.I Readfds
+points to an object of type
+.BR fd_set ,
+which contains a set of descriptors to be checked for reading;
+.I writefds
+similarly for writing.
+Only descriptors
+0 through
+.IR nfds \-1
+are considered.
+The number of ready descriptors is returned,
+and the
+.B fd_set
+pointed to by
+.I readfds
+.RI ( writefds )
+is overwritten with a set of descriptors
+ready to be read
+(written).
+The call waits until at least one descriptor is ready,
+or until
+.I milli
+milliseconds have passed.
+.PP
+Either
+.I readfds
+or
+.I writefds
+may be 0
+if no descriptors are interesting.
+.PP
+The
+.BR fd_set
+type looks like
+.RS
+.EX
+typedef struct {
+ unsigned int fds_bits[FDWORDS];
+} fd_set;
+.EE
+.RE
+.B FDWORDS
+is sufficient to contain as many file descriptors as the system will allow
+(currently 128).
+If there are
+.I B
+bits in an
+.BR "unsigned int" ,
+file descriptor
+.I n
+is represented by
+.BI "1<<((" n % B )-1)
+in word
+.BI fds_bits[ n / B ]\c
+\&.
+.PP
+These macros should be used
+to manipulate the contents
+of an
+.BR fd_set :
+.TF FD_ISSET(n,\0s)
+.TP
+.PD 0
+.B FD_ZERO(s)
+clear all bits
+in set
+.I s
+.TP
+.B "FD_SET(n, s)
+set bit for file descriptor
+.I n
+in set
+.I s
+.TP
+.B "FD_CLR(n, s)
+clear bit for file descriptor
+.I n
+in s
+.TP
+.B "FD_ISSET(n, s)
+return a value of 1
+if bit for file descriptor
+.I n
+is set in
+.IR s ,
+0 otherwise
+.PD
+.SH EXAMPLES
+.EX
+int p[2];
+fd_set wfs;
+pipe(p);
+do {
+ FD_SET(p[1], wfs);
+ write(p[1], ".", 1);
+ i++;
+} while(select(p[1]+1, (fd_set*)0, wfs, 0) == 1);
+printf("Pipe capacity = %d\en", i);
+.EE
+.SH "SEE ALSO"
+.IR read (2)
+.SH DIAGNOSTICS
+.BR EBADF ,
+.BR EFAULT ,
+.BR EINTR
+.SH BUGS
+.I Milli
+is rounded up to the nearest second.
+.br
+.I Select
+is intended for use with streams;
+file descriptors referring to ordinary files
+or to non-stream special files
+always appear ready.
+This is a lie for some special files.