Mark Overmeer > IOMux > IOMux::Select

Download:
IOMux-0.12.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 0.12   Source  

NAME ^

IOMux::Select - simplify use of select()

INHERITANCE ^

 IOMux::Select
   is a IOMux

SYNOPSIS ^

  use IOMux::Select;

  my $mux    = IOMux::Select->new;
  my $server = IOMux::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 IOMux::Poll) however probably available on more systems.

METHODS ^

Constructors

IOMux::Select->new(OPTIONS) See "Constructors" in IOMux

Accessors

User interface

$obj->add(HANDLER|BUNDLE) See "User interface" in IOMux
$obj->endLoop(BOOLEAN) See "User interface" in IOMux
$obj->loop([HEARTBEAT]) See "User interface" in IOMux
$obj->open(MODE, PARAMS) See "User interface" in IOMux
$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 IOMux
$obj->fdset(FILENO, STATE, READ, WRITE, EXCEPT) See "For internal use" in IOMux
$obj->handler(FILENO, [HANDLER]) See "For internal use" in IOMux
$obj->handlers See "For internal use" in IOMux
$obj->remove(FILENO) See "For internal use" in IOMux
$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 IOMux distribution version 0.12, built on January 27, 2011. Website: http://perl.overmeer.net/ All modules in this suite: "Any::Daemon", "IOMux", and "IOMux::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

syntax highlighting: