… | |
… | |
93 | called. |
93 | called. |
94 | |
94 | |
95 | On callback entrance, the value of C<$!> contains the operating system |
95 | On callback entrance, the value of C<$!> contains the operating system |
96 | error (or C<ENOSPC>, C<EPIPE> or C<EBADMSG>). |
96 | error (or C<ENOSPC>, C<EPIPE> or C<EBADMSG>). |
97 | |
97 | |
|
|
98 | The callbakc should throw an exception. If it returns, then |
|
|
99 | AnyEvent::Handle will C<croak> for you. |
|
|
100 | |
98 | While not mandatory, it is I<highly> recommended to set this callback, as |
101 | While not mandatory, it is I<highly> recommended to set this callback, as |
99 | you will not be notified of errors otherwise. The default simply calls |
102 | you will not be notified of errors otherwise. The default simply calls |
100 | die. |
103 | die. |
101 | |
104 | |
102 | =item on_read => $cb->($self) |
105 | =item on_read => $cb->($self) |
… | |
… | |
209 | { |
212 | { |
210 | local $!; |
213 | local $!; |
211 | $self->_shutdown; |
214 | $self->_shutdown; |
212 | } |
215 | } |
213 | |
216 | |
214 | if ($self->{on_error}) { |
|
|
215 | $self->{on_error}($self); |
217 | $self->{on_error}($self) |
216 | } else { |
218 | if $self->{on_error}; |
|
|
219 | |
217 | Carp::croak "AnyEvent::Handle uncaught fatal error: $!"; |
220 | Carp::croak "AnyEvent::Handle uncaught fatal error: $!"; |
218 | } |
|
|
219 | } |
221 | } |
220 | |
222 | |
221 | =item $fh = $handle->fh |
223 | =item $fh = $handle->fh |
222 | |
224 | |
223 | This method returns the file handle of the L<AnyEvent::Handle> object. |
225 | This method returns the file handle of the L<AnyEvent::Handle> object. |
… | |
… | |
469 | |
471 | |
470 | if ( |
472 | if ( |
471 | defined $self->{rbuf_max} |
473 | defined $self->{rbuf_max} |
472 | && $self->{rbuf_max} < length $self->{rbuf} |
474 | && $self->{rbuf_max} < length $self->{rbuf} |
473 | ) { |
475 | ) { |
474 | $! = &Errno::ENOSPC; return $self->error; |
476 | $! = &Errno::ENOSPC; |
|
|
477 | $self->error; |
475 | } |
478 | } |
476 | |
479 | |
477 | return if $self->{in_drain}; |
480 | return if $self->{in_drain}; |
478 | local $self->{in_drain} = 1; |
481 | local $self->{in_drain} = 1; |
479 | |
482 | |
… | |
… | |
481 | no strict 'refs'; |
484 | no strict 'refs'; |
482 | if (my $cb = shift @{ $self->{queue} }) { |
485 | if (my $cb = shift @{ $self->{queue} }) { |
483 | unless ($cb->($self)) { |
486 | unless ($cb->($self)) { |
484 | if ($self->{eof}) { |
487 | if ($self->{eof}) { |
485 | # no progress can be made (not enough data and no data forthcoming) |
488 | # no progress can be made (not enough data and no data forthcoming) |
486 | $! = &Errno::EPIPE; return $self->error; |
489 | $! = &Errno::EPIPE; |
|
|
490 | $self->error; |
487 | } |
491 | } |
488 | |
492 | |
489 | unshift @{ $self->{queue} }, $cb; |
493 | unshift @{ $self->{queue} }, $cb; |
490 | return; |
494 | return; |
491 | } |
495 | } |
… | |
… | |
497 | && $len == length $self->{rbuf} # and no data has been consumed |
501 | && $len == length $self->{rbuf} # and no data has been consumed |
498 | && !@{ $self->{queue} } # and the queue is still empty |
502 | && !@{ $self->{queue} } # and the queue is still empty |
499 | && $self->{on_read} # and we still want to read data |
503 | && $self->{on_read} # and we still want to read data |
500 | ) { |
504 | ) { |
501 | # then no progress can be made |
505 | # then no progress can be made |
502 | $! = &Errno::EPIPE; return $self->error; |
506 | $! = &Errno::EPIPE; |
|
|
507 | $self->error; |
503 | } |
508 | } |
504 | } else { |
509 | } else { |
505 | # read side becomes idle |
510 | # read side becomes idle |
506 | delete $self->{rw}; |
511 | delete $self->{rw}; |
507 | return; |
512 | return; |