<div dir="ltr"><div class="gmail_default" style="font-family:courier new,monospace">I'm trying to use AnyEvent:Run, but I need to make my child smarter.<br></div><div class="gmail_default" style="font-family:courier new,monospace">
and make it an AnyEvent style process that uses 'event driven I/O'.<br>But I can't seem to get anywhere, and I'm obviously missing... something.<br><br></div><div class="gmail_default" style="font-family:courier new,monospace">
I'm attempting the test example below.<br><br>What I see is the child successfully sending and the parent receiving.<br>But I'm not getting the parent-to-child pat, and I don't know if its a<br>problem in parent or in the child, or I'm just doing it wrong.<br>
<br></div><div class="gmail_default" style="font-family:courier new,monospace"></div><div class="gmail_default" style="font-family:courier new,monospace">use strict;<br>use warnings;<br>use Socket;<br>use AnyEvent;<br>use AnyEvent::Run;<br>
use AnyEvent::Handle;<br><br>sub send_msg_to_parent { print "$_[0]\n"; }<br><br>sub child_proc {<br> my $child_hdl = new AnyEvent::Handle (<br> fh => \*STDIN,<br> on_read => sub {<br> my $hdl = shift;<br>
my $d = $hdl->{rbuf};<br> $hdl->{rbuf} = '';<br> send_msg_to_parent("child rx: $d");<br> },<br> );<br> my $child_timer = AnyEvent->timer ( # send a watchdog msg<br>
after => 2,<br> interval => 2,<br> cb => sub {send_msg_to_parent("child timer"),<br> );<br> send_msg_to_parent("child started");<br> my $child_cv = AnyEvent->condvar;<br>
$child_cv->wait;<br>}<br><br><br>my $child = AnyEvent::Run->new(<br> cmd => sub { child_proc() },<br> on_read => sub {<br> my $hdl = shift;<br> my $d = $hdl->{rbuf};<br>
$hdl->{rbuf} = '';<br> print "parent rx: $d";<br> },<br> on_error => sub { print "child died\n"; },<br>);<br>my $parent_timer = AnyEvent->timer (<br>
after => 3,<br> interval => 3,<br> cb => sub { $child->push_write("sent to child\n"); print "parent tx\n";},<br>);<br>$child->push_write("first send to child\n"); print "parent tx 'first send'\n";<br>
my $cv = AnyEvent->condvar;<br>$cv->wait;<br><br></div></div>