|
IO::Mux - Multiplex several virtual streams over a real pipe/socket |
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>) ;
}
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.
IO::Mux object that multiplexes over HANDLE. autoflush will
be turned on for HANDLE.
new IO::Mux::Handle($mux) ;
The handle must then be opened before being used. See the IO::Mux::Handle manpage for more details.
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.
Patrick LeBoutillier, <patl@cpan.org>
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.
|
IO::Mux - Multiplex several virtual streams over a real pipe/socket |