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.163 by root, Mon Jul 27 22:08:52 2009 UTC vs.
Revision 1.172 by root, Wed Aug 5 20:50:27 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.87; 16our $VERSION = 4.901;
17 17
18=head1 SYNOPSIS 18=head1 SYNOPSIS
19 19
20 use AnyEvent; 20 use AnyEvent;
21 use AnyEvent::Handle; 21 use AnyEvent::Handle;
600 600
601=cut 601=cut
602 602
603sub on_starttls { 603sub on_starttls {
604 $_[0]{on_stoptls} = $_[1]; 604 $_[0]{on_stoptls} = $_[1];
605}
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];
605} 615}
606 616
607############################################################################# 617#############################################################################
608 618
609=item $handle->timeout ($seconds) 619=item $handle->timeout ($seconds)
981 991
982sub _drain_rbuf { 992sub _drain_rbuf {
983 my ($self) = @_; 993 my ($self) = @_;
984 994
985 # avoid recursion 995 # avoid recursion
986 return if exists $self->{_skip_drain_rbuf}; 996 return if $self->{_skip_drain_rbuf};
987 local $self->{_skip_drain_rbuf} = 1; 997 local $self->{_skip_drain_rbuf} = 1;
988
989 if (
990 defined $self->{rbuf_max}
991 && $self->{rbuf_max} < length $self->{rbuf}
992 ) {
993 $self->_error (Errno::ENOSPC, 1), return;
994 }
995 998
996 while () { 999 while () {
997 # we need to use a separate tls read buffer, as we must not receive data while 1000 # 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. 1001 # we are draining the buffer, and this can only happen with TLS.
999 $self->{rbuf} .= delete $self->{_tls_rbuf} 1002 $self->{rbuf} .= delete $self->{_tls_rbuf}
1039 $self->{on_eof} 1042 $self->{on_eof}
1040 ? $self->{on_eof}($self) 1043 ? $self->{on_eof}($self)
1041 : $self->_error (0, 1, "Unexpected end-of-file"); 1044 : $self->_error (0, 1, "Unexpected end-of-file");
1042 1045
1043 return; 1046 return;
1047 }
1048
1049 if (
1050 defined $self->{rbuf_max}
1051 && $self->{rbuf_max} < length $self->{rbuf}
1052 ) {
1053 $self->_error (Errno::ENOSPC, 1), return;
1044 } 1054 }
1045 1055
1046 # may need to restart read watcher 1056 # may need to restart read watcher
1047 unless ($self->{_rw}) { 1057 unless ($self->{_rw}) {
1048 $self->start_read 1058 $self->start_read
1722 Net::SSLeay::CTX_set_mode ($tls, 1|2); 1732 Net::SSLeay::CTX_set_mode ($tls, 1|2);
1723 1733
1724 $self->{_rbio} = Net::SSLeay::BIO_new (Net::SSLeay::BIO_s_mem ()); 1734 $self->{_rbio} = Net::SSLeay::BIO_new (Net::SSLeay::BIO_s_mem ());
1725 $self->{_wbio} = Net::SSLeay::BIO_new (Net::SSLeay::BIO_s_mem ()); 1735 $self->{_wbio} = Net::SSLeay::BIO_new (Net::SSLeay::BIO_s_mem ());
1726 1736
1737 Net::SSLeay::BIO_write ($self->{_rbio}, delete $self->{rbuf});
1738
1727 Net::SSLeay::set_bio ($tls, $self->{_rbio}, $self->{_wbio}); 1739 Net::SSLeay::set_bio ($tls, $self->{_rbio}, $self->{_wbio});
1728 1740
1729 $self->{_on_starttls} = sub { $_[0]{on_starttls}(@_) } 1741 $self->{_on_starttls} = sub { $_[0]{on_starttls}(@_) }
1730 if $self->{on_starttls}; 1742 if $self->{on_starttls};
1731 1743
1760 my ($self) = @_; 1772 my ($self) = @_;
1761 1773
1762 return unless $self->{tls}; 1774 return unless $self->{tls};
1763 1775
1764 $self->{tls_ctx}->_put_session (delete $self->{tls}) 1776 $self->{tls_ctx}->_put_session (delete $self->{tls})
1765 if ref $self->{tls}; 1777 if $self->{tls} > 0;
1766 1778
1767 delete @$self{qw(_rbio _wbio _tls_wbuf _on_starttls)}; 1779 delete @$self{qw(_rbio _wbio _tls_wbuf _on_starttls)};
1768} 1780}
1769 1781
1770sub DESTROY { 1782sub DESTROY {
1797 1809
1798=item $handle->destroy 1810=item $handle->destroy
1799 1811
1800Shuts down the handle object as much as possible - this call ensures that 1812Shuts down the handle object as much as possible - this call ensures that
1801no further callbacks will be invoked and as many resources as possible 1813no further callbacks will be invoked and as many resources as possible
1802will be freed. You must not call any methods on the object afterwards. 1814will be freed. Any method you will call on the handle object after
1815destroying it in this way will be silently ignored (and it will return the
1816empty list).
1803 1817
1804Normally, you can just "forget" any references to an AnyEvent::Handle 1818Normally, you can just "forget" any references to an AnyEvent::Handle
1805object and it will simply shut down. This works in fatal error and EOF 1819object and it will simply shut down. This works in fatal error and EOF
1806callbacks, as well as code outside. It does I<NOT> work in a read or write 1820callbacks, as well as code outside. It does I<NOT> work in a read or write
1807callback, so when you want to destroy the AnyEvent::Handle object from 1821callback, so when you want to destroy the AnyEvent::Handle object from
1821sub destroy { 1835sub destroy {
1822 my ($self) = @_; 1836 my ($self) = @_;
1823 1837
1824 $self->DESTROY; 1838 $self->DESTROY;
1825 %$self = (); 1839 %$self = ();
1840 bless $self, "AnyEvent::Handle::destroyed";
1841}
1842
1843sub AnyEvent::Handle::destroyed::AUTOLOAD {
1844 #nop
1826} 1845}
1827 1846
1828=item AnyEvent::Handle::TLS_CTX 1847=item AnyEvent::Handle::TLS_CTX
1829 1848
1830This function creates and returns the AnyEvent::TLS object used by default 1849This function creates and returns the AnyEvent::TLS object used by default

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines