line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Copyrights 2011 by Mark Overmeer. |
2
|
|
|
|
|
|
|
# For other contributors see ChangeLog. |
3
|
|
|
|
|
|
|
# See the manual pages for details on the licensing terms. |
4
|
|
|
|
|
|
|
# Pod stripped from pm file by OODoc 1.07. |
5
|
1
|
|
|
1
|
|
1503
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
36
|
|
6
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
49
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
package IOMux::Service::TCP; |
9
|
1
|
|
|
1
|
|
5
|
use vars '$VERSION'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
53
|
|
10
|
|
|
|
|
|
|
$VERSION = '0.12'; |
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
6
|
use base 'IOMux::Handler::Service'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
105
|
|
13
|
|
|
|
|
|
|
|
14
|
1
|
|
|
1
|
|
7
|
use Log::Report 'iomux'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
9
|
|
15
|
1
|
|
|
1
|
|
307
|
use IOMux::Net::TCP (); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
22
|
|
16
|
|
|
|
|
|
|
|
17
|
1
|
|
|
1
|
|
6
|
use Socket 'SOCK_STREAM'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
425
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub init($) |
21
|
0
|
|
|
0
|
0
|
|
{ my ($self, $args) = @_; |
22
|
|
|
|
|
|
|
|
23
|
0
|
|
0
|
|
|
|
my $socket = $args->{fh} |
24
|
|
|
|
|
|
|
= (delete $args->{socket}) || $self->extractSocket($args); |
25
|
|
|
|
|
|
|
|
26
|
0
|
|
|
|
|
|
my $proto = $socket->socktype; |
27
|
0
|
0
|
|
|
|
|
$proto eq SOCK_STREAM |
28
|
|
|
|
|
|
|
or error __x"{pkg} needs STREAM protocol socket", pkg => ref $self; |
29
|
|
|
|
|
|
|
|
30
|
0
|
|
0
|
|
|
|
$args->{name} ||= "listen tcp ".$socket->sockhost.':'.$socket->sockport; |
31
|
|
|
|
|
|
|
|
32
|
0
|
|
|
|
|
|
$self->SUPER::init($args); |
33
|
|
|
|
|
|
|
|
34
|
0
|
0
|
|
|
|
|
my $ct = $self->{IMST_conn_type} = $args->{conn_type} |
35
|
|
|
|
|
|
|
or error __x"a conn_type for incoming request is need by {name}" |
36
|
|
|
|
|
|
|
, name => $self->name; |
37
|
|
|
|
|
|
|
|
38
|
0
|
|
0
|
|
|
|
$self->{IMST_conn_opts} = $args->{conn_opts} || []; |
39
|
0
|
|
|
|
|
|
$self; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
#------------------------ |
43
|
|
|
|
|
|
|
|
44
|
0
|
|
|
0
|
1
|
|
sub clientType() {shift->{IMST_conn_type}} |
45
|
0
|
|
|
0
|
1
|
|
sub socket() {shift->fh} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
#------------------------- |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
# The read flag is set on the socket, which means that a new connection |
50
|
|
|
|
|
|
|
# attempt is made. |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub mux_read_flagged() |
53
|
0
|
|
|
0
|
1
|
|
{ my $self = shift; |
54
|
|
|
|
|
|
|
|
55
|
0
|
0
|
|
|
|
|
if(my $client = $self->socket->accept) |
56
|
0
|
|
|
|
|
|
{ my $ct = $self->{IMST_conn_type}; |
57
|
0
|
|
|
|
|
|
my $handler = ref $ct eq 'CODE' |
58
|
0
|
|
|
|
|
|
? $ct->(socket => $client, @{$self->{IMST_conn_opts}}) |
59
|
0
|
0
|
|
|
|
|
: $ct->new(socket => $client, @{$self->{IMST_conn_opts}}); |
60
|
0
|
|
|
|
|
|
$self->mux->add($handler); |
61
|
0
|
|
|
|
|
|
$self->mux_connection($client); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
else |
64
|
0
|
|
|
|
|
|
{ alert "accept for {name} failed", name => $self->name; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
1; |