From 6432ce2ec15b0c45691f6a3c288234c8ccd13467 Mon Sep 17 00:00:00 2001 From: Emiel Bruijntjes Date: Mon, 12 Nov 2018 15:19:31 +0100 Subject: [PATCH] added connection::usable() --- include/amqpcpp/connection.h | 10 ++++++++++ include/amqpcpp/connectionimpl.h | 9 +++++++++ include/amqpcpp/linux_tcp/tcpconnection.h | 9 +++++++++ 3 files changed, 28 insertions(+) diff --git a/include/amqpcpp/connection.h b/include/amqpcpp/connection.h index 99edc33..ade2c3b 100644 --- a/include/amqpcpp/connection.h +++ b/include/amqpcpp/connection.h @@ -195,6 +195,16 @@ public: { return _implementation.expected(); } + + /** + * Is the connection in a usable state, or is it already closed or + * in the process of being closed? + * @return bool + */ + bool usable() const + { + return _implementation.usable(); + } /** * Close the connection diff --git a/include/amqpcpp/connectionimpl.h b/include/amqpcpp/connectionimpl.h index bdd79c0..7f8e1b7 100644 --- a/include/amqpcpp/connectionimpl.h +++ b/include/amqpcpp/connectionimpl.h @@ -252,6 +252,15 @@ public: // state must be connected return _state == state_closed; } + + /** + * Is the connection in a usable state / not yet closed? + * @return bool + */ + bool usable() const + { + return (_state == state_protocol || _state == state_handshake || _state == state_connected) && !_closed; + } /** * Mark the connection as ready diff --git a/include/amqpcpp/linux_tcp/tcpconnection.h b/include/amqpcpp/linux_tcp/tcpconnection.h index 3c48170..dd1aabd 100644 --- a/include/amqpcpp/linux_tcp/tcpconnection.h +++ b/include/amqpcpp/linux_tcp/tcpconnection.h @@ -236,6 +236,15 @@ public: */ bool close(bool immediate = false); + /** + * Is the connection in a usable state / not yet closed or being closed + * @return bool + */ + bool usable() const + { + return _connection.usable(); + } + /** * The max frame size. Useful if you set up a buffer to parse incoming data: it does not have to exceed this size. * @return uint32_t