Why doesn't on_eof get called on this example?
Marc Lehmann
schmorp at schmorp.de
Tue Jun 24 13:21:45 CEST 2014
> http://stackoverflow.com/questions/24373840/why-isnt-on-eof-called-in-this-anyeventhandle-example
Well, somebody answered that question.
>> I think that when there is no on_read handler and read queue is empty ( there is no outstanding push_read requests ) AE::Handle is unable to decide
>> whether to call on_eof or on_error. You should be able to construct AE::handle with no on_read and empty queue. Then make push_read( line => ) request and
>> get on_error called.
>
>
> Why is AE::Handle unable to decide? Why couldn't it just call on_eof in that case?
While I wouldn't have framed this as a problem of deciding, it kind of
is a problem of deciding: To decide whether the EOF is an error or not,
AnyEvent::Handle would need to know what you want to with the data.
For example, if you need to e.g. look up the client ip address in a
database (a potentially lengthy process) before starting to accept data,
you might get an unexpected error if AnyEvent started to read, which
is why AnyEvent doesn't read data unless you express your intent to
receive some. and in the POSIX API, EOF is really some kind of data (the
zero-length kind of data :).
(The underlying problem is slightly more complicated, and is explained in
the stackoverflow answer).
--
The choice of a Deliantra, the free code+content MORPG
-----==- _GNU_ http://www.deliantra.net
----==-- _ generation
---==---(_)__ __ ____ __ Marc Lehmann
--==---/ / _ \/ // /\ \/ / schmorp at schmorp.de
-=====/_/_//_/\_,_/ /_/\_\
More information about the anyevent
mailing list