The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

PerlIO::via::Timeout - a PerlIO layer that adds read & write timeout to a handle

VERSION

version 0.16

SYNOPSIS

  use PerlIO::via::Timeout qw(timeout_strategy);
  open my $fh, '<:via(Timeout)', 'foo.html';

  # creates a new timeout strategy with 0.5 second timeout, using select as
  # timeout system
  timeout_strategy($fh, 'Select', read_timeout => 0.5);

  my $line = <$fh>;
  if ($line == undef && $! eq 'Operation timed out') { ... }

DESCRIPTION

This package implements a PerlIO layer, that adds read / write timeout. This can be useful to avoid blocking while accessing a filehandle, and fail after some time.

FUNCTIONS

timeout_strategy

  # creates a L<PerlIO::via::Timeout::Strategy::Select strategy> with 0.5
  # read_timeout and set it to $fh
  timeout_strategy($fh, 'Select', read_timeout => 0.5);

  # same but give an alarm strategy instance directly
  my $strategy = PerlIO::via::Timeout::Strategy::Alarm->new(write_timeout => 2)
  timeout_strategy($fh, $strategy);

  # used as a getter, returns the current strategy
  my $strategy = timeout_strategy($fh);

AVAILABLE STRATEGIES

PerlIO::via::Timeout::Strategy::Select
PerlIO::via::Timeout::Strategy::Alarm

SEE ALSO

PerlIO::via

THANKS TO

Vincent Pit
Christian Hansen
Leon Timmmermans

AUTHOR

Damien "dams" Krotkine

COPYRIGHT AND LICENSE

This software is copyright (c) 2013 by Damien "dams" Krotkine.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.