--- AnyEvent/lib/AnyEvent/Handle.pm 2009/07/16 03:48:33 1.149 +++ AnyEvent/lib/AnyEvent/Handle.pm 2009/07/16 04:16:25 1.150 @@ -82,17 +82,15 @@ Set the callback to be called when an end-of-file condition is detected, i.e. in the case of a socket, when the other side has closed the -connection cleanly. +connection cleanly, and there are no outstanding read requests in the +queue (if there are read requests, then an EOF counts as an unexpected +connection close and will be flagged as an error). For sockets, this just means that the other side has stopped sending data, you can still try to write data, and, in fact, one can return from the EOF callback and continue writing data, as only the read part has been shut down. -While not mandatory, it is I recommended to set an EOF callback, -otherwise you might end up with a closed socket while you are still -waiting for data. - If an EOF condition has been detected but no C callback has been set, then a fatal error will be raised with C<$!> set to <0>. @@ -143,6 +141,11 @@ calling the C callback. If no progress can be made, then a fatal error will be raised (with C<$!> set to C). +Note that, unlike requests in the read queue, an C callback +doesn't mean you I some data: if there is an EOF and there +are outstanding read requests then an error will be flagged. With an +C callback, the C callback will be invoked. + =item on_drain => $cb->($handle) This sets the callback that is called when the write buffer becomes empty @@ -514,7 +517,7 @@ if ($self->{on_timeout}) { $self->{on_timeout}($self); } else { - $self->_error (&Errno::ETIMEDOUT); + $self->_error (Errno::ETIMEDOUT); } # callback could have changed timeout value, optimise @@ -866,7 +869,7 @@ defined $self->{rbuf_max} && $self->{rbuf_max} < length $self->{rbuf} ) { - $self->_error (&Errno::ENOSPC, 1), return; + $self->_error (Errno::ENOSPC, 1), return; } while () { @@ -880,7 +883,7 @@ unless ($cb->($self)) { if ($self->{_eof}) { # no progress can be made (not enough data and no data forthcoming) - $self->_error (&Errno::EPIPE, 1), return; + $self->_error (Errno::EPIPE, 1), return; } unshift @{ $self->{_queue} }, $cb; @@ -898,7 +901,7 @@ ) { # no further data will arrive # so no progress can be made - $self->_error (&Errno::EPIPE, 1), return + $self->_error (Errno::EPIPE, 1), return if $self->{_eof}; last; # more data might arrive @@ -1158,7 +1161,7 @@ # reject if ($reject && $$rbuf =~ $reject) { - $self->_error (&Errno::EBADMSG); + $self->_error (Errno::EBADMSG); } # skip @@ -1184,7 +1187,7 @@ sub { unless ($_[0]{rbuf} =~ s/^(0|[1-9][0-9]*)://) { if ($_[0]{rbuf} =~ /[^0-9]/) { - $self->_error (&Errno::EBADMSG); + $self->_error (Errno::EBADMSG); } return; } @@ -1197,7 +1200,7 @@ if ($_[1] eq ",") { $cb->($_[0], $string); } else { - $self->_error (&Errno::EBADMSG); + $self->_error (Errno::EBADMSG); } }); }); @@ -1297,7 +1300,7 @@ $self->{rbuf} = $json->incr_text; $json->incr_text = ""; - $self->_error (&Errno::EBADMSG); + $self->_error (Errno::EBADMSG); () } else { @@ -1344,7 +1347,7 @@ if (my $ref = eval { Storable::thaw ($_[1]) }) { $cb->($_[0], $ref); } else { - $self->_error (&Errno::EBADMSG); + $self->_error (Errno::EBADMSG); } }); } @@ -1452,7 +1455,7 @@ &_freetls; } else { &_freetls; - $self->_error (&Errno::EPROTO, 1, $err); + $self->_error (Errno::EPROTO, 1, $err); } }