1 | =head1 NAME |
1 | =head1 NAME |
2 | |
2 | |
3 | AnyEvent::Handle - non-blocking I/O on file handles via AnyEvent |
3 | AnyEvent::Handle - non-blocking I/O on streaming handles via AnyEvent |
4 | |
4 | |
5 | =head1 SYNOPSIS |
5 | =head1 SYNOPSIS |
6 | |
6 | |
7 | use AnyEvent; |
7 | use AnyEvent; |
8 | use AnyEvent::Handle; |
8 | use AnyEvent::Handle; |
… | |
… | |
31 | $cv->recv; |
31 | $cv->recv; |
32 | |
32 | |
33 | =head1 DESCRIPTION |
33 | =head1 DESCRIPTION |
34 | |
34 | |
35 | This module is a helper module to make it easier to do event-based I/O on |
35 | This module is a helper module to make it easier to do event-based I/O on |
36 | filehandles. |
36 | stream-based filehandles (sockets, pipes or other stream things). |
37 | |
37 | |
38 | The L<AnyEvent::Intro> tutorial contains some well-documented |
38 | The L<AnyEvent::Intro> tutorial contains some well-documented |
39 | AnyEvent::Handle examples. |
39 | AnyEvent::Handle examples. |
40 | |
40 | |
41 | In the following, when the documentation refers to of "bytes" then this |
41 | In the following, when the documentation refers to of "bytes" then this |
… | |
… | |
531 | $self |
531 | $self |
532 | } |
532 | } |
533 | |
533 | |
534 | sub _start { |
534 | sub _start { |
535 | my ($self) = @_; |
535 | my ($self) = @_; |
|
|
536 | |
|
|
537 | # too many clueless people try to use udp and similar sockets |
|
|
538 | # with AnyEvent::Handle, do them a favour. |
|
|
539 | my $type = getsockopt $self->{fh}, Socket::SOL_SOCKET (), Socket::SO_TYPE (); |
|
|
540 | Carp::croak "AnyEvent::Handle: only stream sockets supported, anything else will NOT work!" |
|
|
541 | if Socket::SOCK_STREAM != (unpack "I", $type) && defined $type; |
536 | |
542 | |
537 | AnyEvent::Util::fh_nonblocking $self->{fh}, 1; |
543 | AnyEvent::Util::fh_nonblocking $self->{fh}, 1; |
538 | |
544 | |
539 | $self->{_activity} = |
545 | $self->{_activity} = |
540 | $self->{_ractivity} = |
546 | $self->{_ractivity} = |