1 | package AnyEvent::Handle; |
1 | package AnyEvent::Handle; |
2 | |
2 | |
3 | no warnings; |
|
|
4 | use strict qw(subs vars); |
|
|
5 | |
|
|
6 | use AnyEvent (); |
|
|
7 | use AnyEvent::Util qw(WSAEWOULDBLOCK); |
|
|
8 | use Scalar::Util (); |
3 | use Scalar::Util (); |
9 | use Carp (); |
4 | use Carp (); |
10 | use Fcntl (); |
|
|
11 | use Errno qw(EAGAIN EINTR); |
5 | use Errno qw(EAGAIN EINTR); |
12 | |
6 | |
|
|
7 | use AnyEvent (); BEGIN { AnyEvent::common_sense } |
|
|
8 | use AnyEvent::Util qw(WSAEWOULDBLOCK); |
|
|
9 | |
13 | =head1 NAME |
10 | =head1 NAME |
14 | |
11 | |
15 | AnyEvent::Handle - non-blocking I/O on file handles via AnyEvent |
12 | AnyEvent::Handle - non-blocking I/O on file handles via AnyEvent |
16 | |
13 | |
17 | =cut |
14 | =cut |
18 | |
15 | |
19 | our $VERSION = 4.83; |
16 | our $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; |
… | |
… | |
72 | |
69 | |
73 | =over 4 |
70 | =over 4 |
74 | |
71 | |
75 | =item fh => $filehandle [MANDATORY] |
72 | =item fh => $filehandle [MANDATORY] |
76 | |
73 | |
|
|
74 | #=item fh => $filehandle [C<fh> or C<connect> MANDATORY] |
|
|
75 | |
77 | The filehandle this L<AnyEvent::Handle> object will operate on. |
76 | The filehandle this L<AnyEvent::Handle> object will operate on. |
78 | |
|
|
79 | NOTE: The filehandle will be set to non-blocking mode (using |
77 | NOTE: The filehandle will be set to non-blocking mode (using |
80 | C<AnyEvent::Util::fh_nonblocking>) by the constructor and needs to stay in |
78 | C<AnyEvent::Util::fh_nonblocking>) by the constructor and needs to stay in |
81 | that mode. |
79 | that mode. |
|
|
80 | |
|
|
81 | #=item connect => [$host, $service] |
|
|
82 | # |
|
|
83 | # You have to specify either this parameter, or C<connect>, below. |
|
|
84 | #Try to connect to the specified host and service (port), using |
|
|
85 | #C<AnyEvent::Socket::tcp_connect>. |
|
|
86 | # |
|
|
87 | #When this |
82 | |
88 | |
83 | =item on_eof => $cb->($handle) |
89 | =item on_eof => $cb->($handle) |
84 | |
90 | |
85 | Set the callback to be called when an end-of-file condition is detected, |
91 | Set the callback to be called when an end-of-file condition is detected, |
86 | i.e. in the case of a socket, when the other side has closed the |
92 | i.e. in the case of a socket, when the other side has closed the |
… | |
… | |
1522 | |
1528 | |
1523 | Instead of starting TLS negotiation immediately when the AnyEvent::Handle |
1529 | Instead of starting TLS negotiation immediately when the AnyEvent::Handle |
1524 | object is created, you can also do that at a later time by calling |
1530 | object is created, you can also do that at a later time by calling |
1525 | C<starttls>. |
1531 | C<starttls>. |
1526 | |
1532 | |
|
|
1533 | Starting TLS is currently an asynchronous operation - when you push some |
|
|
1534 | write data and then call C<< ->starttls >> then TLS negotiation will start |
|
|
1535 | immediately, after which the queued write data is then sent. |
|
|
1536 | |
1527 | The first argument is the same as the C<tls> constructor argument (either |
1537 | The first argument is the same as the C<tls> constructor argument (either |
1528 | C<"connect">, C<"accept"> or an existing Net::SSLeay object). |
1538 | C<"connect">, C<"accept"> or an existing Net::SSLeay object). |
1529 | |
1539 | |
1530 | The second argument is the optional C<AnyEvent::TLS> object that is used |
1540 | The second argument is the optional C<AnyEvent::TLS> object that is used |
1531 | when AnyEvent::Handle has to create its own TLS connection object, or |
1541 | when AnyEvent::Handle has to create its own TLS connection object, or |
… | |
… | |
1555 | $ERROR_SYSCALL = Net::SSLeay::ERROR_SYSCALL (); |
1565 | $ERROR_SYSCALL = Net::SSLeay::ERROR_SYSCALL (); |
1556 | $ERROR_WANT_READ = Net::SSLeay::ERROR_WANT_READ (); |
1566 | $ERROR_WANT_READ = Net::SSLeay::ERROR_WANT_READ (); |
1557 | |
1567 | |
1558 | $ctx ||= $self->{tls_ctx}; |
1568 | $ctx ||= $self->{tls_ctx}; |
1559 | |
1569 | |
|
|
1570 | local $Carp::CarpLevel = 1; # skip ourselves when creating a new context or session |
|
|
1571 | |
1560 | if ("HASH" eq ref $ctx) { |
1572 | if ("HASH" eq ref $ctx) { |
1561 | require AnyEvent::TLS; |
1573 | require AnyEvent::TLS; |
1562 | |
|
|
1563 | local $Carp::CarpLevel = 1; # skip ourselves when creating a new context |
|
|
1564 | |
1574 | |
1565 | if ($ctx->{cache}) { |
1575 | if ($ctx->{cache}) { |
1566 | my $key = $ctx+0; |
1576 | my $key = $ctx+0; |
1567 | $ctx = $TLS_CACHE{$key} ||= new AnyEvent::TLS %$ctx; |
1577 | $ctx = $TLS_CACHE{$key} ||= new AnyEvent::TLS %$ctx; |
1568 | } else { |
1578 | } else { |
… | |
… | |
1640 | |
1650 | |
1641 | &_freetls; |
1651 | &_freetls; |
1642 | |
1652 | |
1643 | my $linger = exists $self->{linger} ? $self->{linger} : 3600; |
1653 | my $linger = exists $self->{linger} ? $self->{linger} : 3600; |
1644 | |
1654 | |
1645 | if ($linger && length $self->{wbuf}) { |
1655 | if ($linger && length $self->{wbuf} && $self->{fh}) { |
1646 | my $fh = delete $self->{fh}; |
1656 | my $fh = delete $self->{fh}; |
1647 | my $wbuf = delete $self->{wbuf}; |
1657 | my $wbuf = delete $self->{wbuf}; |
1648 | |
1658 | |
1649 | my @linger; |
1659 | my @linger; |
1650 | |
1660 | |