| 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
|
|
982
|
use warnings; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
29
|
|
|
6
|
1
|
|
|
1
|
|
5
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
31
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
package IOMux::Net::TCP; |
|
9
|
1
|
|
|
1
|
|
5
|
use vars '$VERSION'; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
46
|
|
|
10
|
|
|
|
|
|
|
$VERSION = '1.00'; |
|
11
|
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
5
|
use base 'IOMux::Handler::Read', 'IOMux::Handler::Write'; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
155
|
|
|
13
|
|
|
|
|
|
|
|
|
14
|
1
|
|
|
1
|
|
5
|
use Log::Report 'iomux'; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
13
|
|
|
15
|
1
|
|
|
1
|
|
243
|
use Socket 'SOCK_STREAM'; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
243
|
|
|
16
|
1
|
|
|
1
|
|
2363
|
use IO::Socket::INET; |
|
|
1
|
|
|
|
|
15889
|
|
|
|
1
|
|
|
|
|
10
|
|
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub init($) |
|
20
|
0
|
|
|
0
|
0
|
|
{ my ($self, $args) = @_; |
|
21
|
|
|
|
|
|
|
|
|
22
|
0
|
|
0
|
|
|
|
$args->{Proto} ||= 'tcp'; |
|
23
|
|
|
|
|
|
|
my $socket = $args->{fh} |
|
24
|
0
|
|
0
|
|
|
|
= (delete $args->{socket}) || $self->extractSocket($args); |
|
25
|
|
|
|
|
|
|
|
|
26
|
0
|
|
0
|
|
|
|
$args->{name} ||= "tcp ".$socket->peerhost.':'.$socket->peerport; |
|
27
|
0
|
|
|
|
|
|
warn "SOCKET=$socket $args->{name}"; |
|
28
|
|
|
|
|
|
|
|
|
29
|
0
|
|
|
|
|
|
$self->IOMux::Handler::Read::init($args); |
|
30
|
0
|
|
|
|
|
|
$self->IOMux::Handler::Write::init($args); |
|
31
|
|
|
|
|
|
|
|
|
32
|
0
|
|
|
|
|
|
$self; |
|
33
|
|
|
|
|
|
|
} |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
#------------------- |
|
36
|
|
|
|
|
|
|
|
|
37
|
0
|
|
|
0
|
1
|
|
sub socket() {shift->fh} |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
#------------------- |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub shutdown($) |
|
42
|
0
|
|
|
0
|
1
|
|
{ my($self, $which) = @_; |
|
43
|
0
|
|
|
|
|
|
my $socket = $self->socket; |
|
44
|
0
|
|
|
|
|
|
my $mux = $self->mux; |
|
45
|
|
|
|
|
|
|
|
|
46
|
0
|
0
|
|
|
|
|
if($which!=1) |
|
47
|
|
|
|
|
|
|
{ # Shutdown for reading. We can do this now. |
|
48
|
0
|
|
|
|
|
|
$socket->shutdown(0); |
|
49
|
0
|
|
|
|
|
|
$self->{IMNT_shutread} = 1; |
|
50
|
|
|
|
|
|
|
# The muxEOF hook must be run from the main loop to consume |
|
51
|
|
|
|
|
|
|
# the rest of the inbuffer if there is anything left. |
|
52
|
|
|
|
|
|
|
# It will also remove $fh from _readers. |
|
53
|
0
|
|
|
|
|
|
$self->fdset(0, 1, 0, 0); |
|
54
|
|
|
|
|
|
|
} |
|
55
|
0
|
0
|
|
|
|
|
if($which!=0) |
|
56
|
|
|
|
|
|
|
{ # Shutdown for writing. Only do this now if there is no pending data. |
|
57
|
0
|
|
|
|
|
|
$self->{IMNT_shutwrite} = 1; |
|
58
|
0
|
0
|
|
|
|
|
unless($self->muxOutputWaiting) |
|
59
|
0
|
|
|
|
|
|
{ $socket->shutdown(1); |
|
60
|
0
|
|
|
|
|
|
$self->fdset(0, 0, 1, 0); |
|
61
|
|
|
|
|
|
|
} |
|
62
|
|
|
|
|
|
|
} |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
$self->close |
|
65
|
|
|
|
|
|
|
if $self->{IMNT_shutread} |
|
66
|
0
|
0
|
0
|
|
|
|
&& $self->{IMNT_shutwrite} && !$self->muxOutputWaiting; |
|
|
|
|
0
|
|
|
|
|
|
67
|
|
|
|
|
|
|
} |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub close() |
|
70
|
0
|
|
|
0
|
1
|
|
{ my $self = shift; |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
warning __x"closing {name} with read buffer", name => $self->name |
|
73
|
0
|
0
|
|
|
|
|
if length $self->{ICMT_inbuf}; |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
warning __x"closing {name} with write buffer", name => $self->name |
|
76
|
0
|
0
|
|
|
|
|
if $self->{ICMT_outbuf}; |
|
77
|
|
|
|
|
|
|
|
|
78
|
0
|
|
|
|
|
|
$self->socket->close; |
|
79
|
0
|
|
|
|
|
|
$self->SUPER::close; |
|
80
|
|
|
|
|
|
|
} |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
#------------------------- |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub muxInit($) |
|
85
|
0
|
|
|
0
|
1
|
|
{ my ($self, $mux) = @_; |
|
86
|
0
|
|
|
|
|
|
$self->SUPER::muxInit($mux); |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
# we will not listen for write until we have something to write |
|
89
|
0
|
|
|
|
|
|
$self->fdset(1, 1, 0, 1); |
|
90
|
|
|
|
|
|
|
} |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub muxOutbufferEmpty() |
|
93
|
0
|
|
|
0
|
1
|
|
{ my $self = shift; |
|
94
|
0
|
|
|
|
|
|
$self->SUPER::muxOutbufferEmpty; |
|
95
|
|
|
|
|
|
|
|
|
96
|
0
|
0
|
0
|
|
|
|
if($self->{IMNT_shutwrite} && !$self->muxOutputWaiting) |
|
97
|
0
|
|
|
|
|
|
{ $self->socket->shutdown(1); |
|
98
|
0
|
|
|
|
|
|
$self->fdset(0, 0, 1, 0); |
|
99
|
0
|
0
|
|
|
|
|
$self->close if $self->{IMNT_shutread}; |
|
100
|
|
|
|
|
|
|
} |
|
101
|
|
|
|
|
|
|
} |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
1; |