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.200 by root, Tue Oct 12 06:47:54 2010 UTC vs.
Revision 1.204 by root, Mon Nov 15 03:29:17 2010 UTC

75 } 75 }
76 76
77 \&$func 77 \&$func
78} 78}
79 79
80sub MAX_READ_SIZE() { 131072 }
81
80=head1 METHODS 82=head1 METHODS
81 83
82=over 4 84=over 4
83 85
84=item $handle = B<new> AnyEvent::Handle fh => $filehandle, key => value... 86=item $handle = B<new> AnyEvent::Handle fh => $filehandle, key => value...
157 159
158Some errors are fatal (which is indicated by C<$fatal> being true). On 160Some errors are fatal (which is indicated by C<$fatal> being true). On
159fatal errors the handle object will be destroyed (by a call to C<< -> 161fatal errors the handle object will be destroyed (by a call to C<< ->
160destroy >>) after invoking the error callback (which means you are free to 162destroy >>) after invoking the error callback (which means you are free to
161examine the handle object). Examples of fatal errors are an EOF condition 163examine the handle object). Examples of fatal errors are an EOF condition
162with active (but unsatisifable) read watchers (C<EPIPE>) or I/O errors. In 164with active (but unsatisfiable) read watchers (C<EPIPE>) or I/O errors. In
163cases where the other side can close the connection at will, it is 165cases where the other side can close the connection at will, it is
164often easiest to not report C<EPIPE> errors in this callback. 166often easiest to not report C<EPIPE> errors in this callback.
165 167
166AnyEvent::Handle tries to find an appropriate error code for you to check 168AnyEvent::Handle tries to find an appropriate error code for you to check
167against, but in some cases (TLS errors), this does not work well. It is 169against, but in some cases (TLS errors), this does not work well. It is
337already have occured on BSD systems), but at least it will protect you 339already have occured on BSD systems), but at least it will protect you
338from most attacks. 340from most attacks.
339 341
340=item read_size => <bytes> 342=item read_size => <bytes>
341 343
342The default read block size (the number of bytes this module will 344The initial read block size, the number of bytes this module will try to
343try to read during each loop iteration, which affects memory 345read during each loop iteration. Each handle object will consume at least
344requirements). Default: C<8192>. 346this amount of memory for the read buffer as well, so when handling many
347connections requirements). See also C<max_read_size>. Default: C<2048>.
348
349=item max_read_size => <bytes>
350
351The maximum read buffer size used by the dynamic adjustment
352algorithm: Each time AnyEvent::Handle can read C<read_size> bytes in
353one go it will double C<read_size> up to the maximum given by this
354option. Default: C<131072> or C<read_size>, whichever is higher.
345 355
346=item low_water_mark => <bytes> 356=item low_water_mark => <bytes>
347 357
348Sets the number of bytes (default: C<0>) that make up an "empty" write 358Sets the number of bytes (default: C<0>) that make up an "empty" write
349buffer: If the buffer reaches this size or gets even samller it is 359buffer: If the buffer reaches this size or gets even samller it is
546 556
547 $self->{_activity} = 557 $self->{_activity} =
548 $self->{_ractivity} = 558 $self->{_ractivity} =
549 $self->{_wactivity} = AE::now; 559 $self->{_wactivity} = AE::now;
550 560
561 $self->{read_size} ||= 2048;
562 $self->{max_read_size} = $self->{read_size}
563 if $self->{read_size} > ($self->{max_read_size} || MAX_READ_SIZE);
564
551 $self->timeout (delete $self->{timeout} ) if $self->{timeout}; 565 $self->timeout (delete $self->{timeout} ) if $self->{timeout};
552 $self->rtimeout (delete $self->{rtimeout} ) if $self->{rtimeout}; 566 $self->rtimeout (delete $self->{rtimeout} ) if $self->{rtimeout};
553 $self->wtimeout (delete $self->{wtimeout} ) if $self->{wtimeout}; 567 $self->wtimeout (delete $self->{wtimeout} ) if $self->{wtimeout};
554 568
555 $self->no_delay (delete $self->{no_delay} ) if exists $self->{no_delay} && $self->{no_delay}; 569 $self->no_delay (delete $self->{no_delay} ) if exists $self->{no_delay} && $self->{no_delay};
764 $_[0]{$on_timeout} = $_[1]; 778 $_[0]{$on_timeout} = $_[1];
765 }; 779 };
766 780
767 *$timeout = sub { 781 *$timeout = sub {
768 my ($self, $new_value) = @_; 782 my ($self, $new_value) = @_;
783
784 $new_value >= 0
785 or Carp::croak "AnyEvent::Handle->$timeout called with negative timeout ($new_value), caught";
769 786
770 $self->{$timeout} = $new_value; 787 $self->{$timeout} = $new_value;
771 delete $self->{$tw}; &$cb; 788 delete $self->{$tw}; &$cb;
772 }; 789 };
773 790
1742 unless ($self->{_rw} || $self->{_eof} || !$self->{fh}) { 1759 unless ($self->{_rw} || $self->{_eof} || !$self->{fh}) {
1743 Scalar::Util::weaken $self; 1760 Scalar::Util::weaken $self;
1744 1761
1745 $self->{_rw} = AE::io $self->{fh}, 0, sub { 1762 $self->{_rw} = AE::io $self->{fh}, 0, sub {
1746 my $rbuf = \($self->{tls} ? my $buf : $self->{rbuf}); 1763 my $rbuf = \($self->{tls} ? my $buf : $self->{rbuf});
1747 my $len = sysread $self->{fh}, $$rbuf, $self->{read_size} || 8192, length $$rbuf; 1764 my $len = sysread $self->{fh}, $$rbuf, $self->{read_size}, length $$rbuf;
1748 1765
1749 if ($len > 0) { 1766 if ($len > 0) {
1750 $self->{_activity} = $self->{_ractivity} = AE::now; 1767 $self->{_activity} = $self->{_ractivity} = AE::now;
1751 1768
1752 if ($self->{tls}) { 1769 if ($self->{tls}) {
1753 Net::SSLeay::BIO_write ($self->{_rbio}, $$rbuf); 1770 Net::SSLeay::BIO_write ($self->{_rbio}, $$rbuf);
1754 1771
1755 &_dotls ($self); 1772 &_dotls ($self);
1756 } else { 1773 } else {
1757 $self->_drain_rbuf; 1774 $self->_drain_rbuf;
1775 }
1776
1777 if ($len == $self->{read_size}) {
1778 $self->{read_size} *= 2;
1779 $self->{read_size} = $self->{max_read_size} || MAX_READ_SIZE
1780 if $self->{read_size} > ($self->{max_read_size} || MAX_READ_SIZE);
1758 } 1781 }
1759 1782
1760 } elsif (defined $len) { 1783 } elsif (defined $len) {
1761 delete $self->{_rw}; 1784 delete $self->{_rw};
1762 $self->{_eof} = 1; 1785 $self->{_eof} = 1;
2003 push @linger, AE::io $fh, 1, sub { 2026 push @linger, AE::io $fh, 1, sub {
2004 my $len = syswrite $fh, $wbuf, length $wbuf; 2027 my $len = syswrite $fh, $wbuf, length $wbuf;
2005 2028
2006 if ($len > 0) { 2029 if ($len > 0) {
2007 substr $wbuf, 0, $len, ""; 2030 substr $wbuf, 0, $len, "";
2008 } else { 2031 } elsif (defined $len || ($! != EAGAIN && $! != EINTR && $! != WSAEWOULDBLOCK)) {
2009 @linger = (); # end 2032 @linger = (); # end
2010 } 2033 }
2011 }; 2034 };
2012 push @linger, AE::timer $linger, 0, sub { 2035 push @linger, AE::timer $linger, 0, sub {
2013 @linger = (); 2036 @linger = ();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines