… | |
… | |
53 | package AnyEvent::Handle; |
53 | package AnyEvent::Handle; |
54 | |
54 | |
55 | use Scalar::Util (); |
55 | use Scalar::Util (); |
56 | use List::Util (); |
56 | use List::Util (); |
57 | use Carp (); |
57 | use Carp (); |
58 | use Errno qw(EAGAIN EINTR); |
58 | use Errno qw(EAGAIN EWOULDBLOCK EINTR); |
59 | |
59 | |
60 | use AnyEvent (); BEGIN { AnyEvent::common_sense } |
60 | use AnyEvent (); BEGIN { AnyEvent::common_sense } |
61 | use AnyEvent::Util qw(WSAEWOULDBLOCK); |
61 | use AnyEvent::Util qw(WSAEWOULDBLOCK); |
62 | |
62 | |
63 | our $VERSION = $AnyEvent::VERSION; |
63 | our $VERSION = $AnyEvent::VERSION; |
… | |
… | |
971 | $self->{on_drain}($self) |
971 | $self->{on_drain}($self) |
972 | if $self->{low_water_mark} >= (length $self->{wbuf}) + (length $self->{_tls_wbuf}) |
972 | if $self->{low_water_mark} >= (length $self->{wbuf}) + (length $self->{_tls_wbuf}) |
973 | && $self->{on_drain}; |
973 | && $self->{on_drain}; |
974 | |
974 | |
975 | delete $self->{_ww} unless length $self->{wbuf}; |
975 | delete $self->{_ww} unless length $self->{wbuf}; |
976 | } elsif ($! != EAGAIN && $! != EINTR && $! != WSAEWOULDBLOCK) { |
976 | } elsif ($! != EAGAIN && $! != EINTR && $! != EWOULDBLOCK && $! != WSAEWOULDBLOCK) { |
977 | $self->_error ($!, 1); |
977 | $self->_error ($!, 1); |
978 | } |
978 | } |
979 | }; |
979 | }; |
980 | |
980 | |
981 | # try to write data immediately |
981 | # try to write data immediately |
… | |
… | |
1570 | }; |
1570 | }; |
1571 | |
1571 | |
1572 | =item regex => $accept[, $reject[, $skip], $cb->($handle, $data) |
1572 | =item regex => $accept[, $reject[, $skip], $cb->($handle, $data) |
1573 | |
1573 | |
1574 | Makes a regex match against the regex object C<$accept> and returns |
1574 | Makes a regex match against the regex object C<$accept> and returns |
1575 | everything up to and including the match. |
1575 | everything up to and including the match. All the usual regex variables |
|
|
1576 | ($1, %+ etc.) from the regex match are available in the callback. |
1576 | |
1577 | |
1577 | Example: read a single line terminated by '\n'. |
1578 | Example: read a single line terminated by '\n'. |
1578 | |
1579 | |
1579 | $handle->push_read (regex => qr<\n>, sub { ... }); |
1580 | $handle->push_read (regex => qr<\n>, sub { ... }); |
1580 | |
1581 | |
… | |
… | |
2038 | } elsif (defined $len) { |
2039 | } elsif (defined $len) { |
2039 | delete $self->{_rw}; |
2040 | delete $self->{_rw}; |
2040 | $self->{_eof} = 1; |
2041 | $self->{_eof} = 1; |
2041 | $self->_drain_rbuf; |
2042 | $self->_drain_rbuf; |
2042 | |
2043 | |
2043 | } elsif ($! != EAGAIN && $! != EINTR && $! != WSAEWOULDBLOCK) { |
2044 | } elsif ($! != EAGAIN && $! != EINTR && $! != EWOULDBLOCK && $! != WSAEWOULDBLOCK) { |
2044 | return $self->_error ($!, 1); |
2045 | return $self->_error ($!, 1); |
2045 | } |
2046 | } |
2046 | }; |
2047 | }; |
2047 | } |
2048 | } |
2048 | } |
2049 | } |
… | |
… | |
2304 | push @linger, AE::io $fh, 1, sub { |
2305 | push @linger, AE::io $fh, 1, sub { |
2305 | my $len = syswrite $fh, $wbuf, length $wbuf; |
2306 | my $len = syswrite $fh, $wbuf, length $wbuf; |
2306 | |
2307 | |
2307 | if ($len > 0) { |
2308 | if ($len > 0) { |
2308 | substr $wbuf, 0, $len, ""; |
2309 | substr $wbuf, 0, $len, ""; |
2309 | } elsif (defined $len || ($! != EAGAIN && $! != EINTR && $! != WSAEWOULDBLOCK)) { |
2310 | } elsif (defined $len || ($! != EAGAIN && $! != EINTR && $! != EWOULDBLOCK && $! != WSAEWOULDBLOCK)) { |
2310 | @linger = (); # end |
2311 | @linger = (); # end |
2311 | } |
2312 | } |
2312 | }; |
2313 | }; |
2313 | push @linger, AE::timer $linger, 0, sub { |
2314 | push @linger, AE::timer $linger, 0, sub { |
2314 | @linger = (); |
2315 | @linger = (); |