From 888dc8c40b9103f4a61392208bfafac1b409d682 Mon Sep 17 00:00:00 2001 From: Emiel Bruijntjes Date: Mon, 12 Nov 2018 15:24:25 +0100 Subject: [PATCH] added channel::usable() to replace channel::connected() --- include/amqpcpp/channel.h | 17 ++++++++++++++--- include/amqpcpp/channelimpl.h | 4 ++-- src/channelimpl.cpp | 8 ++++---- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/include/amqpcpp/channel.h b/include/amqpcpp/channel.h index e5ebe84..44337b0 100644 --- a/include/amqpcpp/channel.h +++ b/include/amqpcpp/channel.h @@ -125,12 +125,23 @@ public: } /** - * Is the channel connected? + * Is the channel usable / not yet closed? * @return bool */ - bool connected() + bool usable() const { - return _implementation->connected(); + return _implementation->usable(); + } + + /** + * Is the channel connected? + * This method is deprecated: use Channel::usable() + * @return bool + * @deprecated + */ + bool connected() const + { + return usable(); } /** diff --git a/include/amqpcpp/channelimpl.h b/include/amqpcpp/channelimpl.h index d3ef475..0385af3 100644 --- a/include/amqpcpp/channelimpl.h +++ b/include/amqpcpp/channelimpl.h @@ -251,10 +251,10 @@ public: Deferred &resume(); /** - * Is the channel connected? + * Is the channel usable / not yet closed? * @return bool */ - bool connected() + bool usable() const { return _state == state_connected || _state == state_ready; } diff --git a/src/channelimpl.cpp b/src/channelimpl.cpp index 75fbe44..b8a7f68 100644 --- a/src/channelimpl.cpp +++ b/src/channelimpl.cpp @@ -71,8 +71,8 @@ void ChannelImpl::onError(const ErrorCallback &callback) // store callback _errorCallback = callback; - // if the channel is connected, all is ok - if (connected()) return; + // if the channel is usable, all is ok + if (usable()) return; // is the channel closing down? if (_state == state_closing) return callback("Channel is closing down"); @@ -246,8 +246,8 @@ Deferred &ChannelImpl::rollbackTransaction() */ Deferred &ChannelImpl::close() { - // this is completely pointless if not connected - if (!connected()) return push(std::make_shared(_state == state_closing)); + // this is completely pointless if already closed + if (!usable()) return push(std::make_shared(_state == state_closing)); // send a channel close frame auto &handler = push(ChannelCloseFrame(_id));