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.44 by root, Thu May 29 00:00:07 2008 UTC vs.
Revision 1.49 by root, Thu May 29 03:45:37 2008 UTC

14 14
15AnyEvent::Handle - non-blocking I/O on file handles via AnyEvent 15AnyEvent::Handle - non-blocking I/O on file handles via AnyEvent
16 16
17=cut 17=cut
18 18
19our $VERSION = '0.04'; 19our $VERSION = '1.0';
20 20
21=head1 SYNOPSIS 21=head1 SYNOPSIS
22 22
23 use AnyEvent; 23 use AnyEvent;
24 use AnyEvent::Handle; 24 use AnyEvent::Handle;
125=item timeout => $fractional_seconds 125=item timeout => $fractional_seconds
126 126
127If non-zero, then this enables an "inactivity" timeout: whenever this many 127If non-zero, then this enables an "inactivity" timeout: whenever this many
128seconds pass without a successful read or write on the underlying file 128seconds pass without a successful read or write on the underlying file
129handle, the C<on_timeout> callback will be invoked (and if that one is 129handle, the C<on_timeout> callback will be invoked (and if that one is
130missing, an C<ETIMEDOUT> errror will be raised). 130missing, an C<ETIMEDOUT> error will be raised).
131 131
132Note that timeout processing is also active when you currently do not have 132Note that timeout processing is also active when you currently do not have
133any outstanding read or write requests: If you plan to keep the connection 133any outstanding read or write requests: If you plan to keep the connection
134idle then you should disable the timout temporarily or ignore the timeout 134idle then you should disable the timout temporarily or ignore the timeout
135in the C<on_timeout> callback. 135in the C<on_timeout> callback.
155isn't finished). 155isn't finished).
156 156
157=item read_size => <bytes> 157=item read_size => <bytes>
158 158
159The default read block size (the amount of bytes this module will try to read 159The default read block size (the amount of bytes this module will try to read
160on each [loop iteration). Default: C<4096>. 160during each (loop iteration). Default: C<8192>.
161 161
162=item low_water_mark => <bytes> 162=item low_water_mark => <bytes>
163 163
164Sets the amount of bytes (default: C<0>) that make up an "empty" write 164Sets the amount of bytes (default: C<0>) that make up an "empty" write
165buffer: If the write reaches this size or gets even samller it is 165buffer: If the write reaches this size or gets even samller it is
238} 238}
239 239
240sub _shutdown { 240sub _shutdown {
241 my ($self) = @_; 241 my ($self) = @_;
242 242
243 delete $self->{_tw};
243 delete $self->{_rw}; 244 delete $self->{_rw};
244 delete $self->{_ww}; 245 delete $self->{_ww};
245 delete $self->{fh}; 246 delete $self->{fh};
246} 247}
247 248
328 # now or in the past already? 329 # now or in the past already?
329 if ($after <= 0) { 330 if ($after <= 0) {
330 $self->{_activity} = $NOW; 331 $self->{_activity} = $NOW;
331 332
332 if ($self->{on_timeout}) { 333 if ($self->{on_timeout}) {
333 $self->{on_timeout}->($self); 334 $self->{on_timeout}($self);
334 } else { 335 } else {
335 $! = Errno::ETIMEDOUT; 336 $! = Errno::ETIMEDOUT;
336 $self->error; 337 $self->error;
337 } 338 }
338 339
444 @_ = ($WH{$type} or Carp::croak "unsupported type passed to AnyEvent::Handle::push_write") 445 @_ = ($WH{$type} or Carp::croak "unsupported type passed to AnyEvent::Handle::push_write")
445 ->($self, @_); 446 ->($self, @_);
446 } 447 }
447 448
448 if ($self->{filter_w}) { 449 if ($self->{filter_w}) {
449 $self->{filter_w}->($self, \$_[0]); 450 $self->{filter_w}($self, \$_[0]);
450 } else { 451 } else {
451 $self->{wbuf} .= $_[0]; 452 $self->{wbuf} .= $_[0];
452 $self->_drain_wbuf; 453 $self->_drain_wbuf;
453 } 454 }
454} 455}
660 delete $self->{_rw}; 661 delete $self->{_rw};
661 return; 662 return;
662 } 663 }
663 } 664 }
664 665
665 if ($self->{_eof}) {
666 $self->_shutdown;
667 $self->{on_eof}($self) 666 $self->{on_eof}($self)
668 if $self->{on_eof}; 667 if $self->{_eof} && $self->{on_eof};
669 }
670} 668}
671 669
672=item $handle->on_read ($cb) 670=item $handle->on_read ($cb)
673 671
674This replaces the currently set C<on_read> callback, or clears it (when 672This replaces the currently set C<on_read> callback, or clears it (when
1055 1053
1056 if ($len > 0) { 1054 if ($len > 0) {
1057 $self->{_activity} = AnyEvent->now; 1055 $self->{_activity} = AnyEvent->now;
1058 1056
1059 $self->{filter_r} 1057 $self->{filter_r}
1060 ? $self->{filter_r}->($self, $rbuf) 1058 ? $self->{filter_r}($self, $rbuf)
1061 : $self->_drain_rbuf; 1059 : $self->_drain_rbuf;
1062 1060
1063 } elsif (defined $len) { 1061 } elsif (defined $len) {
1064 delete $self->{_rw}; 1062 delete $self->{_rw};
1065 delete $self->{_ww};
1066 delete $self->{_tw};
1067 $self->{_eof} = 1; 1063 $self->{_eof} = 1;
1068 $self->_drain_rbuf; 1064 $self->_drain_rbuf;
1069 1065
1070 } elsif ($! != EAGAIN && $! != EINTR && $! != WSAEWOULDBLOCK) { 1066 } elsif ($! != EAGAIN && $! != EINTR && $! != WSAEWOULDBLOCK) {
1071 return $self->error; 1067 return $self->error;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines