… | |
… | |
2 | |
2 | |
3 | no warnings; |
3 | no warnings; |
4 | use strict; |
4 | use strict; |
5 | |
5 | |
6 | use AnyEvent (); |
6 | use AnyEvent (); |
7 | use AnyEvent::Util (); |
7 | use AnyEvent::Util qw(WSAWOULDBLOCK); |
8 | use Scalar::Util (); |
8 | use Scalar::Util (); |
9 | use Carp (); |
9 | use Carp (); |
10 | use Fcntl (); |
10 | use Fcntl (); |
11 | use Errno qw/EAGAIN EINTR/; |
11 | use Errno qw/EAGAIN EINTR/; |
12 | |
12 | |
13 | =head1 NAME |
13 | =head1 NAME |
14 | |
14 | |
15 | AnyEvent::Handle - non-blocking I/O on file handles via AnyEvent |
15 | AnyEvent::Handle - non-blocking I/O on file handles via AnyEvent |
16 | |
16 | |
17 | This module is experimental. |
|
|
18 | |
|
|
19 | =cut |
17 | =cut |
20 | |
18 | |
21 | our $VERSION = '0.04'; |
19 | our $VERSION = '0.04'; |
22 | |
20 | |
23 | =head1 SYNOPSIS |
21 | =head1 SYNOPSIS |
… | |
… | |
25 | use AnyEvent; |
23 | use AnyEvent; |
26 | use AnyEvent::Handle; |
24 | use AnyEvent::Handle; |
27 | |
25 | |
28 | my $cv = AnyEvent->condvar; |
26 | my $cv = AnyEvent->condvar; |
29 | |
27 | |
30 | my $ae_fh = AnyEvent::Handle->new (fh => \*STDIN); |
28 | my $handle = |
31 | |
|
|
32 | #TODO |
|
|
33 | |
|
|
34 | # or use the constructor to pass the callback: |
|
|
35 | |
|
|
36 | my $ae_fh2 = |
|
|
37 | AnyEvent::Handle->new ( |
29 | AnyEvent::Handle->new ( |
38 | fh => \*STDIN, |
30 | fh => \*STDIN, |
39 | on_eof => sub { |
31 | on_eof => sub { |
40 | $cv->broadcast; |
32 | $cv->broadcast; |
41 | }, |
33 | }, |
42 | #TODO |
|
|
43 | ); |
34 | ); |
44 | |
35 | |
45 | $cv->wait; |
36 | # send some request line |
|
|
37 | $handle->push_write ("getinfo\015\012"); |
|
|
38 | |
|
|
39 | # read the response line |
|
|
40 | $handle->push_read (line => sub { |
|
|
41 | my ($handle, $line) = @_; |
|
|
42 | warn "read line <$line>\n"; |
|
|
43 | $cv->send; |
|
|
44 | }); |
|
|
45 | |
|
|
46 | $cv->recv; |
46 | |
47 | |
47 | =head1 DESCRIPTION |
48 | =head1 DESCRIPTION |
48 | |
49 | |
49 | This module is a helper module to make it easier to do event-based I/O on |
50 | This module is a helper module to make it easier to do event-based I/O on |
50 | filehandles. For utility functions for doing non-blocking connects and accepts |
51 | filehandles. For utility functions for doing non-blocking connects and accepts |
… | |
… | |
300 | $self->{on_drain}($self) |
301 | $self->{on_drain}($self) |
301 | if $self->{low_water_mark} >= length $self->{wbuf} |
302 | if $self->{low_water_mark} >= length $self->{wbuf} |
302 | && $self->{on_drain}; |
303 | && $self->{on_drain}; |
303 | |
304 | |
304 | delete $self->{ww} unless length $self->{wbuf}; |
305 | delete $self->{ww} unless length $self->{wbuf}; |
305 | } elsif ($! != EAGAIN && $! != EINTR) { |
306 | } elsif ($! != EAGAIN && $! != EINTR && $! != WSAWOULDBLOCK) { |
306 | $self->error; |
307 | $self->error; |
307 | } |
308 | } |
308 | }; |
309 | }; |
309 | |
310 | |
310 | $self->{ww} = AnyEvent->io (fh => $self->{fh}, poll => "w", cb => $cb); |
311 | $self->{ww} = AnyEvent->io (fh => $self->{fh}, poll => "w", cb => $cb); |
… | |
… | |
786 | } elsif (defined $len) { |
787 | } elsif (defined $len) { |
787 | delete $self->{rw}; |
788 | delete $self->{rw}; |
788 | $self->{eof} = 1; |
789 | $self->{eof} = 1; |
789 | $self->_drain_rbuf; |
790 | $self->_drain_rbuf; |
790 | |
791 | |
791 | } elsif ($! != EAGAIN && $! != EINTR) { |
792 | } elsif ($! != EAGAIN && $! != EINTR && $! != &AnyEvent::Util::WSAWOULDBLOCK) { |
792 | return $self->error; |
793 | return $self->error; |
793 | } |
794 | } |
794 | }); |
795 | }); |
795 | } |
796 | } |
796 | } |
797 | } |