/usr/share/doc/libzeromq-perl/examples/threaded_server.pl is in libzeromq-perl 0.23-1build4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | #!/usr/bin/env perl
use strict;
use threads;
use ZeroMQ::Constants qw(ZMQ_XREQ ZMQ_XREP ZMQ_REQ ZMQ_REP ZMQ_QUEUE);
use ZeroMQ::Raw;
my $ctxt = zmq_init();
my $clients = zmq_socket($ctxt, ZMQ_XREP);
my $workers = zmq_socket($ctxt, ZMQ_XREQ);
my ($host, $port);
if (@ARGV >= 2) {
($host, $port) = @ARGV;
} elsif (@ARGV) {
if ($ARGV[0] =~ /^([\w\.]+):(\d+)$/) {
($host, $port) = ($1, $2);
} else {
$host = $ARGV[0];
}
}
$host ||= '127.0.0.1';
$port ||= 5566;
print "Connecting to server...\n";
zmq_bind( $clients, "tcp://$host:$port" );
zmq_bind( $workers, "inproc://workers" );
for (1..5) {
threads->create( sub {
my $ctxt = shift;
my $wsock = zmq_socket($ctxt, ZMQ_REP);
zmq_connect( $wsock, "inproc://workers" );
while (1) {
my $message = zmq_recv( $wsock );
print zmq_msg_data($message), "\n";
sleep 1; # Do some dummy "work"
zmq_send( $wsock, "World" );
}
}, $ctxt );
}
ZeroMQ::Raw::zmq_device(ZMQ_QUEUE, $clients, $workers);
|