… | |
… | |
72 | The filehandle this L<AnyEvent::Handle> object will operate on. |
72 | The filehandle this L<AnyEvent::Handle> object will operate on. |
73 | |
73 | |
74 | NOTE: The filehandle will be set to non-blocking (using |
74 | NOTE: The filehandle will be set to non-blocking (using |
75 | AnyEvent::Util::fh_nonblocking). |
75 | AnyEvent::Util::fh_nonblocking). |
76 | |
76 | |
77 | =item on_eof => $cb->($self) [MANDATORY] |
77 | =item on_eof => $cb->($self) |
78 | |
78 | |
79 | Set the callback to be called on EOF. |
79 | Set the callback to be called on EOF. |
|
|
80 | |
|
|
81 | While not mandatory, it is highly recommended to set an eof callback, |
|
|
82 | otherwise you might end up with a closed socket while you are still |
|
|
83 | waiting for data. |
80 | |
84 | |
81 | =item on_error => $cb->($self) |
85 | =item on_error => $cb->($self) |
82 | |
86 | |
83 | This is the fatal error callback, that is called when, well, a fatal error |
87 | This is the fatal error callback, that is called when, well, a fatal error |
84 | ocurs, such as not being able to resolve the hostname, failure to connect |
88 | ocurs, such as not being able to resolve the hostname, failure to connect |
… | |
… | |
148 | |
152 | |
149 | $self->{fh} or Carp::croak "mandatory argument fh is missing"; |
153 | $self->{fh} or Carp::croak "mandatory argument fh is missing"; |
150 | |
154 | |
151 | AnyEvent::Util::fh_nonblocking $self->{fh}, 1; |
155 | AnyEvent::Util::fh_nonblocking $self->{fh}, 1; |
152 | |
156 | |
153 | $self->on_eof ((delete $self->{on_eof} ) or Carp::croak "mandatory argument on_eof is missing"); |
157 | $self->on_eof (delete $self->{on_eof} ) if $self->{on_eof}; |
154 | |
|
|
155 | $self->on_error (delete $self->{on_error}) if $self->{on_error}; |
158 | $self->on_error (delete $self->{on_error}) if $self->{on_error}; |
156 | $self->on_drain (delete $self->{on_drain}) if $self->{on_drain}; |
159 | $self->on_drain (delete $self->{on_drain}) if $self->{on_drain}; |
157 | $self->on_read (delete $self->{on_read} ) if $self->{on_read}; |
160 | $self->on_read (delete $self->{on_read} ) if $self->{on_read}; |
158 | |
161 | |
159 | $self->start_read; |
162 | $self->start_read; |
… | |
… | |
400 | } |
403 | } |
401 | } |
404 | } |
402 | |
405 | |
403 | if ($self->{eof}) { |
406 | if ($self->{eof}) { |
404 | $self->_shutdown; |
407 | $self->_shutdown; |
405 | $self->{on_eof}($self); |
408 | $self->{on_eof}($self) |
|
|
409 | if $self->{on_eof}; |
406 | } |
410 | } |
407 | } |
411 | } |
408 | |
412 | |
409 | =item $handle->on_read ($cb) |
413 | =item $handle->on_read ($cb) |
410 | |
414 | |