View on
Mark Overmeer > IOMux-0.12 > IOMux::Select



Annotate this POD

View/Report Bugs
Module Version: 0.12   Source   Latest Release: IOMux-1.00


IOMux::Select - simplify use of select()


   is a IOMux


  use IOMux::Select;

  my $mux    = IOMux::Select->new;
  my $server = IOMux::Service::TCP->new(...);


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.



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


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

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.


  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

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.


  sub heartbeat($$$)
  {   my ($mux, $numready, $timeleft) = @_;
      my ($rd, $rw, $ex) = $mux->selectFlags;
      if(vec($rd, $fileno, 1)==1) {...}

Returns a list of three: respectively the read, write and error flags which show how the files are enlisted.



Event managers

File handles



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!


This module is part of IOMux distribution version 0.12, built on January 27, 2011. Website: All modules in this suite: "Any::Daemon", "IOMux", and "IOMux::HTTP".

Please post questions or ideas to


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

syntax highlighting: