AE::HTTP http_get with want_body_handle doesn't work unless either an on_eof or on_error callback is defined

Peter Juhasz pjuhasz at uhusystems.com
Wed Jan 11 15:52:52 CET 2017


On Wed, 2017-01-11 at 08:04 +0100, Marc Lehmann wrote:
> On Mon, Jan 09, 2017 at 06:36:05PM +0100, Peter Juhasz <pjuhasz at uhusy
> stems.com> wrote:
> > 	sub {
> > 		my $handle = shift;
> 
> $handle is a local variable, it will go out of scope as soon as the
> sub
> returns.
> 

Thanks for the detailed answer!

I've since realized on my own that this happens.
The underlying reason for this, however, is in this line in AE::HTTP:

 $finish->(delete $state{handle});

That is, from this point on the only reference to the AE::Handle object
will be the variable in the callback sub. This is mentioned in the
documentation ("The user is responsible for this handle"), but perhaps
a more explicit explanation of this specific issue would be useful.
It's not just that the handle "will not be used by this module
anymore", but the module gives up ownership of the handle, essentially
transferring it to to the user.

Thanks,
Peter




More information about the anyevent mailing list