.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "IO::BufferedSelect 3pm" .TH IO::BufferedSelect 3pm "2022-11-20" "perl v5.36.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" IO::BufferedSelect \- Line\-buffered select interface .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 12 \& use IO::BufferedSelect; \& my $bs = new BufferedSelect($fh1, $fh2); \& while(1) \& { \& my @ready = $bs\->read_line(); \& foreach(@ready) \& { \& my ($fh, $line) = @$_; \& my $fh_name = ($fh == $fh1 ? "fh1" : "fh2"); \& print "$fh_name: $line"; \& } \& } .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" The \f(CW\*(C`select\*(C'\fR system call (and the \f(CW\*(C`IO::Select\*(C'\fR interface) allows us to process multiple streams simultaneously, blocking until one or more of them is ready for reading or writing. Unfortunately, this requires us to use \f(CW\*(C`sysread\*(C'\fR and \&\f(CW\*(C`syswrite\*(C'\fR rather than Perl's buffered I/O functions. In the case of reading, there are two issues with combining \f(CW\*(C`select\*(C'\fR with \f(CW\*(C`readline\*(C'\fR: (1) \f(CW\*(C`select\*(C'\fR might block but the data we want is already in Perl's input buffer, ready to be slurped in by \f(CW\*(C`readline\*(C'\fR; and (2) \f(CW\*(C`select\*(C'\fR might indicate that data is available, but \f(CW\*(C`readline\*(C'\fR will block because there isn't a full \&\f(CW$/\fR\-terminated line available. .PP The purpose of this module is to implement a buffered version of the \f(CW\*(C`select\*(C'\fR interface that operates on \fIlines\fR, rather than characters. Given a set of filehandles, it will block until a full line is available on one or more of them. .PP Note that this module is currently limited, in that (1) it only does \f(CW\*(C`select\*(C'\fR for readability, not writability or exceptions; and (2) it does not support arbitrary line separators (\f(CW$/\fR): lines must be delimited by newlines. .SH "CONSTRUCTOR" .IX Header "CONSTRUCTOR" .IP "new ( \s-1HANDLES\s0 )" 4 .IX Item "new ( HANDLES )" Create a \f(CW\*(C`BufferedSelect\*(C'\fR object for a set of filehandles. Note that because this class buffers input from these filehandles internally, you should \fBonly\fR use the \f(CW\*(C`BufferedSelect\*(C'\fR object for reading from them (you shouldn't read from them directly or pass them to other BufferedSelect instances). .SH "METHODS" .IX Header "METHODS" .IP "read_line" 4 .IX Item "read_line" .PD 0 .IP "read_line ($timeout)" 4 .IX Item "read_line ($timeout)" .ie n .IP "read_line ($timeout, @handles)" 4 .el .IP "read_line ($timeout, \f(CW@handles\fR)" 4 .IX Item "read_line ($timeout, @handles)" .PD Block until a line is available on one of the filehandles. If \f(CW$timeout\fR is \&\f(CW\*(C`undef\*(C'\fR, it blocks indefinitely; otherwise, it returns after at most \&\f(CW$timeout\fR seconds. .Sp If \f(CW@handles\fR is specified, then only these filehandles will be considered; otherwise, it will use all filehandles passed to the constructor. .Sp Returns a list of pairs \f(CW\*(C`[$fh, $line]\*(C'\fR, where \f(CW$fh\fR is a filehandle and \&\f(CW$line\fR is the line that was read (including the newline, ala \f(CW\*(C`readline\*(C'\fR). If the filehandle reached \s-1EOF,\s0 then \f(CW$line\fR will be undef. Note that \*(L"reached \&\s-1EOF\*(R"\s0 is to be interpreted in the buffered sense: if a filehandle is at \s-1EOF\s0 but there are newline-terminated lines in \f(CW\*(C`BufferedSelect\*(C'\fR's buffer, \f(CW\*(C`read_line\*(C'\fR will continue to return lines until the buffer is empty. .SH "SEE ALSO" .IX Header "SEE ALSO" IO::Select .SH "AUTHOR" .IX Header "AUTHOR" Antal Novak, .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" Copyright (C) 2007 by Antal Novak .PP This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available.