line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Device::TLSPrinter::Network; |
2
|
1
|
|
|
1
|
|
1467
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
37
|
|
3
|
1
|
|
|
1
|
|
5
|
use Carp; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
67
|
|
4
|
1
|
|
|
1
|
|
2273
|
use IO::Socket::INET; |
|
1
|
|
|
|
|
29749
|
|
|
1
|
|
|
|
|
10
|
|
5
|
1
|
|
|
1
|
|
671
|
use Socket; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
957
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
{ |
8
|
1
|
|
|
1
|
|
5
|
no strict "vars"; |
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
372
|
|
9
|
|
|
|
|
|
|
@ISA = qw< Device::TLSPrinter >; |
10
|
|
|
|
|
|
|
} |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
# |
14
|
|
|
|
|
|
|
# init() |
15
|
|
|
|
|
|
|
# ---- |
16
|
|
|
|
|
|
|
sub init { |
17
|
0
|
|
|
0
|
0
|
|
my ($self, %args) = @_; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# check arguments |
20
|
0
|
|
|
|
|
|
my ($host, $port) = split /:/, $self->_device; |
21
|
0
|
|
0
|
|
|
|
$port = getservbyname($port, "tcp") || $port; |
22
|
0
|
0
|
0
|
|
|
|
croak "error: Please specify a host and a port" if not $host or not $port; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# connect to the specified host and port |
25
|
0
|
0
|
|
|
|
|
my $sock = IO::Socket::INET->new( |
26
|
|
|
|
|
|
|
PeerHost => $host, Proto => "tcp", PeerPort => $port, |
27
|
|
|
|
|
|
|
autoflush => 1, Timeout => $self->_timeout |
28
|
|
|
|
|
|
|
) or croak "error: Can't connect to <$host\:$port>: $!"; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# set socket options |
31
|
0
|
|
|
|
|
|
$sock->sockopt(SO_RCVLOWAT, 1); # receiving buffer size |
32
|
0
|
|
|
|
|
|
$sock->sockopt(SO_SNDLOWAT, 1); # sending buffer size |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
# store the socket in the object |
35
|
0
|
|
|
|
|
|
$self->_socket($sock); |
36
|
|
|
|
|
|
|
|
37
|
0
|
|
|
|
|
|
return $self |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
# |
42
|
|
|
|
|
|
|
# read() |
43
|
|
|
|
|
|
|
# ---- |
44
|
|
|
|
|
|
|
sub read { |
45
|
0
|
|
|
0
|
0
|
|
my ($self, %args) = @_; |
46
|
0
|
|
|
|
|
|
my $n = $self->{_socket}->sysread(my $buff, $args{expect}); |
47
|
0
|
|
|
|
|
|
return ($n, $buff) |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# |
52
|
|
|
|
|
|
|
# write() |
53
|
|
|
|
|
|
|
# ----- |
54
|
|
|
|
|
|
|
sub write { |
55
|
0
|
|
|
0
|
0
|
|
my ($self, %args) = @_; |
56
|
0
|
|
|
|
|
|
my $n = $self->{_socket}->syswrite($args{data}); |
57
|
0
|
|
|
|
|
|
return $n |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
# |
62
|
|
|
|
|
|
|
# connected() |
63
|
|
|
|
|
|
|
# --------- |
64
|
|
|
|
|
|
|
sub connected { |
65
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
66
|
0
|
0
|
|
|
|
|
return $self->{_socket}->connected ? 1 : 0 |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
1; |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
__END__ |