You can also provide your own TLS connection object, but you have
to make sure that you call either C<Net::SSLeay::set_connect_state>
or C<Net::SSLeay::set_accept_state> on it before you pass it to
AnyEvent::Handle.
See the C<starttls> method if you need to start TLs negotiation later.
=item tls_ctx => $ssl_ctx
Use the given Net::SSLeay::CTX object to create the new TLS connection
(unless a connection object was specified directly). If this parameter is
missing, then AnyEvent::Handle will use C<AnyEvent::Handle::TLS_CTX>.
=item json => JSON or JSON::XS object
This is the json coder object used by the C<json> read and write types.
If you don't supply it, then AnyEvent::Handle will create and use a
suitable one, which will write and expect UTF-8 encoded JSON texts.
Note that you are responsible to depend on the JSON module if you want to
use this functionality, as AnyEvent does not have a dependency itself.
=item filter_r => $cb
=item filter_w => $cb
These exist, but are undocumented at this time.
=back
=cut
sub new {
my $class = shift;
my $self = bless { @_ }, $class;
$self->{fh} or Carp::croak "mandatory argument fh is missing";
AnyEvent::Util::fh_nonblocking $self->{fh}, 1;
if ($self->{tls}) {
require Net::SSLeay;
$self->starttls (delete $self->{tls}, delete $self->{tls_ctx});
}
$self->{_activity} = AnyEvent->now;
$self->_timeout;
$self->on_drain (delete $self->{on_drain}) if $self->{on_drain};
$self->start_read
if $self->{on_read};
$self
}
sub _shutdown {
my ($self) = @_;
delete $self->{_tw};
delete $self->{_rw};
delete $self->{_ww};
delete $self->{fh};
$self->stoptls;
}
sub _error {
my ($self, $errno, $fatal) = @_;
$self->_shutdown
if $fatal;
$! = $errno;
if ($self->{on_error}) {
$self->{on_error}($self, $fatal);
} else {
Carp::croak "AnyEvent::Handle uncaught error: $!";
}
}
=item $fh = $handle->fh
This method returns the file handle of the L<AnyEvent::Handle> object.
=cut
sub fh { $_[0]{fh} }
=item $handle->on_error ($cb)
Replace the current C<on_error> callback (see the C<on_error> constructor argument).
=cut
sub on_error {
$_[0]{on_error} = $_[1];
=3= |