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.161 by root, Sat Jul 25 06:16:45 2009 UTC vs.
Revision 1.170 by root, Sat Aug 1 09:14:54 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.86; 16our $VERSION = 4.9;
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} if exists $self->{_tls_rbuf}; 1002 $self->{rbuf} .= delete $self->{_tls_rbuf}
1003 if exists $self->{_tls_rbuf};
1000 1004
1001 my $len = length $self->{rbuf}; 1005 my $len = length $self->{rbuf};
1002 1006
1003 if (my $cb = shift @{ $self->{_queue} }) { 1007 if (my $cb = shift @{ $self->{_queue} }) {
1004 unless ($cb->($self)) { 1008 unless ($cb->($self)) {
1005 if ($self->{_eof}) { 1009 # no progress can be made
1006 # no progress can be made (not enough data and no data forthcoming) 1010 # (not enough data and no data forthcoming)
1007 $self->_error (Errno::EPIPE, 1), return; 1011 $self->_error (Errno::EPIPE, 1), return
1008 } 1012 if $self->{_eof};
1009 1013
1010 unshift @{ $self->{_queue} }, $cb; 1014 unshift @{ $self->{_queue} }, $cb;
1011 last; 1015 last;
1012 } 1016 }
1013 } elsif ($self->{on_read}) { 1017 } elsif ($self->{on_read}) {
1033 last; 1037 last;
1034 } 1038 }
1035 } 1039 }
1036 1040
1037 if ($self->{_eof}) { 1041 if ($self->{_eof}) {
1038 if ($self->{on_eof}) { 1042 $self->{on_eof}
1039 $self->{on_eof}($self) 1043 ? $self->{on_eof}($self)
1040 } else {
1041 $self->_error (0, 1, "Unexpected end-of-file"); 1044 : $self->_error (0, 1, "Unexpected end-of-file");
1042 } 1045
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;
1043 } 1054 }
1044 1055
1045 # may need to restart read watcher 1056 # may need to restart read watcher
1046 unless ($self->{_rw}) { 1057 unless ($self->{_rw}) {
1047 $self->start_read 1058 $self->start_read
1796 1807
1797=item $handle->destroy 1808=item $handle->destroy
1798 1809
1799Shuts down the handle object as much as possible - this call ensures that 1810Shuts down the handle object as much as possible - this call ensures that
1800no further callbacks will be invoked and as many resources as possible 1811no further callbacks will be invoked and as many resources as possible
1801will be freed. You must not call any methods on the object afterwards. 1812will be freed. Any method you will call on the handle object after
1813destroying it in this way will be silently ignored (and it will return the
1814empty list).
1802 1815
1803Normally, you can just "forget" any references to an AnyEvent::Handle 1816Normally, you can just "forget" any references to an AnyEvent::Handle
1804object and it will simply shut down. This works in fatal error and EOF 1817object and it will simply shut down. This works in fatal error and EOF
1805callbacks, as well as code outside. It does I<NOT> work in a read or write 1818callbacks, as well as code outside. It does I<NOT> work in a read or write
1806callback, so when you want to destroy the AnyEvent::Handle object from 1819callback, so when you want to destroy the AnyEvent::Handle object from
1820sub destroy { 1833sub destroy {
1821 my ($self) = @_; 1834 my ($self) = @_;
1822 1835
1823 $self->DESTROY; 1836 $self->DESTROY;
1824 %$self = (); 1837 %$self = ();
1838 bless $self, "AnyEvent::Handle::destroyed";
1839}
1840
1841sub AnyEvent::Handle::destroyed::AUTOLOAD {
1842 #nop
1825} 1843}
1826 1844
1827=item AnyEvent::Handle::TLS_CTX 1845=item AnyEvent::Handle::TLS_CTX
1828 1846
1829This function creates and returns the AnyEvent::TLS object used by default 1847This function creates and returns the AnyEvent::TLS object used by default

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines