<div dir="ltr"><div class="gmail_default" style="font-family:courier new,monospace"><br></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Nov 19, 2013 at 7:16 PM, Andrew Whatson <span dir="ltr"><<a href="mailto:whatson@gmail.com" target="_blank">whatson@gmail.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Fulko,<br>
<br>
I think you need to turn on autoflush on STDOUT.  After putting $|=1,<br></blockquote><div><br><div class="gmail_default" style="font-family:courier new,monospace;display:inline">Where did you put it, because no mater what I do,<br>

it doesn't make a difference for me.<br><br></div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I get the following output which seems correct:<br>
<br>
parent tx 'first send'<br>
parent rx: child started<br>
parent rx: child rx: first send to child<br>
<br>
parent rx: child timer<br>
parent tx<br>
parent rx: child rx: sent to child<br>
<br>
parent rx: child timer<br>
parent tx<br>
parent rx: child timer<br>
parent rx: child rx: sent to child<br>
<br>
parent rx: child timer<br>
parent tx<br>
parent rx: child rx: sent to child<br>
<br>
Regards,<br>
Andrew Whatson<br>
<div><div class="h5"><br>
On 20 November 2013 06:03, Fulko Hew <<a href="mailto:fulko.hew@gmail.com">fulko.hew@gmail.com</a>> wrote:<br>
> I'm trying to use AnyEvent:Run, but I need to make my child smarter.<br>
> 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>
> 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>
> 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<br>
> "parent tx\n";},<br>
> );<br>
> $child->push_write("first send to child\n"); print "parent tx 'first<br>
> send'\n";<br>
> my $cv = AnyEvent->condvar;<br>
> $cv->wait;<br>
><br>
><br>
</div></div>> _______________________________________________<br>
> anyevent mailing list<br>
> <a href="mailto:anyevent@lists.schmorp.de">anyevent@lists.schmorp.de</a><br>
> <a href="http://lists.schmorp.de/mailman/listinfo/anyevent" target="_blank">http://lists.schmorp.de/mailman/listinfo/anyevent</a><br>
</blockquote></div><br></div></div>