Detecting EOF in a on_read for AnyEvent::Handle
Marios Titas
redneb8888 at gmail.com
Sun Dec 11 19:52:43 CET 2011
Consider the following scenario: an AnyEvent::Handle object receives
EOF at a moment when the read queue is empty but an on_read callback
has been specified. As a result, the on_read callback will then be
called one last time where it will have a last chance to "consume" all
data from the read buffer. If it doesn't do that then an error will be
triggered. My question is, is there a way for this callback to know
that it has been called because an EOF and not because of new data?
This is useful when you want to do some parsing of the read buffer
which depends on whether an EOF has been reached or not. The same
situation can happen with push_read (the typeless version).
Right now it is possible to check that by looking at $handle->{_eof}
but of course this is problematic as it is not documented.
More information about the anyevent
mailing list