… | |
… | |
14 | on_error => sub { |
14 | on_error => sub { |
15 | my ($hdl, $fatal, $msg) = @_; |
15 | my ($hdl, $fatal, $msg) = @_; |
16 | warn "got error $msg\n"; |
16 | warn "got error $msg\n"; |
17 | $hdl->destroy; |
17 | $hdl->destroy; |
18 | $cv->send; |
18 | $cv->send; |
19 | ); |
19 | }; |
20 | |
20 | |
21 | # send some request line |
21 | # send some request line |
22 | $hdl->push_write ("getinfo\015\012"); |
22 | $hdl->push_write ("getinfo\015\012"); |
23 | |
23 | |
24 | # read the response line |
24 | # read the response line |
… | |
… | |
129 | |
129 | |
130 | The actual numeric host and port (the socket peername) are passed as |
130 | The actual numeric host and port (the socket peername) are passed as |
131 | parameters, together with a retry callback. |
131 | parameters, together with a retry callback. |
132 | |
132 | |
133 | When, for some reason, the handle is not acceptable, then calling |
133 | When, for some reason, the handle is not acceptable, then calling |
134 | C<$retry> will continue with the next conenction target (in case of |
134 | C<$retry> will continue with the next connection target (in case of |
135 | multi-homed hosts or SRV records there can be multiple connection |
135 | multi-homed hosts or SRV records there can be multiple connection |
136 | endpoints). When it is called then the read and write queues, eof status, |
136 | endpoints). At the time it is called the read and write queues, eof |
137 | tls status and similar properties of the handle are being reset. |
137 | status, tls status and similar properties of the handle will have been |
|
|
138 | reset. |
138 | |
139 | |
139 | In most cases, ignoring the C<$retry> parameter is the way to go. |
140 | In most cases, ignoring the C<$retry> parameter is the way to go. |
140 | |
141 | |
141 | =item on_connect_error => $cb->($handle, $message) |
142 | =item on_connect_error => $cb->($handle, $message) |
142 | |
143 | |
143 | This callback is called when the conenction could not be |
144 | This callback is called when the connection could not be |
144 | established. C<$!> will contain the relevant error code, and C<$message> a |
145 | established. C<$!> will contain the relevant error code, and C<$message> a |
145 | message describing it (usually the same as C<"$!">). |
146 | message describing it (usually the same as C<"$!">). |
146 | |
147 | |
147 | If this callback isn't specified, then C<on_error> will be called with a |
148 | If this callback isn't specified, then C<on_error> will be called with a |
148 | fatal error instead. |
149 | fatal error instead. |
… | |
… | |
304 | |
305 | |
305 | =item keepalive => <boolean> |
306 | =item keepalive => <boolean> |
306 | |
307 | |
307 | Enables (default disable) the SO_KEEPALIVE option on the stream socket: |
308 | Enables (default disable) the SO_KEEPALIVE option on the stream socket: |
308 | normally, TCP connections have no time-out once established, so TCP |
309 | normally, TCP connections have no time-out once established, so TCP |
309 | conenctions, once established, can stay alive forever even when the other |
310 | connections, once established, can stay alive forever even when the other |
310 | side has long gone. TCP keepalives are a cheap way to take down long-lived |
311 | side has long gone. TCP keepalives are a cheap way to take down long-lived |
311 | TCP connections whent he other side becomes unreachable. While the default |
312 | TCP connections whent he other side becomes unreachable. While the default |
312 | is OS-dependent, TCP keepalives usually kick in after around two hours, |
313 | is OS-dependent, TCP keepalives usually kick in after around two hours, |
313 | and, if the other side doesn't reply, take down the TCP connection some 10 |
314 | and, if the other side doesn't reply, take down the TCP connection some 10 |
314 | to 15 minutes later. |
315 | to 15 minutes later. |
… | |
… | |
374 | C<undef>. |
375 | C<undef>. |
375 | |
376 | |
376 | =item tls => "accept" | "connect" | Net::SSLeay::SSL object |
377 | =item tls => "accept" | "connect" | Net::SSLeay::SSL object |
377 | |
378 | |
378 | When this parameter is given, it enables TLS (SSL) mode, that means |
379 | When this parameter is given, it enables TLS (SSL) mode, that means |
379 | AnyEvent will start a TLS handshake as soon as the conenction has been |
380 | AnyEvent will start a TLS handshake as soon as the connection has been |
380 | established and will transparently encrypt/decrypt data afterwards. |
381 | established and will transparently encrypt/decrypt data afterwards. |
381 | |
382 | |
382 | All TLS protocol errors will be signalled as C<EPROTO>, with an |
383 | All TLS protocol errors will be signalled as C<EPROTO>, with an |
383 | appropriate error message. |
384 | appropriate error message. |
384 | |
385 | |
… | |
… | |
566 | $message ||= "$!"; |
567 | $message ||= "$!"; |
567 | |
568 | |
568 | if ($self->{on_error}) { |
569 | if ($self->{on_error}) { |
569 | $self->{on_error}($self, $fatal, $message); |
570 | $self->{on_error}($self, $fatal, $message); |
570 | $self->destroy if $fatal; |
571 | $self->destroy if $fatal; |
571 | } elsif ($self->{fh}) { |
572 | } elsif ($self->{fh} || $self->{connect}) { |
572 | $self->destroy; |
573 | $self->destroy; |
573 | Carp::croak "AnyEvent::Handle uncaught error: $message"; |
574 | Carp::croak "AnyEvent::Handle uncaught error: $message"; |
574 | } |
575 | } |
575 | } |
576 | } |
576 | |
577 | |
… | |
… | |
709 | |
710 | |
710 | Replace the current C<on_stoptls> callback (see the C<on_stoptls> constructor argument). |
711 | Replace the current C<on_stoptls> callback (see the C<on_stoptls> constructor argument). |
711 | |
712 | |
712 | =cut |
713 | =cut |
713 | |
714 | |
714 | sub on_starttls { |
715 | sub on_stoptls { |
715 | $_[0]{on_stoptls} = $_[1]; |
716 | $_[0]{on_stoptls} = $_[1]; |
716 | } |
717 | } |
717 | |
718 | |
718 | =item $handle->rbuf_max ($max_octets) |
719 | =item $handle->rbuf_max ($max_octets) |
719 | |
720 | |
… | |
… | |
902 | @_ = ($WH{$type} ||= _load_func "$type\::anyevent_write_type" |
903 | @_ = ($WH{$type} ||= _load_func "$type\::anyevent_write_type" |
903 | or Carp::croak "unsupported/unloadable type '$type' passed to AnyEvent::Handle::push_write") |
904 | or Carp::croak "unsupported/unloadable type '$type' passed to AnyEvent::Handle::push_write") |
904 | ->($self, @_); |
905 | ->($self, @_); |
905 | } |
906 | } |
906 | |
907 | |
|
|
908 | # we downgrade here to avoid hard-to-track-down bugs, |
|
|
909 | # and diagnose the problem earlier and better. |
|
|
910 | |
907 | if ($self->{tls}) { |
911 | if ($self->{tls}) { |
908 | $self->{_tls_wbuf} .= $_[0]; |
912 | utf8::downgrade $self->{_tls_wbuf} .= $_[0]; |
909 | &_dotls ($self) if $self->{fh}; |
913 | &_dotls ($self) if $self->{fh}; |
910 | } else { |
914 | } else { |
911 | $self->{wbuf} .= $_[0]; |
915 | utf8::downgrade $self->{wbuf} .= $_[0]; |
912 | $self->_drain_wbuf if $self->{fh}; |
916 | $self->_drain_wbuf if $self->{fh}; |
913 | } |
917 | } |
914 | } |
918 | } |
915 | |
919 | |
916 | =item $handle->push_write (type => @args) |
920 | =item $handle->push_write (type => @args) |