… | |
… | |
1087 | before it was actually written. One way to do that is to replace your |
1087 | before it was actually written. One way to do that is to replace your |
1088 | C<on_drain> handler by a callback that shuts down the socket (and set |
1088 | C<on_drain> handler by a callback that shuts down the socket (and set |
1089 | C<low_water_mark> to C<0>). This method is a shorthand for just that, and |
1089 | C<low_water_mark> to C<0>). This method is a shorthand for just that, and |
1090 | replaces the C<on_drain> callback with: |
1090 | replaces the C<on_drain> callback with: |
1091 | |
1091 | |
1092 | sub { shutdown $_[0]{fh}, 1 } # for push_shutdown |
1092 | sub { shutdown $_[0]{fh}, 1 } |
1093 | |
1093 | |
1094 | This simply shuts down the write side and signals an EOF condition to the |
1094 | This simply shuts down the write side and signals an EOF condition to the |
1095 | the peer. |
1095 | the peer. |
1096 | |
1096 | |
1097 | You can rely on the normal read queue and C<on_eof> handling |
1097 | You can rely on the normal read queue and C<on_eof> handling |
… | |
… | |
1616 | sub { |
1616 | sub { |
1617 | # when we can use 5.10 we can use ".", but for 5.8 we use the re-pack method |
1617 | # when we can use 5.10 we can use ".", but for 5.8 we use the re-pack method |
1618 | defined (my $len = eval { unpack $format, $_[0]{rbuf} }) |
1618 | defined (my $len = eval { unpack $format, $_[0]{rbuf} }) |
1619 | or return; |
1619 | or return; |
1620 | |
1620 | |
1621 | warn "len $len\n";#d# |
|
|
1622 | $format = length pack $format, $len; |
1621 | $format = length pack $format, $len; |
1623 | warn "len2 $format\n";#d# |
|
|
1624 | |
1622 | |
1625 | # bypass unshift if we already have the remaining chunk |
1623 | # bypass unshift if we already have the remaining chunk |
1626 | if ($format + $len <= length $_[0]{rbuf}) { |
1624 | if ($format + $len <= length $_[0]{rbuf}) { |
1627 | my $data = substr $_[0]{rbuf}, $format, $len; |
1625 | my $data = substr $_[0]{rbuf}, $format, $len; |
1628 | substr $_[0]{rbuf}, 0, $format + $len, ""; |
1626 | substr $_[0]{rbuf}, 0, $format + $len, ""; |
… | |
… | |
1775 | Note that AnyEvent::Handle will automatically C<start_read> for you when |
1773 | Note that AnyEvent::Handle will automatically C<start_read> for you when |
1776 | you change the C<on_read> callback or push/unshift a read callback, and it |
1774 | you change the C<on_read> callback or push/unshift a read callback, and it |
1777 | will automatically C<stop_read> for you when neither C<on_read> is set nor |
1775 | will automatically C<stop_read> for you when neither C<on_read> is set nor |
1778 | there are any read requests in the queue. |
1776 | there are any read requests in the queue. |
1779 | |
1777 | |
1780 | These methods will have no effect when in TLS mode (as TLS doesn't support |
1778 | In older versions of this module (<= 5.3), these methods had no effect, |
1781 | half-duplex connections). |
1779 | as TLS does not support half-duplex connections. In current versions they |
|
|
1780 | work as expected, as this behaviour is required to avoid certain resource |
|
|
1781 | attacks, where the program would be forced to read (and buffer) arbitrary |
|
|
1782 | amounts of data before being able to send some data. The drawback is that |
|
|
1783 | some readings of the the SSL/TLS specifications basically require this |
|
|
1784 | attack to be working, as SSL/TLS implementations might stall sending data |
|
|
1785 | during a rehandshake. |
|
|
1786 | |
|
|
1787 | As a guideline, during the initial handshake, you should not stop reading, |
|
|
1788 | and as a client, it might cause problems, depending on your applciation. |
1782 | |
1789 | |
1783 | =cut |
1790 | =cut |
1784 | |
1791 | |
1785 | sub stop_read { |
1792 | sub stop_read { |
1786 | my ($self) = @_; |
1793 | my ($self) = @_; |
1787 | |
1794 | |
1788 | delete $self->{_rw} unless $self->{tls}; |
1795 | delete $self->{_rw}; |
1789 | } |
1796 | } |
1790 | |
1797 | |
1791 | sub start_read { |
1798 | sub start_read { |
1792 | my ($self) = @_; |
1799 | my ($self) = @_; |
1793 | |
1800 | |