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.150 by root, Thu Jul 16 04:16:25 2009 UTC vs.
Revision 1.157 by root, Wed Jul 22 23:07:13 2009 UTC

1package AnyEvent::Handle; 1package AnyEvent::Handle;
2 2
3no warnings;
4use strict qw(subs vars);
5
6use AnyEvent ();
7use AnyEvent::Util qw(WSAEWOULDBLOCK);
8use Scalar::Util (); 3use Scalar::Util ();
9use Carp (); 4use Carp ();
10use Fcntl ();
11use Errno qw(EAGAIN EINTR); 5use Errno qw(EAGAIN EINTR);
12 6
7use AnyEvent (); BEGIN { AnyEvent::common_sense }
8use AnyEvent::Util qw(WSAEWOULDBLOCK);
9
13=head1 NAME 10=head1 NAME
14 11
15AnyEvent::Handle - non-blocking I/O on file handles via AnyEvent 12AnyEvent::Handle - non-blocking I/O on file handles via AnyEvent
16 13
17=cut 14=cut
18 15
19our $VERSION = 4.82; 16our $VERSION = 4.86;
20 17
21=head1 SYNOPSIS 18=head1 SYNOPSIS
22 19
23 use AnyEvent; 20 use AnyEvent;
24 use AnyEvent::Handle; 21 use AnyEvent::Handle;
26 my $cv = AnyEvent->condvar; 23 my $cv = AnyEvent->condvar;
27 24
28 my $hdl; $hdl = new AnyEvent::Handle 25 my $hdl; $hdl = new AnyEvent::Handle
29 fh => \*STDIN, 26 fh => \*STDIN,
30 on_error => sub { 27 on_error => sub {
28 my ($hdl, $fatal, $msg) = @_;
31 warn "got error $_[2]\n"; 29 warn "got error $msg\n";
30 $hdl->destroy;
32 $cv->send; 31 $cv->send;
33 ); 32 );
34 33
35 # send some request line 34 # send some request line
36 $hdl->push_write ("getinfo\015\012"); 35 $hdl->push_write ("getinfo\015\012");
388 $! = $errno; 387 $! = $errno;
389 $message ||= "$!"; 388 $message ||= "$!";
390 389
391 if ($self->{on_error}) { 390 if ($self->{on_error}) {
392 $self->{on_error}($self, $fatal, $message); 391 $self->{on_error}($self, $fatal, $message);
393 $self->destroy; 392 $self->destroy if $fatal;
394 } elsif ($self->{fh}) { 393 } elsif ($self->{fh}) {
395 $self->destroy; 394 $self->destroy;
396 Carp::croak "AnyEvent::Handle uncaught error: $message"; 395 Carp::croak "AnyEvent::Handle uncaught error: $message";
397 } 396 }
398} 397}
1520 1519
1521Instead of starting TLS negotiation immediately when the AnyEvent::Handle 1520Instead of starting TLS negotiation immediately when the AnyEvent::Handle
1522object is created, you can also do that at a later time by calling 1521object is created, you can also do that at a later time by calling
1523C<starttls>. 1522C<starttls>.
1524 1523
1524Starting TLS is currently an asynchronous operation - when you push some
1525write data and then call C<< ->starttls >> then TLS negotiation will start
1526immediately, after which the queued write data is then sent.
1527
1525The first argument is the same as the C<tls> constructor argument (either 1528The first argument is the same as the C<tls> constructor argument (either
1526C<"connect">, C<"accept"> or an existing Net::SSLeay object). 1529C<"connect">, C<"accept"> or an existing Net::SSLeay object).
1527 1530
1528The second argument is the optional C<AnyEvent::TLS> object that is used 1531The second argument is the optional C<AnyEvent::TLS> object that is used
1529when AnyEvent::Handle has to create its own TLS connection object, or 1532when AnyEvent::Handle has to create its own TLS connection object, or
1553 $ERROR_SYSCALL = Net::SSLeay::ERROR_SYSCALL (); 1556 $ERROR_SYSCALL = Net::SSLeay::ERROR_SYSCALL ();
1554 $ERROR_WANT_READ = Net::SSLeay::ERROR_WANT_READ (); 1557 $ERROR_WANT_READ = Net::SSLeay::ERROR_WANT_READ ();
1555 1558
1556 $ctx ||= $self->{tls_ctx}; 1559 $ctx ||= $self->{tls_ctx};
1557 1560
1561 local $Carp::CarpLevel = 1; # skip ourselves when creating a new context or session
1562
1558 if ("HASH" eq ref $ctx) { 1563 if ("HASH" eq ref $ctx) {
1559 require AnyEvent::TLS; 1564 require AnyEvent::TLS;
1560
1561 local $Carp::CarpLevel = 1; # skip ourselves when creating a new context
1562 1565
1563 if ($ctx->{cache}) { 1566 if ($ctx->{cache}) {
1564 my $key = $ctx+0; 1567 my $key = $ctx+0;
1565 $ctx = $TLS_CACHE{$key} ||= new AnyEvent::TLS %$ctx; 1568 $ctx = $TLS_CACHE{$key} ||= new AnyEvent::TLS %$ctx;
1566 } else { 1569 } else {
1638 1641
1639 &_freetls; 1642 &_freetls;
1640 1643
1641 my $linger = exists $self->{linger} ? $self->{linger} : 3600; 1644 my $linger = exists $self->{linger} ? $self->{linger} : 3600;
1642 1645
1643 if ($linger && length $self->{wbuf}) { 1646 if ($linger && length $self->{wbuf} && $self->{fh}) {
1644 my $fh = delete $self->{fh}; 1647 my $fh = delete $self->{fh};
1645 my $wbuf = delete $self->{wbuf}; 1648 my $wbuf = delete $self->{wbuf};
1646 1649
1647 my @linger; 1650 my @linger;
1648 1651

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines