<div dir="ltr"><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Nov 19, 2013 at 8: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:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Anywhere before "first send to child" should work.  Without this, I<br>
see the following output sometimes:<br>
<div class="im"><br>
  parent rx: child timer<br>
  parent tx<br>
  parent rx: child timer<br>
  child rx: sent to child<br>
<br>
</div>The "child timer\n" and "child rx: sent to child\n" messages are being<br>
received together, due to output buffering in the child process.<br>
Turning on autoflush forces the process to send each line separately.<br>
<br>
I hope this is the problem you're seeing - if not, please explain the<br>
problem in more detail.<br></blockquote><div class="h5"><br><div class="gmail_default" style="font-family:courier new,monospace;display:inline">I don't think its the same problem.<br></div><div class="gmail_default" style="font-family:courier new,monospace;display:inline">

With or without the autoflush, I see the same results:<br><br></div>parent tx first send<br>parent rx: child started<br>parent rx: child timer<br>parent tx<br>parent rx: child timer<br>parent rx: child timer<br>parent tx<br>

<br><div class="gmail_default" style="font-family:courier new,monospace">I think its a problem on the receiving end because if I change<br>the receiver to the code below (without the autoflush),<br>just to test the 'echo' part (without the child timer async sender)<br>

the child _does_ receive and transmit.<br><br>sub child_proc {<br>    while (1) {<br>        chomp (my $d = <STDIN>);<br>        print STDERR "child rx: $d\n";;<br>        send_msg_to_parent("echoing...$d");<br>

        sleep 1;<br>    }<br>}<br><br></div><br>
On 20 November 2013 10:40, Fulko Hew <<a href="mailto:fulko.hew@gmail.com">fulko.hew@gmail.com</a>> wrote:<br>

> On Tue, Nov 19, 2013 at 7:16 PM, Andrew Whatson <<a href="mailto:whatson@gmail.com">whatson@gmail.com</a>> wrote:<br>
>><br>
>> Hi Fulko,<br>
>><br>
>> I think you need to turn on autoflush on STDOUT.  After putting $|=1,<br>
<div class="gmail_default" style="font-family:courier new,monospace;display:inline">><br></div>> Where did you put it, because no mater what I do,<br>
> it doesn't make a difference for me.<br>
>><br>
>> 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>
>><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...<br>
>> > 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>
>> > _______________________________________________<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>
><br>
><br>
</div></div><br></div></div>