Patrick LeBoutillier > IO-Mux-0.08 > IO::Mux

Download:
IO-Mux-0.08.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 0.08   Source  

NAME ^

IO::Mux - Multiplex several virtual streams over a real pipe/socket

SYNOPSIS ^

  use IO::Mux ;

  pipe(R, W) ;

  if (fork){
      my $mux = new IO::Mux(\*W) ;
      my $alice = $mux->new_handle() ;
      open($alice, 'alice') ;
      my $bob = $mux->new_handle() ;
      open($bob, 'bob') ;

      print $alice "Hi Alice!\n" ;
      print $bob "Hi Bob!\n" ;
  }
  else {
      my $mux = new IO::Mux(\*R) ;
      my $alice = $mux->new_handle() ;
      open($alice, 'alice') ;
      my $bob = $mux->new_handle() ;
      open($bob, 'bob') ;

      print scalar(<$bob>) ;
      print scalar(<$alice>) ;
  }

DESCRIPTION ^

IO::Mux allows you to multiplex several virtual streams over a single pipe or socket. This is achieved by creating an IO::Mux object on each end of the real stream and then creating virtual handles (IO::Mux::Handle objects) from these IO::Mux objects.

Each IO::Mux::Handle object is assigned a unique identifier when opened, and IO::Mux::Handle objects on each end of the real stream that have the same identifier are "mapped" to each other.

CONSTRUCTOR ^

new ( HANDLE )

Creates a new IO::Mux object that multiplexes over HANDLE. autoflush will be turned on for HANDLE.

METHODS ^

$mux->get_handle ()

Returns the handle passed when $mux was created. Note that if a GLOB reference was originately passed, only the IO component of the glob will be returned. Therefore it is possible that the value returned here be different than the one actually passed in the constructor.

$mux->new_handle ()

Convenience method. Returns a new IO::Mux::Handle object created on $mux. Is equivalent to:

  new IO::Mux::Handle($mux) ;

The handle must then be opened before being used. See IO::Mux::Handle for more details.

NOTE ^

Once a handle has been passed to an IO::Mux object, it is important that it is not written to/read from directly as this will corrupt the IO::Mux stream. Once the IO::Mux objects on both ends of the stream are out of scope (and have no data pending), normal usage of the handleis can resume.

SEE ALSO ^

IO::Mux::Handle

AUTHOR ^

Patrick LeBoutillier, <patl@cpan.org>

COPYRIGHT AND LICENSE ^

Copyright (C) 2005 by Patrick LeBoutillier

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.5 or, at your option, any later version of Perl 5 you may have available.

syntax highlighting: