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.194 by root, Thu May 20 21:22:21 2010 UTC vs.
Revision 1.197 by root, Tue Aug 31 00:59:55 2010 UTC

191 191
192To access (and remove data from) the read buffer, use the C<< ->rbuf >> 192To access (and remove data from) the read buffer, use the C<< ->rbuf >>
193method or access the C<< $handle->{rbuf} >> member directly. Note that you 193method or access the C<< $handle->{rbuf} >> member directly. Note that you
194must not enlarge or modify the read buffer, you can only remove data at 194must not enlarge or modify the read buffer, you can only remove data at
195the beginning from it. 195the beginning from it.
196
197You can also call C<< ->push_read (...) >> or any other function that
198modifies the read queue. Or do both. Or ...
196 199
197When an EOF condition is detected then AnyEvent::Handle will first try to 200When an EOF condition is detected then AnyEvent::Handle will first try to
198feed all the remaining data to the queued callbacks and C<on_read> before 201feed all the remaining data to the queued callbacks and C<on_read> before
199calling the C<on_eof> callback. If no progress can be made, then a fatal 202calling the C<on_eof> callback. If no progress can be made, then a fatal
200error will be raised (with C<$!> set to C<EPIPE>). 203error will be raised (with C<$!> set to C<EPIPE>).
534sub _start { 537sub _start {
535 my ($self) = @_; 538 my ($self) = @_;
536 539
537 # too many clueless people try to use udp and similar sockets 540 # too many clueless people try to use udp and similar sockets
538 # with AnyEvent::Handle, do them a favour. 541 # with AnyEvent::Handle, do them a favour.
539 if (Socket::SOCK_STREAM != unpack "I", getsockopt $self->{fh}, Socket::SOL_SOCKET (), Socket::SO_TYPE ()) { 542 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!"; 543 Carp::croak "AnyEvent::Handle: only stream sockets supported, anything else will NOT work!"
541 } 544 if Socket::SOCK_STREAM () != (unpack "I", $type) && defined $type;
542 545
543 AnyEvent::Util::fh_nonblocking $self->{fh}, 1; 546 AnyEvent::Util::fh_nonblocking $self->{fh}, 1;
544 547
545 $self->{_activity} = 548 $self->{_activity} =
546 $self->{_ractivity} = 549 $self->{_ractivity} =
933 936
934Instead of formatting your data yourself, you can also let this module 937Instead of formatting your data yourself, you can also let this module
935do the job by specifying a type and type-specific arguments. You 938do the job by specifying a type and type-specific arguments. You
936can also specify the (fully qualified) name of a package, in which 939can also specify the (fully qualified) name of a package, in which
937case AnyEvent tries to load the package and then expects to find the 940case AnyEvent tries to load the package and then expects to find the
938C<anyevent_read_type> function inside (see "custom write types", below). 941C<anyevent_write_type> function inside (see "custom write types", below).
939 942
940Predefined types are (if you have ideas for additional types, feel free to 943Predefined types are (if you have ideas for additional types, feel free to
941drop by and tell us): 944drop by and tell us):
942 945
943=over 4 946=over 4
1107ways, the "simple" way, using only C<on_read> and the "complex" way, using 1110ways, the "simple" way, using only C<on_read> and the "complex" way, using
1108a queue. 1111a queue.
1109 1112
1110In the simple case, you just install an C<on_read> callback and whenever 1113In the simple case, you just install an C<on_read> callback and whenever
1111new data arrives, it will be called. You can then remove some data (if 1114new data arrives, it will be called. You can then remove some data (if
1112enough is there) from the read buffer (C<< $handle->rbuf >>). Or you cna 1115enough is there) from the read buffer (C<< $handle->rbuf >>). Or you can
1113leave the data there if you want to accumulate more (e.g. when only a 1116leave the data there if you want to accumulate more (e.g. when only a
1114partial message has been received so far). 1117partial message has been received so far), or change the read queue with
1118e.g. C<push_read>.
1115 1119
1116In the more complex case, you want to queue multiple callbacks. In this 1120In the more complex case, you want to queue multiple callbacks. In this
1117case, AnyEvent::Handle will call the first queued callback each time new 1121case, AnyEvent::Handle will call the first queued callback each time new
1118data arrives (also the first time it is queued) and removes it when it has 1122data arrives (also the first time it is queued) and removes it when it has
1119done its job (see C<push_read>, below). 1123done its job (see C<push_read>, below).

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines