Mark Overmeer > IOMux > IOMux::Select

Download:
IOMux-0.13.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 0.13   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.

Extends "DESCRIPTION" in IOMux.

METHODS ^

Extends "METHODS" in IOMux.

Constructors

Extends "Constructors" in IOMux.

IOMux::Select->new(OPTIONS)

Inherited, see "Constructors" in IOMux

Accessors

Extends "Accessors" in IOMux.

User interface

Extends "User interface" in IOMux.

$obj->add(HANDLER|BUNDLE)

Inherited, see "User interface" in IOMux

$obj->endLoop(BOOLEAN)

Inherited, see "User interface" in IOMux

$obj->loop( [HEARTBEAT] )

Inherited, see "User interface" in IOMux

$obj->open(MODE, PARAMS)

Inherited, 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

Extends "For internal use" in IOMux.

$obj->changeTimeout(FILENO, OLDTIMEOUT, NEWTIMEOUT)

Inherited, see "For internal use" in IOMux

$obj->fdset(FILENO, STATE, READ, WRITE, EXCEPT)

Inherited, see "For internal use" in IOMux

$obj->handler( FILENO, [HANDLER] )

Inherited, see "For internal use" in IOMux

$obj->handlers()

Inherited, see "For internal use" in IOMux

$obj->remove(FILENO)

Inherited, 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 ^

Extends "DETAILS" in IOMux.

Installation

Extends "Installation" in IOMux.

Event managers

Extends "Event managers" in IOMux.

File handles

Extends "File handles" in IOMux.

Implementation limitations

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!

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.

SEE ALSO ^

This module is part of IOMux distribution version 0.13, built on July 21, 2015. 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-2015 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: