line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package File::Send; |
2
|
|
|
|
|
|
|
{ |
3
|
|
|
|
|
|
|
$File::Send::VERSION = '0.002'; |
4
|
|
|
|
|
|
|
} |
5
|
1
|
|
|
1
|
|
31521
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
29
|
|
6
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
22
|
|
7
|
1
|
|
|
1
|
|
5
|
use Carp; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
62
|
|
8
|
1
|
|
|
1
|
|
658
|
use Errno 'EAGAIN'; |
|
1
|
|
|
|
|
1122
|
|
|
1
|
|
|
|
|
114
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
731
|
use Sub::Exporter::Progressive -setup => { exports => ['sendfile'], groups => { default => ['sendfile'] } }; |
|
1
|
|
|
|
|
904
|
|
|
1
|
|
|
|
|
11
|
|
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
111
|
use Fcntl 'SEEK_CUR'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
278
|
|
13
|
|
|
|
|
|
|
sub _systell { |
14
|
0
|
|
|
0
|
|
0
|
return sysseek $_[0], 0, SEEK_CUR; |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
my $backend = eval { require Sys::Sendfile; 'Sys::Sendfile' } || eval { require File::Map; 'File::Map' } || ''; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
if ($backend eq 'Sys::Sendfile') { |
20
|
|
|
|
|
|
|
*sendfile = sub { |
21
|
2
|
|
|
2
|
|
2398
|
my $ret = Sys::Sendfile::sendfile(@_); |
22
|
2
|
50
|
33
|
|
|
13
|
croak "Couldn't sendfile: $!" if not defined $ret and $! != EAGAIN; |
23
|
2
|
|
|
|
|
6
|
return $ret; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
elsif ($backend eq 'File::Map') { |
27
|
|
|
|
|
|
|
*sendfile = sub { |
28
|
|
|
|
|
|
|
my ($out, $in, $length) = @_; |
29
|
|
|
|
|
|
|
my $offset = _systell $in; |
30
|
|
|
|
|
|
|
$length ||= (-s $in) - $offset; |
31
|
|
|
|
|
|
|
File::Map::map_handle(my $map, $in, '<', $offset, $length); |
32
|
|
|
|
|
|
|
my $ret = syswrite $out, $map; |
33
|
|
|
|
|
|
|
croak "Couldn't sendfile: $!" if not defined $ret and $! != EAGAIN; |
34
|
|
|
|
|
|
|
return $ret; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
else { |
38
|
|
|
|
|
|
|
croak 'No backend for File::Send installed'; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
1; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=pod |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=head1 NAME |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
File::Send - Sending files over a socket efficiently and cross-platform |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=head1 VERSION |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
version 0.002 |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head1 SYNOPSIS |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=head1 DESCRIPTION |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
File::Send provides access to your operating system's C facility, or if that is not available uses L and C to achieve a similarly efficient io function. It allows you to efficiently transfer data from one filehandle to another. Typically the source is a file on disk and the sink is a socket, and some operating systems may not even support other usage. |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head1 FUNCTIONS |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head2 sendfile $out, $in, $count |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
This function sends up to C<$count> B from C<$in> to C<$out>. If $count isn't given, it will send all remaining bytes in $in. C<$in> and C<$out> can be a bareword, constant, scalar expression, typeglob, or a reference to a typeglob. It returns the number of bytes actually sent. On error it throws an exception describing the problem. This function is exported by default. |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=encoding utf8 |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=head1 FUNCTIONS |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head1 AUTHOR |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
Leon Timmermans |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
This software is copyright (c) 2011 by Leon Timmermans. |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
78
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=cut |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
__END__ |