line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WWW::Slides::Controller::TCP; |
2
|
|
|
|
|
|
|
{ |
3
|
|
|
|
|
|
|
|
4
|
6
|
|
|
6
|
|
40241
|
use version; our $VERSION = qv('0.0.9'); |
|
6
|
|
|
|
|
11514
|
|
|
6
|
|
|
|
|
33
|
|
5
|
|
|
|
|
|
|
|
6
|
6
|
|
|
6
|
|
550
|
use warnings; |
|
6
|
|
|
|
|
11
|
|
|
6
|
|
|
|
|
180
|
|
7
|
6
|
|
|
6
|
|
35
|
use strict; |
|
6
|
|
|
|
|
17
|
|
|
6
|
|
|
|
|
154
|
|
8
|
6
|
|
|
6
|
|
31
|
use Carp; |
|
6
|
|
|
|
|
10
|
|
|
6
|
|
|
|
|
486
|
|
9
|
6
|
|
|
6
|
|
4360
|
use English qw( -no_match_vars ); |
|
6
|
|
|
|
|
14687
|
|
|
6
|
|
|
|
|
34
|
|
10
|
|
|
|
|
|
|
|
11
|
6
|
|
|
6
|
|
9633
|
use Object::InsideOut qw( WWW::Slides::Controller::Multiple ); |
|
6
|
|
|
|
|
386864
|
|
|
6
|
|
|
|
|
43
|
|
12
|
6
|
|
|
6
|
|
7172
|
use WWW::Slides::Controller::Single; |
|
6
|
|
|
|
|
18
|
|
|
6
|
|
|
|
|
55
|
|
13
|
6
|
|
|
6
|
|
1394
|
use IO::Socket; |
|
6
|
|
|
|
|
26205
|
|
|
6
|
|
|
|
|
708
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# Module implementation here |
16
|
|
|
|
|
|
|
my @port : Field # Port to listen to |
17
|
|
|
|
|
|
|
: Std(Name => 'port', Private => 1) : Get(Name => 'port') |
18
|
|
|
|
|
|
|
: Arg(Name => 'port', Mandatory => 1); |
19
|
|
|
|
|
|
|
my @door : Field # to accept connections |
20
|
|
|
|
|
|
|
: Std(Name => 'door', Private => 1); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub _init : Init { |
23
|
6
|
|
|
|
|
451
|
my $self = shift; |
24
|
6
|
100
|
|
|
|
153
|
my $sock = IO::Socket::INET->new( |
25
|
|
|
|
|
|
|
Proto => 'tcp', |
26
|
|
|
|
|
|
|
LocalPort => $self->port(), |
27
|
|
|
|
|
|
|
Listen => 3, |
28
|
|
|
|
|
|
|
ReuseAddr => 1, |
29
|
|
|
|
|
|
|
) or croak "cannot create socket: $OS_ERROR"; |
30
|
5
|
|
|
|
|
537
|
$self->set_door($sock); |
31
|
5
|
|
|
|
|
325
|
return; |
32
|
6
|
|
|
6
|
|
1531
|
} |
|
6
|
|
|
|
|
10
|
|
|
6
|
|
|
|
|
34
|
|
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub set_selector { |
35
|
2
|
|
|
2
|
1
|
1446
|
my $self = shift; |
36
|
2
|
|
|
|
|
4
|
my ($selector) = @_; |
37
|
2
|
|
|
|
|
58
|
$selector->add($self->get_door()); |
38
|
2
|
|
|
|
|
139
|
$self->SUPER::set_selector($selector); |
39
|
2
|
|
|
|
|
6
|
return; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub release_selector { |
43
|
2
|
|
|
2
|
1
|
3702
|
my $self = shift; |
44
|
2
|
|
|
|
|
22
|
$self->SUPER::release_selector(); |
45
|
2
|
|
|
|
|
48
|
$self->selector()->remove($self->get_door()); |
46
|
2
|
|
|
|
|
176
|
return; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub owns { |
50
|
2
|
|
|
2
|
1
|
1321
|
my $self = shift; |
51
|
2
|
|
|
|
|
4
|
my ($fh) = @_; |
52
|
2
|
|
66
|
|
|
64
|
return ($fh == $self->get_door()) || $self->SUPER::owns($fh); |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub execute_commands { # A command on the door is actually a connection |
56
|
5
|
|
|
5
|
1
|
7239
|
my $self = shift; |
57
|
5
|
|
|
|
|
12
|
my ($fh, $talk) = @_; |
58
|
5
|
100
|
|
|
|
151
|
if ($fh == $self->get_door()) { |
59
|
4
|
|
|
|
|
388
|
my $newcomer = $fh->accept(); |
60
|
4
|
|
|
|
|
381
|
$self->add(WWW::Slides::Controller::Single->new( |
61
|
|
|
|
|
|
|
in_handle => $newcomer, |
62
|
|
|
|
|
|
|
out_handle => $newcomer, |
63
|
|
|
|
|
|
|
)); |
64
|
4
|
|
|
|
|
22
|
return; |
65
|
|
|
|
|
|
|
} |
66
|
1
|
|
|
|
|
98
|
return $self->SUPER::execute_commands($fh, $talk); |
67
|
|
|
|
|
|
|
} ## end sub get_commands |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
1; # Magic true value required at end of module |
71
|
|
|
|
|
|
|
__END__ |