line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::Net::SSLeay::Socket; |
2
|
|
|
|
|
|
|
|
3
|
56
|
|
|
56
|
|
1701
|
use 5.008001; |
|
56
|
|
|
|
|
204
|
|
4
|
56
|
|
|
56
|
|
400
|
use strict; |
|
56
|
|
|
|
|
128
|
|
|
56
|
|
|
|
|
1426
|
|
5
|
56
|
|
|
56
|
|
295
|
use warnings; |
|
56
|
|
|
|
|
165
|
|
|
56
|
|
|
|
|
2130
|
|
6
|
|
|
|
|
|
|
|
7
|
56
|
|
|
56
|
|
348
|
use Carp qw(croak); |
|
56
|
|
|
|
|
134
|
|
|
56
|
|
|
|
|
3857
|
|
8
|
56
|
|
|
56
|
|
422
|
use English qw( $EVAL_ERROR $OS_ERROR $OUTPUT_AUTOFLUSH -no_match_vars ); |
|
56
|
|
|
|
|
162
|
|
|
56
|
|
|
|
|
493
|
|
9
|
56
|
|
|
56
|
|
9650
|
use Scalar::Util qw(refaddr reftype); |
|
56
|
|
|
|
|
152
|
|
|
56
|
|
|
|
|
3180
|
|
10
|
56
|
|
|
56
|
|
26944
|
use SelectSaver; |
|
56
|
|
|
|
|
87016
|
|
|
56
|
|
|
|
|
2333
|
|
11
|
56
|
|
|
|
|
58659
|
use Socket qw( |
12
|
|
|
|
|
|
|
AF_INET SOCK_DGRAM SOCK_STREAM |
13
|
|
|
|
|
|
|
inet_aton inet_ntoa pack_sockaddr_in unpack_sockaddr_in |
14
|
56
|
|
|
56
|
|
2626
|
); |
|
56
|
|
|
|
|
15214
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our $VERSION = '1.92'; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
my %PROTOS = ( |
19
|
|
|
|
|
|
|
tcp => SOCK_STREAM, |
20
|
|
|
|
|
|
|
udp => SOCK_DGRAM, |
21
|
|
|
|
|
|
|
); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub new { |
24
|
22
|
|
|
22
|
1
|
456
|
my ( $class, %args ) = @_; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
my $self = bless { |
27
|
|
|
|
|
|
|
addr => delete $args{addr} || '127.0.0.1', |
28
|
|
|
|
|
|
|
port => delete $args{port} || 0, |
29
|
|
|
|
|
|
|
proto => delete $args{proto} || 'tcp', |
30
|
22
|
|
50
|
|
|
572
|
queue => delete $args{queue} || 5, |
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
31
|
|
|
|
|
|
|
}, $class; |
32
|
|
|
|
|
|
|
|
33
|
22
|
50
|
|
|
|
548
|
if ( !exists $PROTOS{ $self->{proto} } ) { |
34
|
0
|
|
|
|
|
0
|
croak "Unknown protocol '$self->{proto}'"; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
22
|
|
|
|
|
154
|
$self->_init_server(); |
38
|
|
|
|
|
|
|
|
39
|
22
|
|
|
|
|
100
|
return $self; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub _init_server { |
43
|
22
|
|
|
22
|
|
64
|
my ($self) = @_; |
44
|
|
|
|
|
|
|
|
45
|
22
|
0
|
|
|
|
66
|
my $addr = eval { inet_aton( $self->{addr} ) } |
|
22
|
50
|
|
|
|
424
|
|
46
|
|
|
|
|
|
|
or croak 'Could not pack IP address' |
47
|
|
|
|
|
|
|
. ( $EVAL_ERROR ? ": $EVAL_ERROR" : q{} ); |
48
|
|
|
|
|
|
|
|
49
|
22
|
0
|
|
|
|
68
|
my $sockaddr = eval { pack_sockaddr_in( $self->{port}, $addr ) } |
|
22
|
50
|
|
|
|
154
|
|
50
|
|
|
|
|
|
|
or croak 'Could not create sockaddr_in structure' |
51
|
|
|
|
|
|
|
. ( $EVAL_ERROR ? ": $EVAL_ERROR" : q{} ); |
52
|
|
|
|
|
|
|
|
53
|
22
|
50
|
|
|
|
1434
|
socket $self->{sock}, AF_INET, $PROTOS{ $self->{proto} }, 0 |
54
|
|
|
|
|
|
|
or croak "Could not open server socket: $OS_ERROR"; |
55
|
|
|
|
|
|
|
|
56
|
22
|
50
|
|
|
|
132
|
if ( $self->{proto} eq 'tcp' ) { |
57
|
22
|
50
|
|
|
|
498
|
bind $self->{sock}, $sockaddr |
58
|
|
|
|
|
|
|
or croak "Could not bind server socket: $OS_ERROR"; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
listen $self->{sock}, $self->{queue} |
61
|
22
|
50
|
|
|
|
474
|
or croak "Could not listen on server socket: $OS_ERROR"; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
22
|
|
|
|
|
328
|
my $sockname = getsockname $self->{sock}; |
65
|
22
|
|
|
|
|
210
|
( $self->{sport}, $self->{saddr} ) = unpack_sockaddr_in($sockname); |
66
|
22
|
|
|
|
|
220
|
$self->{saddr} = inet_ntoa( $self->{saddr} ); |
67
|
|
|
|
|
|
|
|
68
|
22
|
|
|
|
|
64
|
return 1; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub get_addr { |
72
|
2
|
|
|
2
|
1
|
4099
|
my ($self) = @_; |
73
|
|
|
|
|
|
|
|
74
|
2
|
|
|
|
|
66
|
return $self->{saddr}; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub get_port { |
78
|
2
|
|
|
2
|
1
|
34
|
my ($self) = @_; |
79
|
|
|
|
|
|
|
|
80
|
2
|
|
|
|
|
168
|
return $self->{sport}; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub accept { |
84
|
29
|
|
|
29
|
1
|
78860
|
my ( $self, $sock ) = @_; |
85
|
|
|
|
|
|
|
|
86
|
29
|
50
|
66
|
|
|
509
|
if ( defined $sock && reftype($sock) ne 'GLOB' ) { |
87
|
0
|
|
|
|
|
0
|
croak 'Argument #1 to accept() must be a typeglob reference'; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
accept $sock, $self->{sock} |
91
|
29
|
50
|
|
|
|
51507
|
or croak "Could not accept connection: $OS_ERROR"; |
92
|
|
|
|
|
|
|
|
93
|
29
|
|
|
|
|
853
|
my $saver = SelectSaver->new($sock); |
94
|
29
|
|
|
|
|
2024
|
local $OUTPUT_AUTOFLUSH = 1; |
95
|
|
|
|
|
|
|
|
96
|
29
|
|
|
|
|
511
|
return $sock; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub connect { |
100
|
29
|
|
|
29
|
1
|
48916
|
my ($self) = @_; |
101
|
|
|
|
|
|
|
|
102
|
29
|
0
|
|
|
|
287
|
my $addr = eval { inet_aton( $self->{saddr} ) } |
|
29
|
50
|
|
|
|
728
|
|
103
|
|
|
|
|
|
|
or croak 'Could not pack IP address' |
104
|
|
|
|
|
|
|
. ( $EVAL_ERROR ? ": $EVAL_ERROR" : q{} ); |
105
|
|
|
|
|
|
|
|
106
|
29
|
0
|
|
|
|
123
|
my $sockaddr = eval { pack_sockaddr_in( $self->{sport}, $addr ) } |
|
29
|
50
|
|
|
|
456
|
|
107
|
|
|
|
|
|
|
or croak 'Could not create sockaddr_in structure' |
108
|
|
|
|
|
|
|
. ( $EVAL_ERROR ? ": $EVAL_ERROR" : q{} ); |
109
|
|
|
|
|
|
|
|
110
|
29
|
50
|
|
|
|
2098
|
socket my $sock, AF_INET, $PROTOS{ $self->{proto} }, 0 |
111
|
|
|
|
|
|
|
or croak "Could not open server socket: $OS_ERROR"; |
112
|
29
|
50
|
|
|
|
3068
|
connect $sock, $sockaddr |
113
|
|
|
|
|
|
|
or croak "Could not connect to server socket: $OS_ERROR"; |
114
|
|
|
|
|
|
|
|
115
|
29
|
|
|
|
|
680
|
my $saver = SelectSaver->new($sock); |
116
|
29
|
|
|
|
|
1714
|
local $OUTPUT_AUTOFLUSH = 1; |
117
|
|
|
|
|
|
|
|
118
|
29
|
|
|
|
|
396
|
return $sock; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub close { |
122
|
22
|
|
|
22
|
1
|
86814
|
my ($self) = @_; |
123
|
|
|
|
|
|
|
|
124
|
22
|
|
|
|
|
600
|
return close $self->{sock}; |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
1; |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
__END__ |