GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
PerlIO::via::Timeout(3) User Contributed Perl Documentation PerlIO::via::Timeout(3)

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

version 0.32

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

  # set the timeout layer to be 0.5 second read timeout
  read_timeout($fh, 0.5);

  my $line = <$fh>;
  if ($line == undef && 0+$! == ETIMEDOUT) {
    # timed out
    ...
  }

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

The timeout is implemented by using "<select"> on the handle before reading/writing.

WARNING the handle won't timeout if you use "sysread" or "syswrite" on it, because these functions works at a lower level. However if you're trying to implement a timeout for a socket, see IO::Socket::Timeout that implements exactly that.

  # set a read timeout of 2.5 seconds
  read_timeout($fh, 2.5);
  # get the current read timeout
  my $secs = read_timeout($fh);

Getter / setter of the read timeout value.

  # set a write timeout of 2.5 seconds
  write_timeout($fh, 2.5);
  # get the current write timeout
  my $secs = write_timeout($fh);

Getter / setter of the write timeout value.

  enable_timeout($fh);

Equivalent to setting timeout_enabled to 1

  disable_timeout($fh);

Equivalent to setting timeout_enabled to 0

  # disable timeout
  timeout_enabled($fh, 0);
  # enable timeout
  timeout_enabled($fh, 1);
  # get the current status
  my $is_enabled = timeout_enabled($fh);

Getter / setter of the timeout enabled flag.

  if (has_timeout_layer($fh)) {
    # set a write timeout of 2.5 seconds
    write_timeout($fh, 2.5);
  }

Returns wether the given filehandle is managed by PerlIO::via::Timeout.

PerlIO::via

Vincent Pit
Christian Hansen
Leon Timmmermans

Damien "dams" Krotkine

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.

2015-07-30 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.