NAME
IO::Mux::Select - simplify use of select()
INHERITANCE
IO::Mux::Select
is a IO::Mux
SYNOPSIS
use IO::Mux::Select;
my $mux = IO::Mux::Select->new;
my $server = IO::Mux::Service::TCP->new(...);
$mux->add($server);
$mux->loop;
DESCRIPTION
Multiplexer implemented around the select()
system call. This select()
is usually less powerful and slower than the poll()
call (implemented in IO::Mux::Poll) however probably available on more systems.
METHODS
Constructors
- IO::Mux::Select->new(OPTIONS) See "Constructors" in IO::Mux
Accessors
User interface
- $obj->add(HANDLER|BUNDLE) See "User interface" in IO::Mux
- $obj->endLoop(BOOLEAN) See "User interface" in IO::Mux
- $obj->loop([HEARTBEAT]) See "User interface" in IO::Mux
- $obj->open(MODE, PARAMS) See "User interface" in IO::Mux
- $obj->showFlags([FLAGS|(RDFLAGS,WRFLAGS,EXFLAGS)])
-
Display the select FLAGS (one of the values received from selectFlags()) or all of these flags. You may also specify three sets of FLAGS explicitly.
When three sets of FLAGS are passed, it will result in three lines preceeded with labels. With only one set, no label will be used.
The flagged filenos are shown numerically (modulo 10) and positionally. For instance, if both filehandle 1 and 4 are flagged, the output string will be
-1--4
.example:
my ($rd, $wr, $er) = $client->selectFlags; print "read flags: ",$client->showFlags($rd); print $client->showFlags(rd, $wr, $er); print $client->showFlags; # saem result print $client->showFlags($client->waitFlags);
For internal use
- $obj->changeTimeout(FILENO, OLDTIMEOUT, NEWTIMEOUT) See "For internal use" in IO::Mux
- $obj->fdset(FILENO, STATE, READ, WRITE, EXCEPT) See "For internal use" in IO::Mux
- $obj->handler(FILENO, [HANDLER]) See "For internal use" in IO::Mux
- $obj->handlers See "For internal use" in IO::Mux
- $obj->remove(FILENO) See "For internal use" in IO::Mux
- $obj->selectFlags
-
Returns a list of three: respectively the read, write and error flags which show the file numbers that the internal
select()
call has flagged as needing inspection.This method can, for instance, be used from within the heartbeat routine.
example:
$mux->loop(\&heartbeat); sub heartbeat($$$) { my ($mux, $numready, $timeleft) = @_; my ($rd, $rw, $ex) = $mux->selectFlags; if(vec($rd, $fileno, 1)==1) {...} }
- $obj->waitFlags
-
Returns a list of three: respectively the read, write and error flags which show how the files are enlisted.
DETAILS
Installation
Event managers
File handles
Alternatives
IO::Multiplex
Difference to IO::Multiplex
IO::Async / Net::Async
Implementation limitations
Limitations on Windows
The select()
system call is very limited: it only works on sockets, not on files or pipes. This means that the process will stall on each file access and pipe activity.
Limitations on UNIX/Linux
Be careful with the use of files. You should open files with the non-stdio version of open()
, with option O_NONBLOCK
. But even then, asynchronous support for reading and writing files and pipes may be lacking on your UNIX dialect.
The select
system call is very powerful, however the (UNIX) standard specifies quite a weak subset of the features usually offered. The standard only requires sockets to be supported. The Windows/cygwin implementation limits itself to that. Modern UNIX dialects usually also support normal pipes and file handlers to be attached.
Please help extending the list of OS specific limitations below!
SEE ALSO
This module is part of IO-Mux distribution version 0.11, built on January 26, 2011. Website: http://perl.overmeer.net/ All modules in this suite: "Any::Daemon", "IO::Mux", and "IO::Mux::HTTP".
Please post questions or ideas to perl@overmeer.net
LICENSE
Copyrights 2011 by Mark Overmeer. For other contributors see ChangeLog.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See http://www.perl.com/perl/misc/Artistic.html
1 POD Error
The following errors were encountered while parsing the POD:
- Around line 152:
=back without =over