line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package ZMQ::Raw::Proxy; |
2
|
|
|
|
|
|
|
$ZMQ::Raw::Proxy::VERSION = '0.38'; |
3
|
14
|
|
|
14
|
|
97
|
use strict; |
|
14
|
|
|
|
|
26
|
|
|
14
|
|
|
|
|
425
|
|
4
|
14
|
|
|
14
|
|
67
|
use warnings; |
|
14
|
|
|
|
|
25
|
|
|
14
|
|
|
|
|
312
|
|
5
|
14
|
|
|
14
|
|
61
|
use ZMQ::Raw; |
|
14
|
|
|
|
|
27
|
|
|
14
|
|
|
|
|
698
|
|
6
|
|
|
|
|
|
|
|
7
|
0
|
|
|
0
|
|
|
sub CLONE_SKIP { 1 } |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 NAME |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
ZMQ::Raw::Proxy - ZeroMQ Proxy class |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 VERSION |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
version 0.38 |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 DESCRIPTION |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
ZeroMQ Proxy |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 SYNOPSIS |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
use ZMQ::Raw; |
24
|
|
|
|
|
|
|
use threads; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
my $ctx = ZMQ::Raw::Context->new; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub Proxy |
29
|
|
|
|
|
|
|
{ |
30
|
|
|
|
|
|
|
my $frontend = ZMQ::Raw::Socket->new ($ctx, ZMQ::Raw->ZMQ_ROUTER); |
31
|
|
|
|
|
|
|
$frontend->bind ('tcp://*:5555'); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
my $backend = ZMQ::Raw::Socket->new ($ctx, ZMQ::Raw->ZMQ_DEALER); |
34
|
|
|
|
|
|
|
$backend->bind ('tcp://*:5556'); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
my $proxy = ZMQ::Raw::Proxy->new(); |
37
|
|
|
|
|
|
|
$proxy->start ($frontend, $backend); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
# start the proxy in a different thread |
41
|
|
|
|
|
|
|
my $proxy = threads->create ('Proxy'); |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
my $req = ZMQ::Raw::Socket->new ($ctx, ZMQ::Raw->ZMQ_REQ); |
44
|
|
|
|
|
|
|
$req->connect ('tcp://127.0.0.1:5555'); |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
my $rep = ZMQ::Raw::Socket->new ($ctx, ZMQ::Raw->ZMQ_REP); |
47
|
|
|
|
|
|
|
$rep->connect ('tcp://127.0.0.1:5556'); |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
# interact |
50
|
|
|
|
|
|
|
$req->send ('hello'); |
51
|
|
|
|
|
|
|
$rep->recv(); |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
$rep->send ('world'); |
54
|
|
|
|
|
|
|
$req->recv(); |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
$ctx->shutdown(); |
57
|
|
|
|
|
|
|
$proxy->join(); |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head1 METHODS |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head2 new( ) |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
Create a new proxy instance. |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=head2 start( $frontend, $backend, [$capture, $control] ) |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
Start the built-in ZeroMQ proxy in the current application thread. The proxy |
68
|
|
|
|
|
|
|
connects the frontend socket to the backend socket. If a C<$capture> socket is |
69
|
|
|
|
|
|
|
provided, the proxy shall send all messages, received on both frontend and |
70
|
|
|
|
|
|
|
backend to the C<$capture> socket. If a C<$control> socket is provided, the proxy |
71
|
|
|
|
|
|
|
also supports flow control. If C<"PAUSE"> is received on this socket, the proxy |
72
|
|
|
|
|
|
|
suspends its activities. If C<"RESUME"> is received, it goes on. If C<"TERMINATE"> |
73
|
|
|
|
|
|
|
is received, it terminates smoothly. |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
B: This method will only return once the current context is closed, |
76
|
|
|
|
|
|
|
that is, it will block. This method B be called in a different interpreter |
77
|
|
|
|
|
|
|
thread. |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head1 AUTHOR |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
Jacques Germishuys |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
Copyright 2017 Jacques Germishuys. |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
88
|
|
|
|
|
|
|
under the terms of either: the GNU General Public License as published |
89
|
|
|
|
|
|
|
by the Free Software Foundation; or the Artistic License. |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
See http://dev.perl.org/licenses/ for more information. |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=cut |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
1; # End of ZMQ::Raw::Proxy |