ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent/lib/AnyEvent/Handle.pm
(Generate patch)

Comparing AnyEvent/lib/AnyEvent/Handle.pm (file contents):
Revision 1.185 by root, Thu Sep 3 19:48:27 2009 UTC vs.
Revision 1.190 by root, Thu Nov 26 10:30:24 2009 UTC

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
130The actual numeric host and port (the socket peername) are passed as 130The actual numeric host and port (the socket peername) are passed as
131parameters, together with a retry callback. 131parameters, together with a retry callback.
132 132
133When, for some reason, the handle is not acceptable, then calling 133When, for some reason, the handle is not acceptable, then calling
134C<$retry> will continue with the next conenction target (in case of 134C<$retry> will continue with the next connection target (in case of
135multi-homed hosts or SRV records there can be multiple connection 135multi-homed hosts or SRV records there can be multiple connection
136endpoints). When it is called then the read and write queues, eof status, 136endpoints). At the time it is called the read and write queues, eof
137tls status and similar properties of the handle are being reset. 137status, tls status and similar properties of the handle will have been
138reset.
138 139
139In most cases, ignoring the C<$retry> parameter is the way to go. 140In 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
143This callback is called when the conenction could not be 144This callback is called when the connection could not be
144established. C<$!> will contain the relevant error code, and C<$message> a 145established. C<$!> will contain the relevant error code, and C<$message> a
145message describing it (usually the same as C<"$!">). 146message describing it (usually the same as C<"$!">).
146 147
147If this callback isn't specified, then C<on_error> will be called with a 148If this callback isn't specified, then C<on_error> will be called with a
148fatal error instead. 149fatal error instead.
304 305
305=item keepalive => <boolean> 306=item keepalive => <boolean>
306 307
307Enables (default disable) the SO_KEEPALIVE option on the stream socket: 308Enables (default disable) the SO_KEEPALIVE option on the stream socket:
308normally, TCP connections have no time-out once established, so TCP 309normally, TCP connections have no time-out once established, so TCP
309conenctions, once established, can stay alive forever even when the other 310connections, once established, can stay alive forever even when the other
310side has long gone. TCP keepalives are a cheap way to take down long-lived 311side has long gone. TCP keepalives are a cheap way to take down long-lived
311TCP connections whent he other side becomes unreachable. While the default 312TCP connections whent he other side becomes unreachable. While the default
312is OS-dependent, TCP keepalives usually kick in after around two hours, 313is OS-dependent, TCP keepalives usually kick in after around two hours,
313and, if the other side doesn't reply, take down the TCP connection some 10 314and, if the other side doesn't reply, take down the TCP connection some 10
314to 15 minutes later. 315to 15 minutes later.
374C<undef>. 375C<undef>.
375 376
376=item tls => "accept" | "connect" | Net::SSLeay::SSL object 377=item tls => "accept" | "connect" | Net::SSLeay::SSL object
377 378
378When this parameter is given, it enables TLS (SSL) mode, that means 379When this parameter is given, it enables TLS (SSL) mode, that means
379AnyEvent will start a TLS handshake as soon as the conenction has been 380AnyEvent will start a TLS handshake as soon as the connection has been
380established and will transparently encrypt/decrypt data afterwards. 381established and will transparently encrypt/decrypt data afterwards.
381 382
382All TLS protocol errors will be signalled as C<EPROTO>, with an 383All TLS protocol errors will be signalled as C<EPROTO>, with an
383appropriate error message. 384appropriate 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
710Replace the current C<on_stoptls> callback (see the C<on_stoptls> constructor argument). 711Replace the current C<on_stoptls> callback (see the C<on_stoptls> constructor argument).
711 712
712=cut 713=cut
713 714
714sub on_starttls { 715sub 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)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines