From e6cbc372cc7df1c1b68d934a59a720f4bcfbce47 Mon Sep 17 00:00:00 2001 From: Pedro Melo Date: Mon, 21 Jul 2014 05:52:34 +0100 Subject: [PATCH] On disconnect() send CLS only if this connection is a subscriber If no SUB was sent before, CLS returns error: > E_INVALID cannot CLS in current state Signed-off-by: Pedro Melo --- lib/AnyEvent/NSQ/Connection.pm | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/AnyEvent/NSQ/Connection.pm b/lib/AnyEvent/NSQ/Connection.pm index 98a247c..1f00362 100644 --- a/lib/AnyEvent/NSQ/Connection.pm +++ b/lib/AnyEvent/NSQ/Connection.pm @@ -89,7 +89,7 @@ sub disconnect { my ($self, $cb) = @_; return unless my $hdl = $self->{handle}; - $hdl->push_write("CLS\012"); + $hdl->push_write("CLS\012") if $self->{is_subscriber}; $self->_on_next_success_frame( sub { @@ -121,7 +121,8 @@ sub subscribe { my ($self, $topic, $chan, $cb) = @_; return unless my $hdl = $self->{handle}; - $self->{message_cb} = $cb; + $self->{message_cb} = $cb; + $self->{is_subscriber} = 1; $hdl->push_write("SUB $topic $chan\012"); $self->_on_next_success_frame(sub { }); ## We don't care about the success ok, and errors will kill us