From 189d6c9ef1a1b616b2a87ae8055e7822632c677c Mon Sep 17 00:00:00 2001 From: Emiel Bruijntjes Date: Sat, 31 Oct 2015 18:26:52 +0100 Subject: [PATCH] added Connection::waiting() method to find out if the connection object is waiting/expecting an answer from the rabbitmq server --- include/connection.h | 12 +++++++++++- include/connectionimpl.h | 7 ++++++- include/receivedframe.h | 2 +- src/connectionimpl.cpp | 23 +++++++++++++++++++---- src/connectionstartframe.h | 2 +- 5 files changed, 38 insertions(+), 8 deletions(-) diff --git a/include/connection.h b/include/connection.h index 64e63e1..ca816f2 100644 --- a/include/connection.h +++ b/include/connection.h @@ -145,13 +145,23 @@ public: } /** - * Retrieve the amount of channels this connection has + * Retrieve the number of channels that are active for this connection * @return std::size_t */ std::size_t channels() const { return _implementation.channels(); } + + /** + * Is the connection busy waiting for an answer from the server? (in the + * meantime you can already send more instructions over it) + * @return bool + */ + std::size_t waiting() const + { + return _implementation.waiting(); + } /** * Some classes have access to private properties diff --git a/include/connectionimpl.h b/include/connectionimpl.h index ced61dd..f90a14a 100644 --- a/include/connectionimpl.h +++ b/include/connectionimpl.h @@ -104,8 +104,13 @@ protected: * Is any channel waiting for an answer on a synchronous call? * @return bool */ - bool waiting() const; + bool waitingChannels() const; + /** + * Is the channel waiting for a response from the peer (server) + * @return bool + */ + bool waiting() const; private: /** diff --git a/include/receivedframe.h b/include/receivedframe.h index 68ed145..7302a52 100644 --- a/include/receivedframe.h +++ b/include/receivedframe.h @@ -5,7 +5,7 @@ * find out if the buffer is big enough to contain an entire frame, and * it will try to recognize the frame type in the buffer * - * This is a class that is used internally by the AMQP library. As a used + * This is a class that is used internally by the AMQP library. As a user * of this library, you normally do not have to instantiate it. * * @documentation public diff --git a/src/connectionimpl.cpp b/src/connectionimpl.cpp index 863b871..bd78082 100644 --- a/src/connectionimpl.cpp +++ b/src/connectionimpl.cpp @@ -150,7 +150,7 @@ uint64_t ConnectionImpl::parse(const Buffer &buffer) // the close() function was called, but if the close frame was not yet sent // if there are no waiting channels, we can do that right now - if (!waiting()) sendClose(); + if (!waitingChannels()) sendClose(); // done return processed; @@ -172,7 +172,7 @@ bool ConnectionImpl::close() // after the send operation the object could be dead Monitor monitor(this); - // number of channels that is waiting for an answer and that has further data + // number of channels that are waiting for an answer and that have further data int waiters = 0; // loop over all channels, and close them @@ -184,7 +184,7 @@ bool ConnectionImpl::close() // we could be dead now if (!monitor.valid()) return true; - // is this channel waiting for an answer + // is this channel waiting for an answer? if (iter->second->waiting()) waiters++; } @@ -258,10 +258,25 @@ void ConnectionImpl::setConnected() } /** - * Is any channel waiting for an answer on a synchronous call? + * Is the connection waiting for an answer from an instruction? * @return bool */ bool ConnectionImpl::waiting() const +{ + // some states are implicit waiting states + if (_state == state_protocol) return true; + if (_state == state_handshake) return true; + if (_state == state_closing) return true; + + // check if there are waiting channels + return waitingChannels(); +} + +/** + * Is any channel waiting for an answer on a synchronous call? + * @return bool + */ +bool ConnectionImpl::waitingChannels() const { // loop through the channels for (auto &iter : _channels) diff --git a/src/connectionstartframe.h b/src/connectionstartframe.h index b7cdb37..a8a0868 100644 --- a/src/connectionstartframe.h +++ b/src/connectionstartframe.h @@ -196,7 +196,7 @@ public: properties["product"] = "Copernica AMQP library"; properties["version"] = "Unknown"; properties["platform"] = "Unknown"; - properties["copyright"] = "Copyright 2014 Copernica BV"; + properties["copyright"] = "Copyright 2015 Copernica BV"; properties["information"] = "http://www.copernica.com"; properties["capabilities"] = capabilities;