[libmessage-passing-zeromq-perl] 23/78: Allow connect or bind to be done in any direction

Jonas Smedegaard js at alioth.debian.org
Mon Sep 30 09:28:20 UTC 2013


This is an automated email from the git hooks/post-receive script.

js pushed a commit to branch master
in repository libmessage-passing-zeromq-perl.

commit 4df08a2992e4f4c4bf9a31c328d41e3570354a1c
Author: Tomas Doran <bobtfish at bobtfish.net>
Date:   Sat Mar 17 18:24:35 2012 +0000

    Allow connect or bind to be done in any direction
---
 lib/Log/Stash/Input/ZeroMQ.pm           |   11 +++--------
 lib/Log/Stash/Output/ZeroMQ.pm          |   13 ++++---------
 lib/Log/Stash/ZeroMQ/Role/HasASocket.pm |   21 +++++++++++++++++++++
 3 files changed, 28 insertions(+), 17 deletions(-)

diff --git a/lib/Log/Stash/Input/ZeroMQ.pm b/lib/Log/Stash/Input/ZeroMQ.pm
index 85c7b72..89364a3 100644
--- a/lib/Log/Stash/Input/ZeroMQ.pm
+++ b/lib/Log/Stash/Input/ZeroMQ.pm
@@ -17,21 +17,16 @@ has '+_socket' => (
     },
 );
 
-has socket_bind => (
-    is => 'ro',
-    isa => 'Str',
+has '+socket_bind' => (
     default => 'tcp://*:5558',
 );
 
 sub _socket_type { 'SUB' }
 
-around _build_socket => sub {
-    my ($orig, $self, @args) = @_;
-    my $socket = $self->$orig(@args);
+after setsockopt => sub {
+    my ($self, $socket) = @_;
     $socket->setsockopt(ZMQ_SUBSCRIBE, '');
     $socket->setsockopt(ZMQ_HWM, 100000); # Buffer up to 100k messages.
-    $socket->bind($self->socket_bind);
-    return $socket;
 };
 
 sub _try_rx {
diff --git a/lib/Log/Stash/Output/ZeroMQ.pm b/lib/Log/Stash/Output/ZeroMQ.pm
index 50e5d78..e6dfef4 100644
--- a/lib/Log/Stash/Output/ZeroMQ.pm
+++ b/lib/Log/Stash/Output/ZeroMQ.pm
@@ -11,20 +11,15 @@ has '+_socket' => (
     },
 );
 
-has connect => (
-    isa => 'Str',
-    is => 'ro',
+has '+connect' => (
     default => sub { 'tcp://127.0.0.1:5558' },
 );
 
 sub _socket_type { 'PUB' }
 
-around _build_socket => sub {
-    my ($orig, $self, @args) = @_;
-    my $socket = $self->$orig(@args);
-    $socket->setsockopt(ZMQ_HWM, 1000);
-    $socket->connect($self->connect);
-    return $socket;
+after setsockopt => sub {
+    my ($self, $socket) = @_;
+    $socket->setsockopt(ZMQ_HWM, 1000); # Buffer up to 100k messages.
 };
 
 sub consume {
diff --git a/lib/Log/Stash/ZeroMQ/Role/HasASocket.pm b/lib/Log/Stash/ZeroMQ/Role/HasASocket.pm
index a41ef1b..6967d31 100644
--- a/lib/Log/Stash/ZeroMQ/Role/HasASocket.pm
+++ b/lib/Log/Stash/ZeroMQ/Role/HasASocket.pm
@@ -39,15 +39,36 @@ sub _build_socket {
     if (!$self->linger) {
         $socket->setsockopt(ZMQ_LINGER, 0);
     }
+    $self->setsockopt($socket);
+    if ($self->_should_connect) {
+        $socket->connect($self->connect);
+    }
+    if ($self->_should_bind) {
+        $socket->bind($self->socket_bind);
+    }
     $socket;
 }
 
+sub setsockopt {}
+
+has socket_bind => (
+    is => 'ro',
+    isa => 'Str',
+    predicate => '_should_bind',
+);
+
 has socket_type => (
     isa => enum([qw[PUB SUB PUSH PULL]]),
     is => 'ro',
     builder => '_socket_type',
 );
 
+has connect => (
+    isa => 'Str',
+    is => 'ro',
+    predicate => '_should_connect',
+);
+
 1;
 
 =head1 NAME

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/libmessage-passing-zeromq-perl.git



More information about the Pkg-perl-cvs-commits mailing list