in reply to Alternative for Select for pipes in Windows?
One way:
use threads qw( async ); use Thread::Queue qw( ); my $q = Threads::Queue->new(); async { while (<STDIN>) { $q->enqueue(...); } $q->enqueue(...); }; async { while (<$fr_child_pipe>) { $q->enqueue(...); } $q->enqueue(...); }; while (defined(my $item = $q->dequeue())) { ... }
Another solution would be to create socket pairs (which are selectable), and have threads that simply convert the pipes into sockets. That would allow you to use existing code.
use threads qw( async ); use Win32::Socketpair qw( winsocketpair ); my ($fr_parent_sock, $fr_parent_sock_writer) = winsocketpair(); async { print($fr_parent_sock_writer $_) while <STDIN>; close($fr_parent_sock_writer); }; my ($fr_child_sock, $fr_child_sock_writer) = winsocketpair(); async { print($fr_child_sock_writer $_) while <$fr_child_pipe>; close($fr_child_sock_writer); }; ... select $fr_parent_sock and $fr_child_sock ...
(You could avoid the second thread by tying the socket directly to the child's STDOUT.)
Update: Fleshed out the code for the second solution, and added a link to the module.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Alternative for Select for pipes in Windows?
by matematiko (Novice) on Nov 06, 2010 at 03:58 UTC | |
by BrowserUk (Patriarch) on Nov 06, 2010 at 05:07 UTC | |
by ikegami (Patriarch) on Nov 06, 2010 at 05:26 UTC | |
by BrowserUk (Patriarch) on Nov 06, 2010 at 06:11 UTC | |
by matematiko (Novice) on Nov 08, 2010 at 00:38 UTC | |
by BrowserUk (Patriarch) on Nov 08, 2010 at 00:52 UTC | |
|
Re^2: Alternative for Select for pipes in Windows?
by BrowserUk (Patriarch) on Nov 06, 2010 at 01:39 UTC | |
by ikegami (Patriarch) on Nov 06, 2010 at 05:22 UTC | |
by BrowserUk (Patriarch) on Nov 06, 2010 at 06:17 UTC |