Detecting EOF in a on_read for AnyEvent::Handle
Marios Titas
redneb8888 at gmail.com
Tue Dec 13 06:31:37 CET 2011
Marc,
Thank you for you response.
On Mon, Dec 12, 2011 at 07:58, Marc Lehmann <schmorp at schmorp.de> wrote:
> On Sun, Dec 11, 2011 at 03:26:57PM -0500, Marios Titas <redneb8888 at gmail.com> wrote:
>> The AnyEvent::Handle man page provides two examples of serving
>> requests in a loop. The first one doesn't work for the above case
>> because it cannot handle the EOF correctly (it will throw an error).
>
> It certainly _does_ handle EOF correctly: an unexpected EOF is an error
> condition in that protocol - this is explained in the text as well.
Yes, I understand that. I meant that it doesn't handle EOF correctly
for the protocol I described above which is why you cannot use this
approach. This is something that is already mentioned in the
documentation. I was merely repeating what you say in the
documentation and trying to explain why I had to use the second
example.
> If you can't handle client data when it receives you either have to
> postpone it, tell the handle to stop reading, or use a blocking approach
> where you don't read as long as you handle a request.
Yes, that's exactly what I want to do: not process any new client data
until I have finished processing the previous request.
My first approach was to use stop_read/start_read but I couldn't make
it work this way. I either don't understand something obvious or there
is a bug in stop_read. Consider the following example:
https://gist.github.com/1470627
My understanding is that in this case, on_read should be called only
once, but when I run this, it gets called more than once.
The only reason I was trying to do more complicated things was because
the stop_read/start_read approach failed.
More information about the anyevent
mailing list