| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package File::FDkeeper::Client ; |
|
2
|
|
|
|
|
|
|
@ISA = qw(File::FDkeeper) ; |
|
3
|
|
|
|
|
|
|
|
|
4
|
3
|
|
|
3
|
|
16
|
use strict ; |
|
|
3
|
|
|
|
|
15
|
|
|
|
3
|
|
|
|
|
134
|
|
|
5
|
3
|
|
|
3
|
|
28
|
use File::FDkeeper ; |
|
|
3
|
|
|
|
|
7
|
|
|
|
3
|
|
|
|
|
67
|
|
|
6
|
3
|
|
|
3
|
|
3549
|
use File::FDpasser ; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
use Carp ; |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub new { |
|
11
|
|
|
|
|
|
|
my $class = shift ; |
|
12
|
|
|
|
|
|
|
my $path = shift ; |
|
13
|
|
|
|
|
|
|
my %args = @_ ; |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
my $this = {} ; |
|
16
|
|
|
|
|
|
|
$this->{path} = $path ; |
|
17
|
|
|
|
|
|
|
bless($this, $class) ; |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
while (my ($k, $v) = each %args){ |
|
20
|
|
|
|
|
|
|
croak("Invalid attribute '$k'") ; |
|
21
|
|
|
|
|
|
|
} |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
my $client = endp_connect($path) ; |
|
24
|
|
|
|
|
|
|
croak("Error connecting to server endpoint '$path': $!") unless $client ; |
|
25
|
|
|
|
|
|
|
$client->autoflush(1) ; |
|
26
|
|
|
|
|
|
|
$this->{client} = $client ; |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
return $this ; |
|
29
|
|
|
|
|
|
|
} |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub put { |
|
33
|
|
|
|
|
|
|
my $this = shift ; |
|
34
|
|
|
|
|
|
|
my $fh = shift ; |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
if (UNIVERSAL::isa($fh, 'GLOB')){ |
|
37
|
|
|
|
|
|
|
$fh = *{$fh}{IO} ; |
|
38
|
|
|
|
|
|
|
} |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
$this->_init_cmd('put') ; |
|
41
|
|
|
|
|
|
|
if (! send_file($this->{client}, $fh)){ |
|
42
|
|
|
|
|
|
|
close($this->{client}) ; |
|
43
|
|
|
|
|
|
|
croak("Error sending filehandle: $!") ; |
|
44
|
|
|
|
|
|
|
} |
|
45
|
|
|
|
|
|
|
my @ret = $this->_wrap_up() ; |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
return undef unless $ret[0] ; |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
# For some reason, the filehandle needs to be closed now |
|
50
|
|
|
|
|
|
|
# if we want to get it back later. |
|
51
|
|
|
|
|
|
|
close($fh) ; |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
return $ret[1] ; |
|
54
|
|
|
|
|
|
|
} |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub get { |
|
58
|
|
|
|
|
|
|
my $this = shift ; |
|
59
|
|
|
|
|
|
|
my $fhid = shift ; |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
$this->_init_cmd("get$fhid\n") ; |
|
62
|
|
|
|
|
|
|
my @ret = $this->_wrap_up() ; |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
return ($ret[0] ? $ret[2] : undef) ; |
|
65
|
|
|
|
|
|
|
} |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub del { |
|
69
|
|
|
|
|
|
|
my $this = shift ; |
|
70
|
|
|
|
|
|
|
my $fhid = shift ; |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
$this->_init_cmd("del$fhid\n") ; |
|
73
|
|
|
|
|
|
|
my @ret = $this->_wrap_up() ; |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
return $ret[0] ; |
|
76
|
|
|
|
|
|
|
} |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub cnt { |
|
80
|
|
|
|
|
|
|
my $this = shift ; |
|
81
|
|
|
|
|
|
|
my $fhid = shift ; |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
$this->_init_cmd("cnt") ; |
|
84
|
|
|
|
|
|
|
my @ret = $this->_wrap_up() ; |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
return $ret[1] ; |
|
87
|
|
|
|
|
|
|
} |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub _init_cmd { |
|
91
|
|
|
|
|
|
|
my $this = shift ; |
|
92
|
|
|
|
|
|
|
my $cmd = shift ; |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
my $client = $this->{client} ; |
|
95
|
|
|
|
|
|
|
if (! print $client $cmd){ |
|
96
|
|
|
|
|
|
|
close($this->{client}) ; |
|
97
|
|
|
|
|
|
|
croak("Error writing command: $!") ; |
|
98
|
|
|
|
|
|
|
} |
|
99
|
|
|
|
|
|
|
} |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub _wrap_up { |
|
103
|
|
|
|
|
|
|
my $this = shift ; |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
my $client = $this->{client} ; |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
my @ret = eval { |
|
108
|
|
|
|
|
|
|
my $resp_code = $this->_read_resp_code($client) ; |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
# print STDERR "[$resp_code $resp_data]\n" ; |
|
111
|
|
|
|
|
|
|
if ($resp_code eq 'okl'){ |
|
112
|
|
|
|
|
|
|
my $resp_data = <$client> ; |
|
113
|
|
|
|
|
|
|
chomp($resp_data) ; |
|
114
|
|
|
|
|
|
|
return (1, $resp_data, undef) ; |
|
115
|
|
|
|
|
|
|
} |
|
116
|
|
|
|
|
|
|
elsif ($resp_code eq 'okh'){ |
|
117
|
|
|
|
|
|
|
my $resp_fh = recv_fh($client) or die("Error receiving filehandle: $!") ; |
|
118
|
|
|
|
|
|
|
return (1, undef, $resp_fh) ; |
|
119
|
|
|
|
|
|
|
} |
|
120
|
|
|
|
|
|
|
elsif ($resp_code eq 'okn'){ |
|
121
|
|
|
|
|
|
|
return (1, undef, undef) ; |
|
122
|
|
|
|
|
|
|
} |
|
123
|
|
|
|
|
|
|
elsif ($resp_code eq 'err'){ |
|
124
|
|
|
|
|
|
|
my $resp_data = <$client> ; |
|
125
|
|
|
|
|
|
|
chomp($resp_data) ; |
|
126
|
|
|
|
|
|
|
return (0, $resp_data, undef) ; |
|
127
|
|
|
|
|
|
|
} |
|
128
|
|
|
|
|
|
|
else{ |
|
129
|
|
|
|
|
|
|
die("Invalid response code '$resp_code'") ; |
|
130
|
|
|
|
|
|
|
} |
|
131
|
|
|
|
|
|
|
} ; |
|
132
|
|
|
|
|
|
|
if ($@){ |
|
133
|
|
|
|
|
|
|
close($this->{client}) ; |
|
134
|
|
|
|
|
|
|
croak($@) ; |
|
135
|
|
|
|
|
|
|
} |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
return @ret ; |
|
138
|
|
|
|
|
|
|
} |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
1 ; |
|
142
|
|
|
|
|
|
|
|