line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::Net::SSLeay::Socket; |
2
|
|
|
|
|
|
|
|
3
|
56
|
|
|
56
|
|
1241
|
use 5.008001; |
|
56
|
|
|
|
|
150
|
|
4
|
56
|
|
|
56
|
|
236
|
use strict; |
|
56
|
|
|
|
|
100
|
|
|
56
|
|
|
|
|
1026
|
|
5
|
56
|
|
|
56
|
|
289
|
use warnings; |
|
56
|
|
|
|
|
217
|
|
|
56
|
|
|
|
|
1465
|
|
6
|
|
|
|
|
|
|
|
7
|
56
|
|
|
56
|
|
255
|
use Carp qw(croak); |
|
56
|
|
|
|
|
87
|
|
|
56
|
|
|
|
|
3420
|
|
8
|
56
|
|
|
56
|
|
284
|
use English qw( $EVAL_ERROR $OS_ERROR $OUTPUT_AUTOFLUSH -no_match_vars ); |
|
56
|
|
|
|
|
85
|
|
|
56
|
|
|
|
|
402
|
|
9
|
56
|
|
|
56
|
|
7445
|
use Scalar::Util qw(refaddr reftype); |
|
56
|
|
|
|
|
138
|
|
|
56
|
|
|
|
|
2636
|
|
10
|
56
|
|
|
56
|
|
19735
|
use SelectSaver; |
|
56
|
|
|
|
|
64171
|
|
|
56
|
|
|
|
|
1597
|
|
11
|
56
|
|
|
|
|
45386
|
use Socket qw( |
12
|
|
|
|
|
|
|
AF_INET SOCK_DGRAM SOCK_STREAM |
13
|
|
|
|
|
|
|
inet_aton inet_ntoa pack_sockaddr_in unpack_sockaddr_in |
14
|
56
|
|
|
56
|
|
1861
|
); |
|
56
|
|
|
|
|
10751
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our $VERSION = '1.93_01'; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
my %PROTOS = ( |
19
|
|
|
|
|
|
|
tcp => SOCK_STREAM, |
20
|
|
|
|
|
|
|
udp => SOCK_DGRAM, |
21
|
|
|
|
|
|
|
); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub new { |
24
|
22
|
|
|
22
|
1
|
478
|
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
|
|
|
430
|
queue => delete $args{queue} || 5, |
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
31
|
|
|
|
|
|
|
}, $class; |
32
|
|
|
|
|
|
|
|
33
|
22
|
50
|
|
|
|
442
|
if ( !exists $PROTOS{ $self->{proto} } ) { |
34
|
0
|
|
|
|
|
0
|
croak "Unknown protocol '$self->{proto}'"; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
22
|
|
|
|
|
114
|
$self->_init_server(); |
38
|
|
|
|
|
|
|
|
39
|
22
|
|
|
|
|
76
|
return $self; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub _init_server { |
43
|
22
|
|
|
22
|
|
52
|
my ($self) = @_; |
44
|
|
|
|
|
|
|
|
45
|
22
|
0
|
|
|
|
36
|
my $addr = eval { inet_aton( $self->{addr} ) } |
|
22
|
50
|
|
|
|
388
|
|
46
|
|
|
|
|
|
|
or croak 'Could not pack IP address' |
47
|
|
|
|
|
|
|
. ( $EVAL_ERROR ? ": $EVAL_ERROR" : q{} ); |
48
|
|
|
|
|
|
|
|
49
|
22
|
0
|
|
|
|
48
|
my $sockaddr = eval { pack_sockaddr_in( $self->{port}, $addr ) } |
|
22
|
50
|
|
|
|
132
|
|
50
|
|
|
|
|
|
|
or croak 'Could not create sockaddr_in structure' |
51
|
|
|
|
|
|
|
. ( $EVAL_ERROR ? ": $EVAL_ERROR" : q{} ); |
52
|
|
|
|
|
|
|
|
53
|
22
|
50
|
|
|
|
1812
|
socket $self->{sock}, AF_INET, $PROTOS{ $self->{proto} }, 0 |
54
|
|
|
|
|
|
|
or croak "Could not open server socket: $OS_ERROR"; |
55
|
|
|
|
|
|
|
|
56
|
22
|
50
|
|
|
|
100
|
if ( $self->{proto} eq 'tcp' ) { |
57
|
22
|
50
|
|
|
|
614
|
bind $self->{sock}, $sockaddr |
58
|
|
|
|
|
|
|
or croak "Could not bind server socket: $OS_ERROR"; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
listen $self->{sock}, $self->{queue} |
61
|
22
|
50
|
|
|
|
384
|
or croak "Could not listen on server socket: $OS_ERROR"; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
22
|
|
|
|
|
230
|
my $sockname = getsockname $self->{sock}; |
65
|
22
|
|
|
|
|
172
|
( $self->{sport}, $self->{saddr} ) = unpack_sockaddr_in($sockname); |
66
|
22
|
|
|
|
|
308
|
$self->{saddr} = inet_ntoa( $self->{saddr} ); |
67
|
|
|
|
|
|
|
|
68
|
22
|
|
|
|
|
66
|
return 1; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub get_addr { |
72
|
2
|
|
|
2
|
1
|
3188
|
my ($self) = @_; |
73
|
|
|
|
|
|
|
|
74
|
2
|
|
|
|
|
54
|
return $self->{saddr}; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub get_port { |
78
|
2
|
|
|
2
|
1
|
15
|
my ($self) = @_; |
79
|
|
|
|
|
|
|
|
80
|
2
|
|
|
|
|
118
|
return $self->{sport}; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub accept { |
84
|
29
|
|
|
29
|
1
|
89320
|
my ( $self, $sock ) = @_; |
85
|
|
|
|
|
|
|
|
86
|
29
|
50
|
66
|
|
|
511
|
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
|
|
|
|
52320
|
or croak "Could not accept connection: $OS_ERROR"; |
92
|
|
|
|
|
|
|
|
93
|
29
|
|
|
|
|
552
|
my $saver = SelectSaver->new($sock); |
94
|
29
|
|
|
|
|
1545
|
local $OUTPUT_AUTOFLUSH = 1; |
95
|
|
|
|
|
|
|
|
96
|
29
|
|
|
|
|
426
|
return $sock; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub connect { |
100
|
29
|
|
|
29
|
1
|
57957
|
my ($self) = @_; |
101
|
|
|
|
|
|
|
|
102
|
29
|
0
|
|
|
|
183
|
my $addr = eval { inet_aton( $self->{saddr} ) } |
|
29
|
50
|
|
|
|
592
|
|
103
|
|
|
|
|
|
|
or croak 'Could not pack IP address in connect' |
104
|
|
|
|
|
|
|
. ( $EVAL_ERROR ? ": $EVAL_ERROR" : q{} ); |
105
|
|
|
|
|
|
|
|
106
|
29
|
0
|
|
|
|
86
|
my $sockaddr = eval { pack_sockaddr_in( $self->{sport}, $addr ) } |
|
29
|
50
|
|
|
|
328
|
|
107
|
|
|
|
|
|
|
or croak 'Could not create sockaddr_in structure in connect' |
108
|
|
|
|
|
|
|
. ( $EVAL_ERROR ? ": $EVAL_ERROR" : q{} ); |
109
|
|
|
|
|
|
|
|
110
|
29
|
50
|
|
|
|
1534
|
socket my $sock, AF_INET, $PROTOS{ $self->{proto} }, 0 |
111
|
|
|
|
|
|
|
or croak "Could not open server socket in connect: $OS_ERROR"; |
112
|
29
|
50
|
|
|
|
2639
|
connect $sock, $sockaddr |
113
|
|
|
|
|
|
|
or croak "Could not connect to server socket: $OS_ERROR"; |
114
|
|
|
|
|
|
|
|
115
|
29
|
|
|
|
|
721
|
my $saver = SelectSaver->new($sock); |
116
|
29
|
|
|
|
|
1441
|
local $OUTPUT_AUTOFLUSH = 1; |
117
|
|
|
|
|
|
|
|
118
|
29
|
|
|
|
|
331
|
return $sock; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub close { |
122
|
22
|
|
|
22
|
1
|
78566
|
my ($self) = @_; |
123
|
|
|
|
|
|
|
|
124
|
22
|
|
|
|
|
472
|
return close $self->{sock}; |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
1; |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
__END__ |