line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
=head1 NAME |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
AnyEvent::IO::Perl - pure perl backend for AnyEvent::IO |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 SYNOPSIS |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
use AnyEvent::IO; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 DESCRIPTION |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
This is the pure-perl backend of L - it is always available, |
12
|
|
|
|
|
|
|
but does not actually implement any I/O operation asynchronously - |
13
|
|
|
|
|
|
|
everything is synchronous. |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
For simple programs that can wait for I/O, this is likely the most |
16
|
|
|
|
|
|
|
efficient implementation. |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=cut |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
package AnyEvent::IO::Perl; |
21
|
|
|
|
|
|
|
|
22
|
4
|
|
|
4
|
|
2176
|
use AnyEvent (); BEGIN { AnyEvent::common_sense } |
|
4
|
|
|
4
|
|
29
|
|
|
4
|
|
|
|
|
103
|
|
|
4
|
|
|
|
|
17
|
|
23
|
|
|
|
|
|
|
our $VERSION = $AnyEvent::VERSION; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
package AnyEvent::IO; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
our $MODEL = "AnyEvent::IO::Perl"; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub aio_load($$) { |
30
|
4
|
|
|
4
|
1
|
13
|
my ($path, $cb, $fh, $data) = @_; |
31
|
|
|
|
|
|
|
|
32
|
4
|
50
|
33
|
|
|
269
|
$cb->( |
33
|
|
|
|
|
|
|
(open $fh, "<:raw:perlio", $path |
34
|
|
|
|
|
|
|
and stat $fh |
35
|
|
|
|
|
|
|
and (-s _) == sysread $fh, $data, -s _) |
36
|
|
|
|
|
|
|
? $data : () |
37
|
|
|
|
|
|
|
); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub aio_open($$$$) { |
41
|
3
|
100
|
|
3
|
1
|
126
|
sysopen my $fh, $_[0], $_[1], $_[2] |
42
|
|
|
|
|
|
|
or return $_[3](); |
43
|
|
|
|
|
|
|
|
44
|
2
|
|
|
|
|
13
|
$_[3]($fh) |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub aio_close($$) { |
48
|
2
|
|
|
2
|
1
|
25
|
$_[1](close $_[0]); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub aio_seek($$$$) { |
52
|
1
|
|
|
1
|
1
|
2
|
my $data; |
53
|
1
|
|
33
|
|
|
12
|
$_[3](sysseek $_[0], $_[1], $_[2] or ()); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub aio_read($$$) { |
57
|
3
|
|
|
3
|
1
|
4
|
my $data; |
58
|
3
|
50
|
|
|
|
43
|
$_[2]( (defined sysread $_[0], $data, $_[1]) ? $data : () ); |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub aio_write($$$) { |
62
|
4
|
|
|
4
|
1
|
70
|
my $res = syswrite $_[0], $_[1]; |
63
|
4
|
50
|
|
|
|
23
|
$_[2](defined $res ? $res : ()); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub aio_truncate($$$) { |
67
|
|
|
|
|
|
|
#TODO: raises an exception on !truncate|ftruncate systems, maybe eval + set errno? |
68
|
0
|
|
0
|
0
|
1
|
0
|
$_[2](truncate $_[0], $_[1] or ()); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub aio_utime($$$$) { |
72
|
0
|
|
0
|
0
|
1
|
0
|
$_[3](utime $_[1], $_[2], $_[0] or ()); |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub aio_chown($$$$) { |
76
|
0
|
|
0
|
0
|
1
|
0
|
$_[3](chown defined $_[1] ? $_[1] : -1, defined $_[2] ? $_[2] : -1, $_[0] or ()); |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub aio_chmod($$$) { |
80
|
0
|
|
0
|
0
|
1
|
0
|
$_[2](chmod $_[1], $_[0] or ()); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub aio_stat($$) { |
84
|
8
|
|
|
8
|
1
|
187
|
$_[1](stat $_[0]); |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub aio_lstat($$) { |
88
|
1
|
|
|
1
|
1
|
17
|
$_[1](lstat $_[0]); |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub aio_link($$$) { |
92
|
0
|
|
0
|
0
|
1
|
0
|
$_[2](link $_[0], $_[1] or ()); |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub aio_symlink($$$) { |
96
|
|
|
|
|
|
|
#TODO: raises an exception on !symlink systems, maybe eval + set errno? |
97
|
0
|
|
0
|
0
|
1
|
0
|
$_[2](symlink $_[0], $_[1] or ()); |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub aio_readlink($$) { |
101
|
|
|
|
|
|
|
#TODO: raises an exception on !symlink systems, maybe eval + set errno? |
102
|
0
|
|
|
0
|
1
|
0
|
my $res = readlink $_[0]; |
103
|
0
|
0
|
|
|
|
0
|
$_[1](defined $res ? $res : ()); |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub aio_rename($$$) { |
107
|
1
|
|
33
|
1
|
1
|
48
|
$_[2](rename $_[0], $_[1] or ()); |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub aio_unlink($$) { |
111
|
2
|
|
66
|
2
|
1
|
83
|
$_[1](unlink $_[0] or ()); |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub aio_mkdir($$$) { |
115
|
2
|
|
66
|
2
|
1
|
189
|
$_[2](mkdir $_[0], $_[1] or ()); |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
sub aio_rmdir($$) { |
119
|
2
|
|
66
|
2
|
1
|
87
|
$_[1](rmdir $_[0] or ()); |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
sub aio_readdir($$) { |
123
|
2
|
|
|
2
|
1
|
5
|
my ($fh, @res); |
124
|
|
|
|
|
|
|
|
125
|
2
|
100
|
|
|
|
67
|
opendir $fh, $_[0] |
126
|
|
|
|
|
|
|
or return $_[1](); |
127
|
|
|
|
|
|
|
|
128
|
1
|
|
|
|
|
34
|
@res = grep !/^\.\.?$/, readdir $fh; |
129
|
|
|
|
|
|
|
|
130
|
1
|
50
|
|
|
|
32
|
$_[1]((closedir $fh) ? \@res : ()); |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head1 SEE ALSO |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
L, L. |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=head1 AUTHOR |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
Marc Lehmann |
140
|
|
|
|
|
|
|
http://anyevent.schmorp.de |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=cut |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
1 |
145
|
|
|
|
|
|
|
|