line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
3
|
|
|
3
|
|
4252
|
use utf8; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
19
|
|
2
|
3
|
|
|
3
|
|
104
|
use strict; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
73
|
|
3
|
3
|
|
|
3
|
|
18
|
use warnings; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
123
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package DR::Tnt::LowLevel::Connector::Sync; |
6
|
3
|
|
|
3
|
|
17
|
use Mouse; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
14
|
|
7
|
3
|
|
|
3
|
|
2829
|
use IO::Socket::INET; |
|
3
|
|
|
|
|
73647
|
|
|
3
|
|
|
|
|
22
|
|
8
|
3
|
|
|
3
|
|
1878
|
use IO::Socket::UNIX; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
31
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
extends 'DR::Tnt::LowLevel::Connector'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub _connect { |
13
|
0
|
|
|
0
|
|
|
my ($self, $cb) = @_; |
14
|
|
|
|
|
|
|
|
15
|
0
|
|
|
|
|
|
my $fh; |
16
|
0
|
0
|
0
|
|
|
|
if ($self->host eq 'unix' or $self->host eq 'unix/') { |
17
|
0
|
|
|
|
|
|
$fh = IO::Socket::UNIX->new( |
18
|
|
|
|
|
|
|
Type => SOCK_STREAM, |
19
|
|
|
|
|
|
|
Peer => $self->port, |
20
|
|
|
|
|
|
|
); |
21
|
|
|
|
|
|
|
} else { |
22
|
0
|
|
|
|
|
|
$fh = IO::Socket::INET->new( |
23
|
|
|
|
|
|
|
PeerHost => $self->host, |
24
|
|
|
|
|
|
|
PeerPort => $self->port, |
25
|
|
|
|
|
|
|
Proto => 'tcp', |
26
|
|
|
|
|
|
|
); |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
0
|
0
|
|
|
|
|
unless ($fh) { |
30
|
0
|
|
|
|
|
|
$cb->(ER_SOCKET => $!); |
31
|
0
|
|
|
|
|
|
return; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
0
|
|
|
|
|
|
$self->_set_fh($fh); |
35
|
0
|
|
|
|
|
|
$cb->(OK => 'Socket connected'); |
36
|
|
|
|
|
|
|
|
37
|
0
|
|
|
|
|
|
return; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub _handshake { |
41
|
0
|
|
|
0
|
|
|
my ($self, $cb) = @_; |
42
|
|
|
|
|
|
|
$self->sread(128, sub { |
43
|
0
|
|
|
0
|
|
|
my ($state, $message, $hs) = @_; |
44
|
0
|
0
|
|
|
|
|
unless ($state eq 'OK') { |
45
|
0
|
|
|
|
|
|
pop; |
46
|
0
|
|
|
|
|
|
goto \&$cb; |
47
|
|
|
|
|
|
|
} |
48
|
0
|
|
|
|
|
|
$cb->(OK => 'handshake was read', $hs); |
49
|
0
|
|
|
|
|
|
}); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub send_pkt { |
53
|
0
|
|
|
0
|
0
|
|
my ($self, $pkt, $cb) = @_; |
54
|
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
|
while (1) { |
56
|
0
|
|
|
|
|
|
my $done = syswrite $self->fh, $pkt; |
57
|
0
|
0
|
|
|
|
|
unless (defined $done) { |
58
|
0
|
|
|
|
|
|
$cb->(ER_SOCKET => $!); |
59
|
0
|
|
|
|
|
|
return; |
60
|
|
|
|
|
|
|
} |
61
|
0
|
0
|
|
|
|
|
if ($done == length $pkt) { |
62
|
0
|
|
|
|
|
|
$cb->(OK => 'swrite done'); |
63
|
0
|
|
|
|
|
|
return; |
64
|
|
|
|
|
|
|
} |
65
|
0
|
0
|
|
|
|
|
substr $pkt, 0, $done, '' if $done; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub _wait_something { |
70
|
0
|
|
|
0
|
|
|
my ($self) = @_; |
71
|
0
|
0
|
|
|
|
|
return unless $self->fh; |
72
|
|
|
|
|
|
|
|
73
|
0
|
|
|
|
|
|
do { |
74
|
0
|
|
|
|
|
|
my $blob = ''; |
75
|
0
|
|
|
|
|
|
my $done = sysread $self->fh, $blob, 4096; |
76
|
|
|
|
|
|
|
|
77
|
0
|
0
|
|
|
|
|
unless ($done) { |
78
|
0
|
0
|
|
|
|
|
unless (defined $done) { |
79
|
0
|
|
0
|
|
|
|
$self->socket_error($! // 'Connection lost'); |
80
|
0
|
|
|
|
|
|
return; |
81
|
|
|
|
|
|
|
} |
82
|
0
|
|
|
|
|
|
$self->socket_error('Remote host closed connection'); |
83
|
0
|
|
|
|
|
|
return; |
84
|
|
|
|
|
|
|
} |
85
|
0
|
|
|
|
|
|
$self->rbuf($self->rbuf . $blob); |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
} until $self->check_rbuf; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
after handshake => sub { |
91
|
|
|
|
|
|
|
my ($self) = @_; |
92
|
|
|
|
|
|
|
$self->_wait_something; |
93
|
|
|
|
|
|
|
}; |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
after wait_response => sub { |
96
|
|
|
|
|
|
|
my ($self) = @_; |
97
|
|
|
|
|
|
|
$self->_wait_something; |
98
|
|
|
|
|
|
|
}; |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |