in reply to Re^2: How to Multiplex a Client using IO::Select
in thread How to Multiplex a Client using IO::Select
One example is, STDIN won't work in Windows with select
So don't insist that everything is selectable. Use select on the sockets which is portable, and use a thread for STDIN. There is only 1 STDIN, so the cost is minimal.
Your main dispatch loop then becomes something like:
my $Qstdin = new Thread::Queue; async { $Qstdin->enqueue( $_ ) while defined( $_ = <STDIN> ); }->detach; ... while( 1 ) { if( my @readers = $selector->can_read( 0.1 ) ) { ## See what they have to say } elsif( my @writers = $selector->can_write( 0.1 ) { ## Tell'em what they need to know } elsif( my @exceptors = $selector->has_exception( 0.1 ) { ## Deal with their tantrums } else { while( $Qstdin->pending ) { my $kbinput = $Qstdin->dequeue; ## do whatever } } }
That should be portable to any OS supporting threads:
That means that all the facilties provided by the local shell, like:
are available without any extra effort, code or complications on your behalf.
|
|---|