line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::Net::SSLeay::Socket; |
2
|
|
|
|
|
|
|
|
3
|
56
|
|
|
56
|
|
1522
|
use 5.008001; |
|
56
|
|
|
|
|
196
|
|
4
|
56
|
|
|
56
|
|
363
|
use strict; |
|
56
|
|
|
|
|
134
|
|
|
56
|
|
|
|
|
1238
|
|
5
|
56
|
|
|
56
|
|
328
|
use warnings; |
|
56
|
|
|
|
|
140
|
|
|
56
|
|
|
|
|
1648
|
|
6
|
|
|
|
|
|
|
|
7
|
56
|
|
|
56
|
|
335
|
use Carp qw(croak); |
|
56
|
|
|
|
|
103
|
|
|
56
|
|
|
|
|
3259
|
|
8
|
56
|
|
|
56
|
|
374
|
use English qw( $EVAL_ERROR $OS_ERROR $OUTPUT_AUTOFLUSH -no_match_vars ); |
|
56
|
|
|
|
|
121
|
|
|
56
|
|
|
|
|
479
|
|
9
|
56
|
|
|
56
|
|
9491
|
use Scalar::Util qw(refaddr reftype); |
|
56
|
|
|
|
|
159
|
|
|
56
|
|
|
|
|
3313
|
|
10
|
56
|
|
|
56
|
|
25161
|
use SelectSaver; |
|
56
|
|
|
|
|
85110
|
|
|
56
|
|
|
|
|
2074
|
|
11
|
56
|
|
|
|
|
58691
|
use Socket qw( |
12
|
|
|
|
|
|
|
AF_INET SOCK_DGRAM SOCK_STREAM |
13
|
|
|
|
|
|
|
inet_aton inet_ntoa pack_sockaddr_in unpack_sockaddr_in |
14
|
56
|
|
|
56
|
|
2528
|
); |
|
56
|
|
|
|
|
14875
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our $VERSION = '1.93_02'; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
my %PROTOS = ( |
19
|
|
|
|
|
|
|
tcp => SOCK_STREAM, |
20
|
|
|
|
|
|
|
udp => SOCK_DGRAM, |
21
|
|
|
|
|
|
|
); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub new { |
24
|
22
|
|
|
22
|
1
|
424
|
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
|
|
|
528
|
queue => delete $args{queue} || 5, |
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
31
|
|
|
|
|
|
|
}, $class; |
32
|
|
|
|
|
|
|
|
33
|
22
|
50
|
|
|
|
396
|
if ( !exists $PROTOS{ $self->{proto} } ) { |
34
|
0
|
|
|
|
|
0
|
croak "Unknown protocol '$self->{proto}'"; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
22
|
|
|
|
|
114
|
$self->_init_server(); |
38
|
|
|
|
|
|
|
|
39
|
22
|
|
|
|
|
86
|
return $self; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub _init_server { |
43
|
22
|
|
|
22
|
|
76
|
my ($self) = @_; |
44
|
|
|
|
|
|
|
|
45
|
22
|
0
|
|
|
|
42
|
my $addr = eval { inet_aton( $self->{addr} ) } |
|
22
|
50
|
|
|
|
406
|
|
46
|
|
|
|
|
|
|
or croak 'Could not pack IP address' |
47
|
|
|
|
|
|
|
. ( $EVAL_ERROR ? ": $EVAL_ERROR" : q{} ); |
48
|
|
|
|
|
|
|
|
49
|
22
|
0
|
|
|
|
64
|
my $sockaddr = eval { pack_sockaddr_in( $self->{port}, $addr ) } |
|
22
|
50
|
|
|
|
152
|
|
50
|
|
|
|
|
|
|
or croak 'Could not create sockaddr_in structure' |
51
|
|
|
|
|
|
|
. ( $EVAL_ERROR ? ": $EVAL_ERROR" : q{} ); |
52
|
|
|
|
|
|
|
|
53
|
22
|
50
|
|
|
|
1528
|
socket $self->{sock}, AF_INET, $PROTOS{ $self->{proto} }, 0 |
54
|
|
|
|
|
|
|
or croak "Could not open server socket: $OS_ERROR"; |
55
|
|
|
|
|
|
|
|
56
|
22
|
50
|
|
|
|
164
|
if ( $self->{proto} eq 'tcp' ) { |
57
|
22
|
50
|
|
|
|
562
|
bind $self->{sock}, $sockaddr |
58
|
|
|
|
|
|
|
or croak "Could not bind server socket: $OS_ERROR"; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
listen $self->{sock}, $self->{queue} |
61
|
22
|
50
|
|
|
|
480
|
or croak "Could not listen on server socket: $OS_ERROR"; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
22
|
|
|
|
|
312
|
my $sockname = getsockname $self->{sock}; |
65
|
22
|
|
|
|
|
244
|
( $self->{sport}, $self->{saddr} ) = unpack_sockaddr_in($sockname); |
66
|
22
|
|
|
|
|
234
|
$self->{saddr} = inet_ntoa( $self->{saddr} ); |
67
|
|
|
|
|
|
|
|
68
|
22
|
|
|
|
|
62
|
return 1; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub get_addr { |
72
|
2
|
|
|
2
|
1
|
3314
|
my ($self) = @_; |
73
|
|
|
|
|
|
|
|
74
|
2
|
|
|
|
|
113
|
return $self->{saddr}; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub get_port { |
78
|
2
|
|
|
2
|
1
|
32
|
my ($self) = @_; |
79
|
|
|
|
|
|
|
|
80
|
2
|
|
|
|
|
145
|
return $self->{sport}; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub accept { |
84
|
29
|
|
|
29
|
1
|
72502
|
my ( $self, $sock ) = @_; |
85
|
|
|
|
|
|
|
|
86
|
29
|
50
|
66
|
|
|
556
|
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
|
|
|
|
48984
|
or croak "Could not accept connection: $OS_ERROR"; |
92
|
|
|
|
|
|
|
|
93
|
29
|
|
|
|
|
723
|
my $saver = SelectSaver->new($sock); |
94
|
29
|
|
|
|
|
1863
|
local $OUTPUT_AUTOFLUSH = 1; |
95
|
|
|
|
|
|
|
|
96
|
29
|
|
|
|
|
526
|
return $sock; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub connect { |
100
|
29
|
|
|
29
|
1
|
44078
|
my ($self) = @_; |
101
|
|
|
|
|
|
|
|
102
|
29
|
0
|
|
|
|
264
|
my $addr = eval { inet_aton( $self->{saddr} ) } |
|
29
|
50
|
|
|
|
597
|
|
103
|
|
|
|
|
|
|
or croak 'Could not pack IP address in connect' |
104
|
|
|
|
|
|
|
. ( $EVAL_ERROR ? ": $EVAL_ERROR" : q{} ); |
105
|
|
|
|
|
|
|
|
106
|
29
|
0
|
|
|
|
136
|
my $sockaddr = eval { pack_sockaddr_in( $self->{sport}, $addr ) } |
|
29
|
50
|
|
|
|
397
|
|
107
|
|
|
|
|
|
|
or croak 'Could not create sockaddr_in structure in connect' |
108
|
|
|
|
|
|
|
. ( $EVAL_ERROR ? ": $EVAL_ERROR" : q{} ); |
109
|
|
|
|
|
|
|
|
110
|
29
|
50
|
|
|
|
1852
|
socket my $sock, AF_INET, $PROTOS{ $self->{proto} }, 0 |
111
|
|
|
|
|
|
|
or croak "Could not open server socket in connect: $OS_ERROR"; |
112
|
29
|
50
|
|
|
|
2741
|
connect $sock, $sockaddr |
113
|
|
|
|
|
|
|
or croak "Could not connect to server socket: $OS_ERROR"; |
114
|
|
|
|
|
|
|
|
115
|
29
|
|
|
|
|
596
|
my $saver = SelectSaver->new($sock); |
116
|
29
|
|
|
|
|
1800
|
local $OUTPUT_AUTOFLUSH = 1; |
117
|
|
|
|
|
|
|
|
118
|
29
|
|
|
|
|
363
|
return $sock; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub close { |
122
|
22
|
|
|
22
|
1
|
78370
|
my ($self) = @_; |
123
|
|
|
|
|
|
|
|
124
|
22
|
|
|
|
|
529
|
return close $self->{sock}; |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
1; |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
__END__ |