… | |
… | |
14 | |
14 | |
15 | AnyEvent::Handle - non-blocking I/O on file handles via AnyEvent |
15 | AnyEvent::Handle - non-blocking I/O on file handles via AnyEvent |
16 | |
16 | |
17 | =cut |
17 | =cut |
18 | |
18 | |
19 | our $VERSION = 4.233; |
19 | our $VERSION = 4.3; |
20 | |
20 | |
21 | =head1 SYNOPSIS |
21 | =head1 SYNOPSIS |
22 | |
22 | |
23 | use AnyEvent; |
23 | use AnyEvent; |
24 | use AnyEvent::Handle; |
24 | use AnyEvent::Handle; |
… | |
… | |
58 | means characters. As sysread and syswrite are used for all I/O, their |
58 | means characters. As sysread and syswrite are used for all I/O, their |
59 | treatment of characters applies to this module as well. |
59 | treatment of characters applies to this module as well. |
60 | |
60 | |
61 | All callbacks will be invoked with the handle object as their first |
61 | All callbacks will be invoked with the handle object as their first |
62 | argument. |
62 | argument. |
|
|
63 | |
|
|
64 | =head2 SIGPIPE is not handled by this module |
|
|
65 | |
|
|
66 | SIGPIPE is not handled by this module, so one of the practical |
|
|
67 | requirements of using it is to ignore SIGPIPE (C<$SIG{PIPE} = |
|
|
68 | 'IGNORE'>). At least, this is highly recommend in a networked program: If |
|
|
69 | you use AnyEvent::Handle in a filter program (like sort), exiting on |
|
|
70 | SIGPIPE is probably the right thing to do. |
63 | |
71 | |
64 | =head1 METHODS |
72 | =head1 METHODS |
65 | |
73 | |
66 | =over 4 |
74 | =over 4 |
67 | |
75 | |
… | |
… | |
1311 | while ((my $len = Net::SSLeay::write ($self->{tls}, $self->{_tls_wbuf})) > 0) { |
1319 | while ((my $len = Net::SSLeay::write ($self->{tls}, $self->{_tls_wbuf})) > 0) { |
1312 | substr $self->{_tls_wbuf}, 0, $len, ""; |
1320 | substr $self->{_tls_wbuf}, 0, $len, ""; |
1313 | } |
1321 | } |
1314 | } |
1322 | } |
1315 | |
1323 | |
1316 | if (length ($buf = Net::SSLeay::BIO_read ($self->{_wbio}))) { |
|
|
1317 | $self->{wbuf} .= $buf; |
|
|
1318 | $self->_drain_wbuf; |
|
|
1319 | } |
|
|
1320 | |
|
|
1321 | while (defined ($buf = Net::SSLeay::read ($self->{tls}))) { |
1324 | while (defined ($buf = Net::SSLeay::read ($self->{tls}))) { |
1322 | if (length $buf) { |
1325 | unless (length $buf) { |
1323 | $self->{rbuf} .= $buf; |
|
|
1324 | $self->_drain_rbuf unless $self->{_in_drain}; |
|
|
1325 | } else { |
|
|
1326 | # let's treat SSL-eof as we treat normal EOF |
1326 | # let's treat SSL-eof as we treat normal EOF |
|
|
1327 | delete $self->{_rw}; |
1327 | $self->{_eof} = 1; |
1328 | $self->{_eof} = 1; |
1328 | $self->_shutdown; |
|
|
1329 | return; |
|
|
1330 | } |
1329 | } |
|
|
1330 | |
|
|
1331 | $self->{rbuf} .= $buf; |
|
|
1332 | $self->_drain_rbuf unless $self->{_in_drain}; |
|
|
1333 | |
|
|
1334 | $self->{tls} or return; # tls could have gone away |
1331 | } |
1335 | } |
1332 | |
1336 | |
1333 | my $err = Net::SSLeay::get_error ($self->{tls}, -1); |
1337 | my $err = Net::SSLeay::get_error ($self->{tls}, -1); |
1334 | |
1338 | |
1335 | if ($err!= Net::SSLeay::ERROR_WANT_READ ()) { |
1339 | if ($err!= Net::SSLeay::ERROR_WANT_READ ()) { |
… | |
… | |
1338 | } elsif ($err == Net::SSLeay::ERROR_SSL ()) { |
1342 | } elsif ($err == Net::SSLeay::ERROR_SSL ()) { |
1339 | return $self->_error (&Errno::EIO, 1); |
1343 | return $self->_error (&Errno::EIO, 1); |
1340 | } |
1344 | } |
1341 | |
1345 | |
1342 | # all others are fine for our purposes |
1346 | # all others are fine for our purposes |
|
|
1347 | } |
|
|
1348 | |
|
|
1349 | if (length ($buf = Net::SSLeay::BIO_read ($self->{_wbio}))) { |
|
|
1350 | $self->{wbuf} .= $buf; |
|
|
1351 | $self->_drain_wbuf; |
1343 | } |
1352 | } |
1344 | } |
1353 | } |
1345 | |
1354 | |
1346 | =item $handle->starttls ($tls[, $tls_ctx]) |
1355 | =item $handle->starttls ($tls[, $tls_ctx]) |
1347 | |
1356 | |
… | |
… | |
1402 | }; |
1411 | }; |
1403 | $self->{filter_r} = sub { |
1412 | $self->{filter_r} = sub { |
1404 | Net::SSLeay::BIO_write ($_[0]{_rbio}, ${$_[1]}); |
1413 | Net::SSLeay::BIO_write ($_[0]{_rbio}, ${$_[1]}); |
1405 | &_dotls; |
1414 | &_dotls; |
1406 | }; |
1415 | }; |
|
|
1416 | |
|
|
1417 | &_dotls; # need to trigger the initial negotiation exchange |
1407 | } |
1418 | } |
1408 | |
1419 | |
1409 | =item $handle->stoptls |
1420 | =item $handle->stoptls |
1410 | |
1421 | |
1411 | Destroys the SSL connection, if any. Partial read or write data will be |
1422 | Destroys the SSL connection, if any. Partial read or write data will be |