… | |
… | |
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.234; |
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; |
… | |
… | |
1319 | 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) { |
1320 | substr $self->{_tls_wbuf}, 0, $len, ""; |
1320 | substr $self->{_tls_wbuf}, 0, $len, ""; |
1321 | } |
1321 | } |
1322 | } |
1322 | } |
1323 | |
1323 | |
1324 | if (length ($buf = Net::SSLeay::BIO_read ($self->{_wbio}))) { |
|
|
1325 | $self->{wbuf} .= $buf; |
|
|
1326 | $self->_drain_wbuf; |
|
|
1327 | } |
|
|
1328 | |
|
|
1329 | while (defined ($buf = Net::SSLeay::read ($self->{tls}))) { |
1324 | while (defined ($buf = Net::SSLeay::read ($self->{tls}))) { |
1330 | if (length $buf) { |
1325 | unless (length $buf) { |
1331 | $self->{rbuf} .= $buf; |
|
|
1332 | $self->_drain_rbuf unless $self->{_in_drain}; |
|
|
1333 | } else { |
|
|
1334 | # 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}; |
1335 | $self->{_eof} = 1; |
1328 | $self->{_eof} = 1; |
1336 | $self->_shutdown; |
|
|
1337 | return; |
|
|
1338 | } |
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 |
1339 | } |
1335 | } |
1340 | |
1336 | |
1341 | my $err = Net::SSLeay::get_error ($self->{tls}, -1); |
1337 | my $err = Net::SSLeay::get_error ($self->{tls}, -1); |
1342 | |
1338 | |
1343 | if ($err!= Net::SSLeay::ERROR_WANT_READ ()) { |
1339 | if ($err!= Net::SSLeay::ERROR_WANT_READ ()) { |
… | |
… | |
1346 | } elsif ($err == Net::SSLeay::ERROR_SSL ()) { |
1342 | } elsif ($err == Net::SSLeay::ERROR_SSL ()) { |
1347 | return $self->_error (&Errno::EIO, 1); |
1343 | return $self->_error (&Errno::EIO, 1); |
1348 | } |
1344 | } |
1349 | |
1345 | |
1350 | # 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; |
1351 | } |
1352 | } |
1352 | } |
1353 | } |
1353 | |
1354 | |
1354 | =item $handle->starttls ($tls[, $tls_ctx]) |
1355 | =item $handle->starttls ($tls[, $tls_ctx]) |
1355 | |
1356 | |
… | |
… | |
1410 | }; |
1411 | }; |
1411 | $self->{filter_r} = sub { |
1412 | $self->{filter_r} = sub { |
1412 | Net::SSLeay::BIO_write ($_[0]{_rbio}, ${$_[1]}); |
1413 | Net::SSLeay::BIO_write ($_[0]{_rbio}, ${$_[1]}); |
1413 | &_dotls; |
1414 | &_dotls; |
1414 | }; |
1415 | }; |
|
|
1416 | |
|
|
1417 | &_dotls; # need to trigger the initial negotiation exchange |
1415 | } |
1418 | } |
1416 | |
1419 | |
1417 | =item $handle->stoptls |
1420 | =item $handle->stoptls |
1418 | |
1421 | |
1419 | 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 |