Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / devtools / v8plus / man / man3 / IO::Select.3
CommitLineData
920dae64
AT
1.\" Automatically generated by Pod::Man v1.37, Pod::Parser v1.32
2.\"
3.\" Standard preamble:
4.\" ========================================================================
5.de Sh \" Subsection heading
6.br
7.if t .Sp
8.ne 5
9.PP
10\fB\\$1\fR
11.PP
12..
13.de Sp \" Vertical space (when we can't use .PP)
14.if t .sp .5v
15.if n .sp
16..
17.de Vb \" Begin verbatim text
18.ft CW
19.nf
20.ne \\$1
21..
22.de Ve \" End verbatim text
23.ft R
24.fi
25..
26.\" Set up some character translations and predefined strings. \*(-- will
27.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
28.\" double quote, and \*(R" will give a right double quote. | will give a
29.\" real vertical bar. \*(C+ will give a nicer C++. Capital omega is used to
30.\" do unbreakable dashes and therefore won't be available. \*(C` and \*(C'
31.\" expand to `' in nroff, nothing in troff, for use with C<>.
32.tr \(*W-|\(bv\*(Tr
33.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
34.ie n \{\
35. ds -- \(*W-
36. ds PI pi
37. if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
38. if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
39. ds L" ""
40. ds R" ""
41. ds C` ""
42. ds C' ""
43'br\}
44.el\{\
45. ds -- \|\(em\|
46. ds PI \(*p
47. ds L" ``
48. ds R" ''
49'br\}
50.\"
51.\" If the F register is turned on, we'll generate index entries on stderr for
52.\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index
53.\" entries marked with X<> in POD. Of course, you'll have to process the
54.\" output yourself in some meaningful fashion.
55.if \nF \{\
56. de IX
57. tm Index:\\$1\t\\n%\t"\\$2"
58..
59. nr % 0
60. rr F
61.\}
62.\"
63.\" For nroff, turn off justification. Always turn off hyphenation; it makes
64.\" way too many mistakes in technical documents.
65.hy 0
66.if n .na
67.\"
68.\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
69.\" Fear. Run. Save yourself. No user-serviceable parts.
70. \" fudge factors for nroff and troff
71.if n \{\
72. ds #H 0
73. ds #V .8m
74. ds #F .3m
75. ds #[ \f1
76. ds #] \fP
77.\}
78.if t \{\
79. ds #H ((1u-(\\\\n(.fu%2u))*.13m)
80. ds #V .6m
81. ds #F 0
82. ds #[ \&
83. ds #] \&
84.\}
85. \" simple accents for nroff and troff
86.if n \{\
87. ds ' \&
88. ds ` \&
89. ds ^ \&
90. ds , \&
91. ds ~ ~
92. ds /
93.\}
94.if t \{\
95. ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
96. ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
97. ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
98. ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
99. ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
100. ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
101.\}
102. \" troff and (daisy-wheel) nroff accents
103.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
104.ds 8 \h'\*(#H'\(*b\h'-\*(#H'
105.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
106.ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
107.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
108.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
109.ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
110.ds ae a\h'-(\w'a'u*4/10)'e
111.ds Ae A\h'-(\w'A'u*4/10)'E
112. \" corrections for vroff
113.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
114.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
115. \" for low resolution devices (crt and lpr)
116.if \n(.H>23 .if \n(.V>19 \
117\{\
118. ds : e
119. ds 8 ss
120. ds o a
121. ds d- d\h'-1'\(ga
122. ds D- D\h'-1'\(hy
123. ds th \o'bp'
124. ds Th \o'LP'
125. ds ae ae
126. ds Ae AE
127.\}
128.rm #[ #] #H #V #F C
129.\" ========================================================================
130.\"
131.IX Title "IO::Select 3"
132.TH IO::Select 3 "2001-09-21" "perl v5.8.8" "Perl Programmers Reference Guide"
133.SH "NAME"
134IO::Select \- OO interface to the select system call
135.SH "SYNOPSIS"
136.IX Header "SYNOPSIS"
137.Vb 1
138\& use IO::Select;
139.Ve
140.PP
141.Vb 1
142\& $s = IO::Select->new();
143.Ve
144.PP
145.Vb 2
146\& $s->add(\e*STDIN);
147\& $s->add($some_handle);
148.Ve
149.PP
150.Vb 1
151\& @ready = $s->can_read($timeout);
152.Ve
153.PP
154.Vb 1
155\& @ready = IO::Select->new(@handles)->can_read(0);
156.Ve
157.SH "DESCRIPTION"
158.IX Header "DESCRIPTION"
159The \f(CW\*(C`IO::Select\*(C'\fR package implements an object approach to the system \f(CW\*(C`select\*(C'\fR
160function call. It allows the user to see what \s-1IO\s0 handles, see IO::Handle,
161are ready for reading, writing or have an exception pending.
162.SH "CONSTRUCTOR"
163.IX Header "CONSTRUCTOR"
164.IP "new ( [ \s-1HANDLES\s0 ] )" 4
165.IX Item "new ( [ HANDLES ] )"
166The constructor creates a new object and optionally initialises it with a set
167of handles.
168.SH "METHODS"
169.IX Header "METHODS"
170.IP "add ( \s-1HANDLES\s0 )" 4
171.IX Item "add ( HANDLES )"
172Add the list of handles to the \f(CW\*(C`IO::Select\*(C'\fR object. It is these values that
173will be returned when an event occurs. \f(CW\*(C`IO::Select\*(C'\fR keeps these values in a
174cache which is indexed by the \f(CW\*(C`fileno\*(C'\fR of the handle, so if more than one
175handle with the same \f(CW\*(C`fileno\*(C'\fR is specified then only the last one is cached.
176.Sp
177Each handle can be an \f(CW\*(C`IO::Handle\*(C'\fR object, an integer or an array
178reference where the first element is an \f(CW\*(C`IO::Handle\*(C'\fR or an integer.
179.IP "remove ( \s-1HANDLES\s0 )" 4
180.IX Item "remove ( HANDLES )"
181Remove all the given handles from the object. This method also works
182by the \f(CW\*(C`fileno\*(C'\fR of the handles. So the exact handles that were added
183need not be passed, just handles that have an equivalent \f(CW\*(C`fileno\*(C'\fR
184.IP "exists ( \s-1HANDLE\s0 )" 4
185.IX Item "exists ( HANDLE )"
186Returns a true value (actually the handle itself) if it is present.
187Returns undef otherwise.
188.IP "handles" 4
189.IX Item "handles"
190Return an array of all registered handles.
191.IP "can_read ( [ \s-1TIMEOUT\s0 ] )" 4
192.IX Item "can_read ( [ TIMEOUT ] )"
193Return an array of handles that are ready for reading. \f(CW\*(C`TIMEOUT\*(C'\fR is
194the maximum amount of time to wait before returning an empty list, in
195seconds, possibly fractional. If \f(CW\*(C`TIMEOUT\*(C'\fR is not given and any
196handles are registered then the call will block.
197.IP "can_write ( [ \s-1TIMEOUT\s0 ] )" 4
198.IX Item "can_write ( [ TIMEOUT ] )"
199Same as \f(CW\*(C`can_read\*(C'\fR except check for handles that can be written to.
200.IP "has_exception ( [ \s-1TIMEOUT\s0 ] )" 4
201.IX Item "has_exception ( [ TIMEOUT ] )"
202Same as \f(CW\*(C`can_read\*(C'\fR except check for handles that have an exception
203condition, for example pending out-of-band data.
204.IP "count ()" 4
205.IX Item "count ()"
206Returns the number of handles that the object will check for when
207one of the \f(CW\*(C`can_\*(C'\fR methods is called or the object is passed to
208the \f(CW\*(C`select\*(C'\fR static method.
209.IP "\fIbits()\fR" 4
210.IX Item "bits()"
211Return the bit string suitable as argument to the core \fIselect()\fR call.
212.IP "select ( \s-1READ\s0, \s-1WRITE\s0, \s-1EXCEPTION\s0 [, \s-1TIMEOUT\s0 ] )" 4
213.IX Item "select ( READ, WRITE, EXCEPTION [, TIMEOUT ] )"
214\&\f(CW\*(C`select\*(C'\fR is a static method, that is you call it with the package name
215like \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
216\&\f(CW\*(C`IO::Select\*(C'\fR objects. \f(CW\*(C`TIMEOUT\*(C'\fR is optional and has the same effect as
217for the core select call.
218.Sp
219The result will be an array of 3 elements, each a reference to an array
220which will hold the handles that are ready for reading, writing and have
221exceptions respectively. Upon error an empty list is returned.
222.SH "EXAMPLE"
223.IX Header "EXAMPLE"
224Here is a short example which shows how \f(CW\*(C`IO::Select\*(C'\fR could be used
225to write a server which communicates with several sockets while also
226listening for more connections on a listen socket
227.PP
228.Vb 2
229\& use IO::Select;
230\& use IO::Socket;
231.Ve
232.PP
233.Vb 2
234\& $lsn = new IO::Socket::INET(Listen => 1, LocalPort => 8080);
235\& $sel = new IO::Select( $lsn );
236.Ve
237.PP
238.Vb 9
239\& while(@ready = $sel->can_read) {
240\& foreach $fh (@ready) {
241\& if($fh == $lsn) {
242\& # Create a new socket
243\& $new = $lsn->accept;
244\& $sel->add($new);
245\& }
246\& else {
247\& # Process socket
248.Ve
249.PP
250.Vb 6
251\& # Maybe we have finished with the socket
252\& $sel->remove($fh);
253\& $fh->close;
254\& }
255\& }
256\& }
257.Ve
258.SH "AUTHOR"
259.IX Header "AUTHOR"
260Graham Barr. Currently maintained by the Perl Porters. Please report all
261bugs to <perl5\-porters@perl.org>.
262.SH "COPYRIGHT"
263.IX Header "COPYRIGHT"
264Copyright (c) 1997\-8 Graham Barr <gbarr@pobox.com>. All rights reserved.
265This program is free software; you can redistribute it and/or
266modify it under the same terms as Perl itself.