From eeafb28e4ddb29b6394051e20621067d8c0ccfac Mon Sep 17 00:00:00 2001 From: bergmann Date: Tue, 27 Nov 2018 21:50:21 +0100 Subject: [PATCH] * fixed bug: check connection status before closing channel --- include/cppamqp/connection.h | 2 ++ include/cppamqp/connection.inl | 3 +++ src/cppamqp/channel.cpp | 2 +- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/include/cppamqp/connection.h b/include/cppamqp/connection.h index 2426aa4..d5375db 100644 --- a/include/cppamqp/connection.h +++ b/include/cppamqp/connection.h @@ -34,6 +34,8 @@ namespace cppamqp std::unique_ptr _internal; public: + inline operator bool() const; + inline amqp_connection_state_t& handle (); inline const amqp_connection_state_t& handle () const; diff --git a/include/cppamqp/connection.inl b/include/cppamqp/connection.inl index 5196f9e..4a3336d 100644 --- a/include/cppamqp/connection.inl +++ b/include/cppamqp/connection.inl @@ -35,6 +35,9 @@ namespace cppamqp return value; } + connection::operator bool() const + { return static_cast(_internal); } + amqp_connection_state_t& connection::handle() { if (!_internal) diff --git a/src/cppamqp/channel.cpp b/src/cppamqp/channel.cpp index 601cd93..e6cdd8f 100644 --- a/src/cppamqp/channel.cpp +++ b/src/cppamqp/channel.cpp @@ -20,7 +20,7 @@ channel::internal::internal(const cppamqp::connection& p_connection, channel_num channel::internal::~internal() { - if (handle <= 0) + if (handle <= 0 || !static_cast(connection)) return; __impl::check_and_raise( amqp_channel_close(connection.handle(), handle, AMQP_REPLY_SUCCESS),