1PerlIO::via::Timeout(3pUms)er Contributed Perl DocumentatPieornlIO::via::Timeout(3pm)
2
3
4
6 PerlIO::via::Timeout - a PerlIO layer that adds read & write timeout to
7 a handle
8
10 version 0.32
11
13 use Errno qw(ETIMEDOUT);
14 use PerlIO::via::Timeout qw(:all);
15 open my $fh, '<:via(Timeout)', 'foo.html';
16
17 # set the timeout layer to be 0.5 second read timeout
18 read_timeout($fh, 0.5);
19
20 my $line = <$fh>;
21 if ($line == undef && 0+$! == ETIMEDOUT) {
22 # timed out
23 ...
24 }
25
27 This package implements a PerlIO layer, that adds read / write timeout.
28 This can be useful to avoid blocking while accessing a handle (file,
29 socket, ...), and fail after some time.
30
31 The timeout is implemented by using "<select"> on the handle before
32 reading/writing.
33
34 WARNING the handle won't timeout if you use "sysread" or "syswrite" on
35 it, because these functions works at a lower level. However if you're
36 trying to implement a timeout for a socket, see IO::Socket::Timeout
37 that implements exactly that.
38
40 read_timeout
41 # set a read timeout of 2.5 seconds
42 read_timeout($fh, 2.5);
43 # get the current read timeout
44 my $secs = read_timeout($fh);
45
46 Getter / setter of the read timeout value.
47
48 write_timeout
49 # set a write timeout of 2.5 seconds
50 write_timeout($fh, 2.5);
51 # get the current write timeout
52 my $secs = write_timeout($fh);
53
54 Getter / setter of the write timeout value.
55
56 enable_timeout
57 enable_timeout($fh);
58
59 Equivalent to setting timeout_enabled to 1
60
61 disable_timeout
62 disable_timeout($fh);
63
64 Equivalent to setting timeout_enabled to 0
65
66 timeout_enabled
67 # disable timeout
68 timeout_enabled($fh, 0);
69 # enable timeout
70 timeout_enabled($fh, 1);
71 # get the current status
72 my $is_enabled = timeout_enabled($fh);
73
74 Getter / setter of the timeout enabled flag.
75
76 has_timeout_layer
77 if (has_timeout_layer($fh)) {
78 # set a write timeout of 2.5 seconds
79 write_timeout($fh, 2.5);
80 }
81
82 Returns wether the given filehandle is managed by PerlIO::via::Timeout.
83
85 PerlIO::via
86
88 Vincent Pit
89 Christian Hansen
90 Leon Timmmermans
91
93 Damien "dams" Krotkine
94
96 This software is copyright (c) 2013 by Damien "dams" Krotkine.
97
98 This is free software; you can redistribute it and/or modify it under
99 the same terms as the Perl 5 programming language system itself.
100
101
102
103perl v5.30.1 2020-01-30 PerlIO::via::Timeout(3pm)