PROXY  WHOIS  RQUOTE  TEXTS  SOFT  FOREX  BBOARD
 Music  Philosophy  Code  Literature  Russian

= ROOT|Technical|Code_Examples|Perl|site_perl|AnyEvent|Handle.pm =

page 4 of 15



}

=item $handle->on_eof ($cb)

Replace the current C<on_eof> callback (see the C<on_eof> constructor argument).

=cut

sub on_eof {
   $_[0]{on_eof} = $_[1];
}

=item $handle->on_timeout ($cb)

Replace the current C<on_timeout> callback, or disables the callback
(but not the timeout) if C<$cb> = C<undef>. See C<timeout> constructor
argument.

=cut

sub on_timeout {
   $_[0]{on_timeout} = $_[1];
}

#############################################################################

=item $handle->timeout ($seconds)

Configures (or disables) the inactivity timeout.

=cut

sub timeout {
   my ($self, $timeout) = @_;

   $self->{timeout} = $timeout;
   $self->_timeout;
}

# reset the timeout watcher, as neccessary
# also check for time-outs
sub _timeout {
   my ($self) = @_;

   if ($self->{timeout}) {
      my $NOW = AnyEvent->now;

      # when would the timeout trigger?
      my $after = $self->{_activity} + $self->{timeout} - $NOW;

      # now or in the past already?
      if ($after <= 0) {
         $self->{_activity} = $NOW;

         if ($self->{on_timeout}) {
            $self->{on_timeout}($self);
         } else {
            $self->_error (&Errno::ETIMEDOUT);
         }

         # callback could have changed timeout value, optimise
         return unless $self->{timeout};

         # calculate new after
         $after = $self->{timeout};
      }

      Scalar::Util::weaken $self;
      return unless $self; # ->error could have destroyed $self

      $self->{_tw} ||= AnyEvent->timer (after => $after, cb => sub {
         delete $self->{_tw};
         $self->_timeout;
      });
   } else {
      delete $self->{_tw};
   }
}

#############################################################################

=back

=head2 WRITE QUEUE

AnyEvent::Handle manages two queues per handle, one for writing and one
for reading.

The write queue is very simple: you can add data to its end, and
AnyEvent::Handle will automatically try to get rid of it for you.

When data could be written and the write buffer is shorter then the low
water mark, the C<on_drain> callback will be invoked.

=over 4

=item $handle->on_drain ($cb)

Sets the C<on_drain> callback or clears it (see the description of
C<on_drain> in the constructor).
=4=

1|2|3| < PREV = PAGE 4 = NEXT > |5|6|7|8|9|10|11|12|13.15

UP TO ROOT | UP TO DIR | TO FIRST PAGE

Google
 


E-mail Facebook Google Digg del.icio.us BlinkList Fark Furl Ma.gnolia Netscape NewsVine Reddit Slashdot Spurl StumbleUpon Technorati YahooMyWeb LiveJournal Blogmarks TwitThis Live News2.ru BobrDobr.ru Memori.ru MoeMesto.ru

0.00627899 wallclock secs ( 0.00 usr + 0.00 sys = 0.00 CPU)