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 <melo@simplicidade.org>
This commit is contained in:
Pedro Melo
2014-07-21 05:52:34 +01:00
parent d807d361f3
commit e6cbc372cc

View File

@@ -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 {
@@ -122,6 +122,7 @@ sub subscribe {
return unless my $hdl = $self->{handle};
$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