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.219 by root, Mon Jul 18 01:19:43 2011 UTC vs.
Revision 1.221 by root, Thu Aug 4 09:35:37 2011 UTC

359already have occured on BSD systems), but at least it will protect you 359already have occured on BSD systems), but at least it will protect you
360from most attacks. 360from most attacks.
361 361
362=item read_size => <bytes> 362=item read_size => <bytes>
363 363
364The initial read block size, the number of bytes this module will try to 364The initial read block size, the number of bytes this module will try
365read during each loop iteration. Each handle object will consume at least 365to read during each loop iteration. Each handle object will consume
366this amount of memory for the read buffer as well, so when handling many 366at least this amount of memory for the read buffer as well, so when
367connections requirements). See also C<max_read_size>. Default: C<2048>. 367handling many connections watch out for memory requirements). See also
368C<max_read_size>. Default: C<2048>.
368 369
369=item max_read_size => <bytes> 370=item max_read_size => <bytes>
370 371
371The maximum read buffer size used by the dynamic adjustment 372The maximum read buffer size used by the dynamic adjustment
372algorithm: Each time AnyEvent::Handle can read C<read_size> bytes in 373algorithm: Each time AnyEvent::Handle can read C<read_size> bytes in
1543 1544
1544 sub { 1545 sub {
1545 # accept 1546 # accept
1546 if ($$rbuf =~ $accept) { 1547 if ($$rbuf =~ $accept) {
1547 $data .= substr $$rbuf, 0, $+[0], ""; 1548 $data .= substr $$rbuf, 0, $+[0], "";
1548 $cb->($self, $data); 1549 $cb->($_[0], $data);
1549 return 1; 1550 return 1;
1550 } 1551 }
1551 1552
1552 # reject 1553 # reject
1553 if ($reject && $$rbuf =~ $reject) { 1554 if ($reject && $$rbuf =~ $reject) {
1554 $self->_error (Errno::EBADMSG); 1555 $_[0]->_error (Errno::EBADMSG);
1555 } 1556 }
1556 1557
1557 # skip 1558 # skip
1558 if ($skip && $$rbuf =~ $skip) { 1559 if ($skip && $$rbuf =~ $skip) {
1559 $data .= substr $$rbuf, 0, $+[0], ""; 1560 $data .= substr $$rbuf, 0, $+[0], "";
1575 my ($self, $cb) = @_; 1576 my ($self, $cb) = @_;
1576 1577
1577 sub { 1578 sub {
1578 unless ($_[0]{rbuf} =~ s/^(0|[1-9][0-9]*)://) { 1579 unless ($_[0]{rbuf} =~ s/^(0|[1-9][0-9]*)://) {
1579 if ($_[0]{rbuf} =~ /[^0-9]/) { 1580 if ($_[0]{rbuf} =~ /[^0-9]/) {
1580 $self->_error (Errno::EBADMSG); 1581 $_[0]->_error (Errno::EBADMSG);
1581 } 1582 }
1582 return; 1583 return;
1583 } 1584 }
1584 1585
1585 my $len = $1; 1586 my $len = $1;
1586 1587
1587 $self->unshift_read (chunk => $len, sub { 1588 $_[0]->unshift_read (chunk => $len, sub {
1588 my $string = $_[1]; 1589 my $string = $_[1];
1589 $_[0]->unshift_read (chunk => 1, sub { 1590 $_[0]->unshift_read (chunk => 1, sub {
1590 if ($_[1] eq ",") { 1591 if ($_[1] eq ",") {
1591 $cb->($_[0], $string); 1592 $cb->($_[0], $string);
1592 } else { 1593 } else {
1593 $self->_error (Errno::EBADMSG); 1594 $_[0]->_error (Errno::EBADMSG);
1594 } 1595 }
1595 }); 1596 });
1596 }); 1597 });
1597 1598
1598 1 1599 1
1671 1672
1672 my $data; 1673 my $data;
1673 my $rbuf = \$self->{rbuf}; 1674 my $rbuf = \$self->{rbuf};
1674 1675
1675 sub { 1676 sub {
1676 my $ref = eval { $json->incr_parse ($self->{rbuf}) }; 1677 my $ref = eval { $json->incr_parse ($_[0]{rbuf}) };
1677 1678
1678 if ($ref) { 1679 if ($ref) {
1679 $self->{rbuf} = $json->incr_text; 1680 $_[0]{rbuf} = $json->incr_text;
1680 $json->incr_text = ""; 1681 $json->incr_text = "";
1681 $cb->($self, $ref); 1682 $cb->($_[0], $ref);
1682 1683
1683 1 1684 1
1684 } elsif ($@) { 1685 } elsif ($@) {
1685 # error case 1686 # error case
1686 $json->incr_skip; 1687 $json->incr_skip;
1687 1688
1688 $self->{rbuf} = $json->incr_text; 1689 $_[0]{rbuf} = $json->incr_text;
1689 $json->incr_text = ""; 1690 $json->incr_text = "";
1690 1691
1691 $self->_error (Errno::EBADMSG); 1692 $_[0]->_error (Errno::EBADMSG);
1692 1693
1693 () 1694 ()
1694 } else { 1695 } else {
1695 $self->{rbuf} = ""; 1696 $_[0]{rbuf} = "";
1696 1697
1697 () 1698 ()
1698 } 1699 }
1699 } 1700 }
1700}; 1701};
1733 # read remaining chunk 1734 # read remaining chunk
1734 $_[0]->unshift_read (chunk => $len, sub { 1735 $_[0]->unshift_read (chunk => $len, sub {
1735 if (my $ref = eval { Storable::thaw ($_[1]) }) { 1736 if (my $ref = eval { Storable::thaw ($_[1]) }) {
1736 $cb->($_[0], $ref); 1737 $cb->($_[0], $ref);
1737 } else { 1738 } else {
1738 $self->_error (Errno::EBADMSG); 1739 $_[0]->_error (Errno::EBADMSG);
1739 } 1740 }
1740 }); 1741 });
1741 } 1742 }
1742 1743
1743 1 1744 1

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines