line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Copyrights 2011-2015 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 2.02. |
5
|
1
|
|
|
1
|
|
1370
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
36
|
|
6
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
37
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
package IOMux::Service::TCP; |
9
|
1
|
|
|
1
|
|
5
|
use vars '$VERSION'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
56
|
|
10
|
|
|
|
|
|
|
$VERSION = '1.00'; |
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
6
|
use base 'IOMux::Handler::Service'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
89
|
|
13
|
|
|
|
|
|
|
|
14
|
1
|
|
|
1
|
|
6
|
use Log::Report 'iomux'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
10
|
|
15
|
1
|
|
|
1
|
|
287
|
use IOMux::Net::TCP (); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
18
|
|
16
|
|
|
|
|
|
|
|
17
|
1
|
|
|
1
|
|
5
|
use Socket 'SOCK_STREAM'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
429
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub init($) |
21
|
0
|
|
|
0
|
0
|
|
{ my ($self, $args) = @_; |
22
|
|
|
|
|
|
|
|
23
|
0
|
|
0
|
|
|
|
$args->{Proto} ||= 'tcp'; |
24
|
|
|
|
|
|
|
my $socket = $args->{fh} |
25
|
0
|
|
0
|
|
|
|
= (delete $args->{socket}) || $self->extractSocket($args); |
26
|
|
|
|
|
|
|
|
27
|
0
|
|
|
|
|
|
my $proto = $socket->socktype; |
28
|
0
|
0
|
|
|
|
|
$proto eq SOCK_STREAM |
29
|
|
|
|
|
|
|
or error __x"{pkg} needs STREAM protocol socket", pkg => ref $self; |
30
|
|
|
|
|
|
|
|
31
|
0
|
|
0
|
|
|
|
$args->{name} ||= "listen tcp ".$socket->sockhost.':'.$socket->sockport; |
32
|
|
|
|
|
|
|
|
33
|
0
|
|
|
|
|
|
$self->SUPER::init($args); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
my $ct = $self->{IMST_conn_type} = $args->{conn_type} |
36
|
0
|
0
|
|
|
|
|
or error __x"a conn_type for incoming request is need by {name}" |
37
|
|
|
|
|
|
|
, name => $self->name; |
38
|
|
|
|
|
|
|
|
39
|
0
|
|
0
|
|
|
|
$self->{IMST_conn_opts} = $args->{conn_opts} || []; |
40
|
0
|
|
|
|
|
|
$self; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
#------------------------ |
44
|
|
|
|
|
|
|
|
45
|
0
|
|
|
0
|
1
|
|
sub clientType() {shift->{IMST_conn_type}} |
46
|
0
|
|
|
0
|
1
|
|
sub socket() {shift->fh} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
#------------------------- |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
# The read flag is set on the socket, which means that a new connection |
51
|
|
|
|
|
|
|
# attempt is made. |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub muxReadFlagged() |
54
|
0
|
|
|
0
|
1
|
|
{ my $self = shift; |
55
|
|
|
|
|
|
|
|
56
|
0
|
|
|
|
|
|
my $client = $self->socket->accept; |
57
|
0
|
0
|
|
|
|
|
unless($client) |
58
|
0
|
|
|
|
|
|
{ alert __x"accept for {name} failed", name => $self->name; |
59
|
0
|
|
|
|
|
|
return; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
# create an object which handles this connection |
63
|
0
|
|
|
|
|
|
my $ct = $self->{IMST_conn_type}; |
64
|
0
|
|
|
|
|
|
my $opts = $self->{IMST_conn_opts}; |
65
|
0
|
0
|
|
|
|
|
my $handler = ref $ct eq 'CODE' |
66
|
|
|
|
|
|
|
? $ct->( socket => $client, Proto => 'tcp', @$opts) |
67
|
|
|
|
|
|
|
: $ct->new(socket => $client, Proto => 'tcp', @$opts); |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
# add the new socket to the mux, to be watched |
70
|
0
|
|
|
|
|
|
$self->mux->add($handler); |
71
|
|
|
|
|
|
|
|
72
|
0
|
|
|
|
|
|
$self->muxConnection($client); |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
1; |