Debian Codegraph @

upstream/opensuse-tumbleweed/man3/IO::Select.3pm

raw
1 .\" -*- mode: troff; coding: utf-8 -*-
2 .\" Automatically generated by Pod::Man v6.0.2 (Pod::Simple 3.45)
3 .\"
4 .\" Standard preamble:
5 .\" ========================================================================
6 .de Sp \" Vertical space (when we can't use .PP)
7 .if t .sp .5v
8 .if n .sp
9 ..
10 .de Vb \" Begin verbatim text
11 .ft CW
12 .nf
13 .ne \\$1
14 ..
15 .de Ve \" End verbatim text
16 .ft R
17 .fi
18 ..
19 .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>.
20 .ie n \{\
21 . ds C` ""
22 . ds C' ""
23 'br\}
24 .el\{\
25 . ds C`
26 . ds C'
27 'br\}
28 .\"
29 .\" Escape single quotes in literal strings from groff's Unicode transform.
30 .ie \n(.g .ds Aq \(aq
31 .el .ds Aq '
32 .\"
33 .\" If the F register is >0, we'll generate index entries on stderr for
34 .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
35 .\" entries marked with X<> in POD. Of course, you'll have to process the
36 .\" output yourself in some meaningful fashion.
37 .\"
38 .\" Avoid warning from groff about undefined register 'F'.
39 .de IX
40 ..
41 .nr rF 0
42 .if \n(.g .if rF .nr rF 1
43 .if (\n(rF:(\n(.g==0)) \{\
44 . if \nF \{\
45 . de IX
46 . tm Index:\\$1\t\\n%\t"\\$2"
47 ..
48 . if !\nF==2 \{\
49 . nr % 0
50 . nr F 2
51 . \}
52 . \}
53 .\}
54 .rr rF
55 .\"
56 .\" Required to disable full justification in groff 1.23.0.
57 .if n .ds AD l
58 .\" ========================================================================
59 .\"
60 .IX Title "IO::Select 3pm"
61 .TH IO::Select 3pm 2026-03-09 "perl v5.42.1" "Perl Programmers Reference Guide"
62 .\" For nroff, turn off justification. Always turn off hyphenation; it makes
63 .\" way too many mistakes in technical documents.
64 .if n .ad l
65 .nh
66 .SH NAME
67 IO::Select \- OO interface to the "select" system call
68 .SH SYNOPSIS
69 .IX Header "SYNOPSIS"
70 .Vb 1
71 \& use IO::Select;
72 \&
73 \& my $s = IO::Select\->new();
74 \&
75 \& $s\->add(\e*STDIN);
76 \& $s\->add($some_handle);
77 \&
78 \& my @ready1 = $s\->can_read($timeout);
79 \&
80 \& my @ready2 = IO::Select\->new(@handles)\->can_read(0);
81 .Ve
82 .SH DESCRIPTION
83 .IX Header "DESCRIPTION"
84 The \f(CW\*(C`IO::Select\*(C'\fR package implements an object approach to the system \f(CW\*(C`select\*(C'\fR
85 function call. It allows the user to see what IO handles, see IO::Handle,
86 are ready for reading, writing or have an exception pending.
87 .SH CONSTRUCTOR
88 .IX Header "CONSTRUCTOR"
89 .IP "new ( [ HANDLES ] )" 4
90 .IX Item "new ( [ HANDLES ] )"
91 The constructor creates a new object and optionally initialises it with a set
92 of handles.
93 .SH METHODS
94 .IX Header "METHODS"
95 .IP "add ( HANDLES )" 4
96 .IX Item "add ( HANDLES )"
97 Add the list of handles to the \f(CW\*(C`IO::Select\*(C'\fR object. It is these values that
98 will be returned when an event occurs. \f(CW\*(C`IO::Select\*(C'\fR keeps these values in a
99 cache which is indexed by the \f(CW\*(C`fileno\*(C'\fR of the handle, so if more than one
100 handle with the same \f(CW\*(C`fileno\*(C'\fR is specified then only the last one is cached.
101 .Sp
102 Each handle can be an \f(CW\*(C`IO::Handle\*(C'\fR object, an integer or an array
103 reference where the first element is an \f(CW\*(C`IO::Handle\*(C'\fR or an integer.
104 .IP "remove ( HANDLES )" 4
105 .IX Item "remove ( HANDLES )"
106 Remove all the given handles from the object. This method also works
107 by the \f(CW\*(C`fileno\*(C'\fR of the handles. So the exact handles that were added
108 need not be passed, just handles that have an equivalent \f(CW\*(C`fileno\*(C'\fR
109 .IP "exists ( HANDLE )" 4
110 .IX Item "exists ( HANDLE )"
111 Returns a true value (actually the handle itself) if it is present.
112 Returns undef otherwise.
113 .IP handles 4
114 .IX Item "handles"
115 Return an array of all registered handles.
116 .IP "can_read ( [ TIMEOUT ] )" 4
117 .IX Item "can_read ( [ TIMEOUT ] )"
118 Return an array of handles that are ready for reading. \f(CW\*(C`TIMEOUT\*(C'\fR is the
119 maximum amount of time to wait before returning an empty list (with \f(CW$!\fR
120 unchanged), in seconds, possibly fractional. If \f(CW\*(C`TIMEOUT\*(C'\fR is not given
121 and any handles are registered then the call will block indefinitely.
122 Upon error, an empty list is returned, with \f(CW$!\fR set to indicate the
123 error. To distinguish between timeout and error, set \f(CW$!\fR to zero
124 before calling this method, and check it after an empty list is returned.
125 .IP "can_write ( [ TIMEOUT ] )" 4
126 .IX Item "can_write ( [ TIMEOUT ] )"
127 Same as \f(CW\*(C`can_read\*(C'\fR except check for handles that can be written to.
128 .IP "has_exception ( [ TIMEOUT ] )" 4
129 .IX Item "has_exception ( [ TIMEOUT ] )"
130 Same as \f(CW\*(C`can_read\*(C'\fR except check for handles that have an exception
131 condition, for example pending out\-of\-band data.
132 .IP "count ()" 4
133 .IX Item "count ()"
134 Returns the number of handles that the object will check for when
135 one of the \f(CW\*(C`can_\*(C'\fR methods is called or the object is passed to
136 the \f(CW\*(C`select\*(C'\fR static method.
137 .IP \fBbits()\fR 4
138 .IX Item "bits()"
139 Return the bit string suitable as argument to the core \fBselect()\fR call.
140 .IP "select ( READ, WRITE, EXCEPTION [, TIMEOUT ] )" 4
141 .IX Item "select ( READ, WRITE, EXCEPTION [, TIMEOUT ] )"
142 \&\f(CW\*(C`select\*(C'\fR is a static method, that is you call it with the package name
143 like \f(CW\*(C`new\*(C'\fR. \f(CW\*(C`READ\*(C'\fR, \f(CW\*(C`WRITE\*(C'\fR and \f(CW\*(C`EXCEPTION\*(C'\fR are either \f(CW\*(C`undef\*(C'\fR or
144 \&\f(CW\*(C`IO::Select\*(C'\fR objects. \f(CW\*(C`TIMEOUT\*(C'\fR is optional and has the same effect as
145 for the core select call.
146 .Sp
147 If at least one handle is ready for the specified kind of operation,
148 the result will be an array of 3 elements, each a reference to an array
149 which will hold the handles that are ready for reading, writing and
150 have exceptions respectively. Upon timeout, an empty list is returned,
151 with \f(CW$!\fR unchanged. Upon error, an empty list is returned, with \f(CW$!\fR
152 set to indicate the error. To distinguish between timeout and error,
153 set \f(CW$!\fR to zero before calling this method, and check it after an
154 empty list is returned.
155 .SH EXAMPLE
156 .IX Header "EXAMPLE"
157 Here is a short example which shows how \f(CW\*(C`IO::Select\*(C'\fR could be used
158 to write a server which communicates with several sockets while also
159 listening for more connections on a listen socket
160 .PP
161 .Vb 2
162 \& use IO::Select;
163 \& use IO::Socket;
164 \&
165 \& my $lsn = IO::Socket::INET\->new(Listen => 1, LocalPort => 8080);
166 \& my $sel = IO::Select\->new( $lsn );
167 \&
168 \& while(my @ready = $sel\->can_read) {
169 \& foreach my $fh (@ready) {
170 \& if($fh == $lsn) {
171 \& # Create a new socket
172 \& my $new = $lsn\->accept;
173 \& $sel\->add($new);
174 \& }
175 \& else {
176 \& # Process socket
177 \&
178 \& # Maybe we have finished with the socket
179 \& $sel\->remove($fh);
180 \& $fh\->close;
181 \& }
182 \& }
183 \& }
184 .Ve
185 .SH AUTHOR
186 .IX Header "AUTHOR"
187 Graham Barr. Currently maintained by the Perl Porters. Please report all
188 bugs at <https://github.com/Perl/perl5/issues>.
189 .SH COPYRIGHT
190 .IX Header "COPYRIGHT"
191 Copyright (c) 1997\-8 Graham Barr <[email protected]>. All rights reserved.
192 This program is free software; you can redistribute it and/or
193 modify it under the same terms as Perl itself.