line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package POE::Component::Server::JSONRPC::Tcp; |
2
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
39
|
|
3
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
29
|
|
4
|
1
|
|
|
1
|
|
5
|
use base qw(POE::Component::Server::JSONRPC); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
125
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
|
|
5
|
use POE qw/ |
9
|
|
|
|
|
|
|
Component::Server::TCP |
10
|
|
|
|
|
|
|
Filter::Line |
11
|
1
|
|
|
1
|
|
6
|
/; |
|
1
|
|
|
|
|
2
|
|
12
|
1
|
|
|
1
|
|
27883
|
use JSON::Any; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 NAME |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
POE::Component::Server::JSONRPC::Tcp - POE tcp based JSON-RPC server |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head2 new |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
constructor |
21
|
|
|
|
|
|
|
=cut |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub new { |
24
|
|
|
|
|
|
|
my $self = shift->SUPER::new( @_ > 1 ? {@_} : $_[0] ); |
25
|
|
|
|
|
|
|
return $self; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=head2 poe_init_server |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
Init TCP Server. |
31
|
|
|
|
|
|
|
=cut |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub poe_init_server { |
34
|
|
|
|
|
|
|
my ($self, $kernel, $session, $heap) = @_[OBJECT, KERNEL, SESSION, HEAP]; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
my $bind = sub { |
37
|
|
|
|
|
|
|
my $method = $_[0]; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
return sub { |
40
|
|
|
|
|
|
|
my ($kernel, $tcp_session, @args) = @_[KERNEL, SESSION, ARG0..$#_ ]; |
41
|
|
|
|
|
|
|
#~ $kernel->post( $session->ID, $method, $tcp_session->ID, @args ); |
42
|
|
|
|
|
|
|
$kernel->post( $session->ID, $method, {content=>$args[0]},$tcp_session->ID, "" ); |
43
|
|
|
|
|
|
|
}; |
44
|
|
|
|
|
|
|
}; |
45
|
|
|
|
|
|
|
$self->{tcp} = POE::Component::Server::TCP->new( |
46
|
|
|
|
|
|
|
Port => $self->{Port}, |
47
|
|
|
|
|
|
|
$self->{Address} ? ( Address => $self->{Address} ) : (), |
48
|
|
|
|
|
|
|
$self->{Hostname} ? ( Hostname => $self->{Hostname} ) : (), |
49
|
|
|
|
|
|
|
$self->{Domain} ? ( Domain => $self->{Domain} ) : (), |
50
|
|
|
|
|
|
|
$self->{Concurrency} ? ( Concurrency => $self->{Concurrency} ) : (), |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
ClientInput => $bind->('input_handler'), |
53
|
|
|
|
|
|
|
# ClientConnected => $bind->('tcp_connect_handler'), |
54
|
|
|
|
|
|
|
# ClientDisconnected => $bind->('tcp_disconnect_handler'), |
55
|
|
|
|
|
|
|
# ClientError => $bind->('tcp_client_error_handler'), |
56
|
|
|
|
|
|
|
# ClientFlushed => $bind->('tcp_client_flush_handler'), |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
ClientInputFilter => $self->{ClientInputFilter} || POE::Filter::Line->new, |
59
|
|
|
|
|
|
|
ClientOutputFilter => $self->{ClientOutputFilter} || POE::Filter::Line->new, |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
InlineStates => { |
62
|
|
|
|
|
|
|
send => sub { |
63
|
|
|
|
|
|
|
my ($client, $data) = @_[ARG0..$#_]; |
64
|
|
|
|
|
|
|
$client->put($data) if $client; |
65
|
|
|
|
|
|
|
}, |
66
|
|
|
|
|
|
|
}, |
67
|
|
|
|
|
|
|
); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=head2 poe_send |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
Send TCP response |
73
|
|
|
|
|
|
|
=cut |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub poe_send { |
76
|
|
|
|
|
|
|
my ($kernel,$response, $content) = @_[KERNEL,ARG0..$#_]; |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
# TCP |
79
|
|
|
|
|
|
|
$kernel->post($response => send => $response,$content); |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
1; |