Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

io::bufferedselect(3pm) [debian man page]

IO::BufferedSelect(3pm) 				User Contributed Perl Documentation				   IO::BufferedSelect(3pm)

NAME
IO::BufferedSelect - Line-buffered select interface SYNOPSIS
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"; } } DESCRIPTION
The "select" system call (and the "IO::Select" 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 "sysread" and "syswrite" rather than Perl's buffered I/O functions. In the case of reading, there are two issues with combining "select" with "readline": (1) "select" might block but the data we want is already in Perl's input buffer, ready to be slurped in by "readline"; and(2) "select" might indicate that data is available, but "readline" will block because there isn't a full $/-terminated line available. The purpose of this module is to implement a buffered version of the "select" interface that operates on lines, rather than characters. Given a set of filehandles, it will block until a full line is available on one or more of them. Note that this module is currently limited, in that(1) it only does "select" for readability, not writability or exceptions; and(2) it does not support arbitrary line separators ($/): lines must be delimited by newlines. CONSTRUCTOR
new ( HANDLES ) Create a "BufferedSelect" object for a set of filehandles. Note that because this class buffers input from these filehandles internally, you should only use the "BufferedSelect" object for reading from them (you shouldn't read from them directly or pass them to other BufferedSelect instances). METHODS
read_line read_line ($timeout) read_line ($timeout, @handles) Block until a line is available on one of the filehandles. If $timeout is "undef", it blocks indefinitely; otherwise, it returns after at most $timeout seconds. If @handles is specified, then only these filehandles will be considered; otherwise, it will use all filehandles passed to the constructor. Returns a list of pairs "[$fh, $line]", where $fh is a filehandle and $line is the line that was read (including the newline, ala "readline"). If the filehandle reached EOF, then $line will be undef. Note that "reached EOF" is to be interpreted in the buffered sense: if a filehandle is at EOF but there are newline-terminated lines in "BufferedSelect"'s buffer, "read_line" will continue to return lines until the buffer is empty. SEE ALSO
IO::Select AUTHOR
Antal Novak, <afn@cpan.org> COPYRIGHT AND LICENSE
Copyright (C) 2007 by Antal Novak 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. perl v5.10.1 2007-03-13 IO::BufferedSelect(3pm)

Check Out this Related Man Page

IO::Select(3perl)					 Perl Programmers Reference Guide					 IO::Select(3perl)

NAME
IO::Select - OO interface to the select system call SYNOPSIS
use IO::Select; $s = IO::Select->new(); $s->add(*STDIN); $s->add($some_handle); @ready = $s->can_read($timeout); @ready = IO::Select->new(@handles)->can_read(0); DESCRIPTION
The "IO::Select" package implements an object approach to the system "select" function call. It allows the user to see what IO handles, see IO::Handle, are ready for reading, writing or have an exception pending. CONSTRUCTOR
new ( [ HANDLES ] ) The constructor creates a new object and optionally initialises it with a set of handles. METHODS
add ( HANDLES ) Add the list of handles to the "IO::Select" object. It is these values that will be returned when an event occurs. "IO::Select" keeps these values in a cache which is indexed by the "fileno" of the handle, so if more than one handle with the same "fileno" is specified then only the last one is cached. Each handle can be an "IO::Handle" object, an integer or an array reference where the first element is an "IO::Handle" or an integer. remove ( HANDLES ) Remove all the given handles from the object. This method also works by the "fileno" of the handles. So the exact handles that were added need not be passed, just handles that have an equivalent "fileno" exists ( HANDLE ) Returns a true value (actually the handle itself) if it is present. Returns undef otherwise. handles Return an array of all registered handles. can_read ( [ TIMEOUT ] ) Return an array of handles that are ready for reading. "TIMEOUT" is the maximum amount of time to wait before returning an empty list, in seconds, possibly fractional. If "TIMEOUT" is not given and any handles are registered then the call will block. can_write ( [ TIMEOUT ] ) Same as "can_read" except check for handles that can be written to. has_exception ( [ TIMEOUT ] ) Same as "can_read" except check for handles that have an exception condition, for example pending out-of-band data. count () Returns the number of handles that the object will check for when one of the "can_" methods is called or the object is passed to the "select" static method. bits() Return the bit string suitable as argument to the core select() call. select ( READ, WRITE, EXCEPTION [, TIMEOUT ] ) "select" is a static method, that is you call it with the package name like "new". "READ", "WRITE" and "EXCEPTION" are either "undef" or "IO::Select" objects. "TIMEOUT" is optional and has the same effect as for the core select call. The result will be an array of 3 elements, each a reference to an array which will hold the handles that are ready for reading, writing and have exceptions respectively. Upon error an empty list is returned. EXAMPLE
Here is a short example which shows how "IO::Select" could be used to write a server which communicates with several sockets while also listening for more connections on a listen socket use IO::Select; use IO::Socket; $lsn = IO::Socket::INET->new(Listen => 1, LocalPort => 8080); $sel = IO::Select->new( $lsn ); while(@ready = $sel->can_read) { foreach $fh (@ready) { if($fh == $lsn) { # Create a new socket $new = $lsn->accept; $sel->add($new); } else { # Process socket # Maybe we have finished with the socket $sel->remove($fh); $fh->close; } } } AUTHOR
Graham Barr. Currently maintained by the Perl Porters. Please report all bugs to <perl5-porters@perl.org>. COPYRIGHT
Copyright (c) 1997-8 Graham Barr <gbarr@pobox.com>. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.14.2 2011-09-19 IO::Select(3perl)
Man Page