| 1 | # Copyrights 2011-2020 by [Mark Overmeer <markov@cpan.org>]. | ||||||||||||||||||||
| 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 | # This code is part of distribution IOMux. Meta-POD processed with OODoc | ||||||||||||||||||||
| 6 | # into POD and HTML manual-pages. See README.md | ||||||||||||||||||||
| 7 | # Copyright Mark Overmeer. Licensed under the same terms as Perl itself. | ||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | package IOMux::Service::TCP; | ||||||||||||||||||||
| 10 | 1 | ▶ | use vars '$VERSION'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | 1 | $VERSION = '1.01'; | |||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | 1 | ▶ | use base 'IOMux::Handler::Service'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | 1 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 16 | 1 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | 1 | ▶ | use Log::Report 'iomux'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 19 | 1 | ▶ | use IOMux::Net::TCP (); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | 1 | ▶ | use Socket 'SOCK_STREAM'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | sub init($) | ||||||||||||||||||||
| 25 | 0 | ▶ | { my ($self, $args) = @_; | ||||||||||||||||||
|
Subroutine
init: not called CC=8 SCAR=42.8
Pod
undocumented
| |||||||||||||||||||||
| 26 | |||||||||||||||||||||
| 27 | 0 | ▶ | $args->{Proto} ||= 'tcp'; | ||||||||||||||||||
|
Condition0%0/2
$args->{"Proto"} ||= "tcp"
MC/DC0%0/1
$args->{"Proto"} ||= "tcp"
$args->{"Proto"}
Truth table0%0/2
A
A= $args->{"Proto"}
| |||||||||||||||||||||
| 28 | 0 | ▶ | my $socket = delete $args->{socket} || $self->extractSocket($args); | ||||||||||||||||||
|
Condition0%0/3
delete $args->{'socket'} || $self->extractSocket($args)
MC/DC0%0/2
delete $args->{'socket'} || $self->extractSocket($args)
delete $args->{'socket'}
$self->extractSocket($args)
Truth table0%0/3
A || B
A= delete $args->{'socket'}B= $self->extractSocket($args)
| |||||||||||||||||||||
| 29 | 0 | ▶ | $socket->socktype eq SOCK_STREAM | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 30 | or error __x"{pkg} needs STREAM protocol socket", pkg => ref $self; | ||||||||||||||||||||
| 31 | 0 | $args->{fh} = $socket; | |||||||||||||||||||
| 32 | |||||||||||||||||||||
| 33 | 0 | my $sockaddr = $socket->sockhost.':'.$socket->sockport; | |||||||||||||||||||
| 34 | 0 | ▶ | $args->{name} ||= "listen tcp $sockaddr"; | ||||||||||||||||||
|
Condition0%0/2
$args->{"name"} ||= "listen tcp $sockaddr"
MC/DC0%0/1
$args->{"name"} ||= "listen tcp $sockaddr"
$args->{"name"}
Truth table0%0/2
A
A= $args->{"name"}
| |||||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | 0 | $self->SUPER::init($args); | |||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | my $ct = $self->{IMST_conn_type} = $args->{conn_type} | ||||||||||||||||||||
| 39 | 0 | ▶ | or error __x"a conn_type for incoming request is need by {name}" | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 40 | , name => $self->name; | ||||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | 0 | ▶ | $self->{IMST_conn_opts} = $args->{conn_opts} || []; | ||||||||||||||||||
|
Condition0%0/2
$args->{'conn_opts'} || []
MC/DC0%0/1
$args->{'conn_opts'} || []
$args->{'conn_opts'}
Truth table0%0/2
A
A= $args->{'conn_opts'}
| |||||||||||||||||||||
| 43 | 0 | ▶ | $self->{IMST_hostname} = $args->{hostname} || $sockaddr; | ||||||||||||||||||
|
Condition0%0/3
$args->{'hostname'} || $sockaddr
MC/DC0%0/2
$args->{'hostname'} || $sockaddr
$args->{'hostname'}
$sockaddr
Truth table0%0/3
A || B
A= $args->{'hostname'}B= $sockaddr
| |||||||||||||||||||||
| 44 | 0 | $self; | |||||||||||||||||||
| 45 | } | ||||||||||||||||||||
| 46 | |||||||||||||||||||||
| 47 | #------------------------ | ||||||||||||||||||||
| 48 | |||||||||||||||||||||
| 49 | 0 | ▶ | sub clientType() {shift->{IMST_conn_type}} | ||||||||||||||||||
|
Subroutine
clientType: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 50 | 0 | ▶ | sub socket() {shift->fh} | ||||||||||||||||||
|
Subroutine
socket: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 51 | 0 | ▶ | sub hostname() {shift->{IMST_hostname}} | ||||||||||||||||||
|
Subroutine
hostname: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | #------------------------- | ||||||||||||||||||||
| 54 | |||||||||||||||||||||
| 55 | # The read flag is set on the socket, which means that a new connection | ||||||||||||||||||||
| 56 | # attempt is made. | ||||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | sub muxReadFlagged() | ||||||||||||||||||||
| 60 | 0 | ▶ | { my $self = shift; | ||||||||||||||||||
|
Subroutine
muxReadFlagged: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||
| 61 | |||||||||||||||||||||
| 62 | 0 | my $client = $self->socket->accept; | |||||||||||||||||||
| 63 | 0 | ▶ | unless($client) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 64 | 0 | { alert __x"accept for socket {name} failed", name => $self->name; | |||||||||||||||||||
| 65 | 0 | return; | |||||||||||||||||||
| 66 | } | ||||||||||||||||||||
| 67 | |||||||||||||||||||||
| 68 | # create an object which handles this connection | ||||||||||||||||||||
| 69 | 0 | my $ct = $self->clientType; | |||||||||||||||||||
| 70 | 0 | my $opts = $self->{IMST_conn_opts}; | |||||||||||||||||||
| 71 | 0 | ▶ | my $handler = ref $ct eq 'CODE' | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 72 | ? $ct-> (socket => $client, Proto => 'tcp', @$opts) | ||||||||||||||||||||
| 73 | : $ct->new(socket => $client, Proto => 'tcp', @$opts); | ||||||||||||||||||||
| 74 | |||||||||||||||||||||
| 75 | # add the new socket to the mux, to be watched | ||||||||||||||||||||
| 76 | 0 | $self->mux->add($handler); | |||||||||||||||||||
| 77 | |||||||||||||||||||||
| 78 | 0 | $self->muxConnection($client); | |||||||||||||||||||
| 79 | } | ||||||||||||||||||||
| 80 | |||||||||||||||||||||
| 81 | 1 | 1; | |||||||||||||||||||