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.167 by root, Tue Jul 28 11:02:19 2009 UTC vs.
Revision 1.174 by root, Sat Aug 8 20:52:06 2009 UTC

11 11
12AnyEvent::Handle - non-blocking I/O on file handles via AnyEvent 12AnyEvent::Handle - non-blocking I/O on file handles via AnyEvent
13 13
14=cut 14=cut
15 15
16our $VERSION = 4.881; 16our $VERSION = 4.91;
17 17
18=head1 SYNOPSIS 18=head1 SYNOPSIS
19 19
20 use AnyEvent; 20 use AnyEvent;
21 use AnyEvent::Handle; 21 use AnyEvent::Handle;
602 602
603sub on_starttls { 603sub on_starttls {
604 $_[0]{on_stoptls} = $_[1]; 604 $_[0]{on_stoptls} = $_[1];
605} 605}
606 606
607=item $handle->rbuf_max ($max_octets)
608
609Configures the C<rbuf_max> setting (C<undef> disables it).
610
611=cut
612
613sub rbuf_max {
614 $_[0]{rbuf_max} = $_[1];
615}
616
607############################################################################# 617#############################################################################
608 618
609=item $handle->timeout ($seconds) 619=item $handle->timeout ($seconds)
610 620
611Configures (or disables) the inactivity timeout. 621Configures (or disables) the inactivity timeout.
614 624
615sub timeout { 625sub timeout {
616 my ($self, $timeout) = @_; 626 my ($self, $timeout) = @_;
617 627
618 $self->{timeout} = $timeout; 628 $self->{timeout} = $timeout;
629 delete $self->{_tw};
619 $self->_timeout; 630 $self->_timeout;
620} 631}
621 632
622# reset the timeout watcher, as neccessary 633# reset the timeout watcher, as neccessary
623# also check for time-outs 634# also check for time-outs
984 995
985 # avoid recursion 996 # avoid recursion
986 return if $self->{_skip_drain_rbuf}; 997 return if $self->{_skip_drain_rbuf};
987 local $self->{_skip_drain_rbuf} = 1; 998 local $self->{_skip_drain_rbuf} = 1;
988 999
989 if (
990 defined $self->{rbuf_max}
991 && $self->{rbuf_max} < length $self->{rbuf}
992 ) {
993 $self->_error (Errno::ENOSPC, 1), return;
994 }
995
996 while () { 1000 while () {
997 # we need to use a separate tls read buffer, as we must not receive data while 1001 # we need to use a separate tls read buffer, as we must not receive data while
998 # we are draining the buffer, and this can only happen with TLS. 1002 # we are draining the buffer, and this can only happen with TLS.
999 $self->{rbuf} .= delete $self->{_tls_rbuf} 1003 $self->{rbuf} .= delete $self->{_tls_rbuf}
1000 if exists $self->{_tls_rbuf}; 1004 if exists $self->{_tls_rbuf};
1039 $self->{on_eof} 1043 $self->{on_eof}
1040 ? $self->{on_eof}($self) 1044 ? $self->{on_eof}($self)
1041 : $self->_error (0, 1, "Unexpected end-of-file"); 1045 : $self->_error (0, 1, "Unexpected end-of-file");
1042 1046
1043 return; 1047 return;
1048 }
1049
1050 if (
1051 defined $self->{rbuf_max}
1052 && $self->{rbuf_max} < length $self->{rbuf}
1053 ) {
1054 $self->_error (Errno::ENOSPC, 1), return;
1044 } 1055 }
1045 1056
1046 # may need to restart read watcher 1057 # may need to restart read watcher
1047 unless ($self->{_rw}) { 1058 unless ($self->{_rw}) {
1048 $self->start_read 1059 $self->start_read
1722 Net::SSLeay::CTX_set_mode ($tls, 1|2); 1733 Net::SSLeay::CTX_set_mode ($tls, 1|2);
1723 1734
1724 $self->{_rbio} = Net::SSLeay::BIO_new (Net::SSLeay::BIO_s_mem ()); 1735 $self->{_rbio} = Net::SSLeay::BIO_new (Net::SSLeay::BIO_s_mem ());
1725 $self->{_wbio} = Net::SSLeay::BIO_new (Net::SSLeay::BIO_s_mem ()); 1736 $self->{_wbio} = Net::SSLeay::BIO_new (Net::SSLeay::BIO_s_mem ());
1726 1737
1738 Net::SSLeay::BIO_write ($self->{_rbio}, delete $self->{rbuf});
1739
1727 Net::SSLeay::set_bio ($tls, $self->{_rbio}, $self->{_wbio}); 1740 Net::SSLeay::set_bio ($tls, $self->{_rbio}, $self->{_wbio});
1728 1741
1729 $self->{_on_starttls} = sub { $_[0]{on_starttls}(@_) } 1742 $self->{_on_starttls} = sub { $_[0]{on_starttls}(@_) }
1730 if $self->{on_starttls}; 1743 if $self->{on_starttls};
1731 1744
1760 my ($self) = @_; 1773 my ($self) = @_;
1761 1774
1762 return unless $self->{tls}; 1775 return unless $self->{tls};
1763 1776
1764 $self->{tls_ctx}->_put_session (delete $self->{tls}) 1777 $self->{tls_ctx}->_put_session (delete $self->{tls})
1765 if ref $self->{tls}; 1778 if $self->{tls} > 0;
1766 1779
1767 delete @$self{qw(_rbio _wbio _tls_wbuf _on_starttls)}; 1780 delete @$self{qw(_rbio _wbio _tls_wbuf _on_starttls)};
1768} 1781}
1769 1782
1770sub DESTROY { 1783sub DESTROY {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines