added Connection::waiting() method to find out if the connection object is waiting/expecting an answer from the rabbitmq server

This commit is contained in:
Emiel Bruijntjes 2015-10-31 18:26:52 +01:00
parent f3955bcd51
commit 189d6c9ef1
5 changed files with 38 additions and 8 deletions

View File

@ -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 * @return std::size_t
*/ */
std::size_t channels() const std::size_t channels() const
{ {
return _implementation.channels(); 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 * Some classes have access to private properties

View File

@ -104,8 +104,13 @@ protected:
* Is any channel waiting for an answer on a synchronous call? * Is any channel waiting for an answer on a synchronous call?
* @return bool * @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: private:
/** /**

View File

@ -5,7 +5,7 @@
* find out if the buffer is big enough to contain an entire frame, and * 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 * 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. * of this library, you normally do not have to instantiate it.
* *
* @documentation public * @documentation public

View File

@ -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 // 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 there are no waiting channels, we can do that right now
if (!waiting()) sendClose(); if (!waitingChannels()) sendClose();
// done // done
return processed; return processed;
@ -172,7 +172,7 @@ bool ConnectionImpl::close()
// after the send operation the object could be dead // after the send operation the object could be dead
Monitor monitor(this); 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; int waiters = 0;
// loop over all channels, and close them // loop over all channels, and close them
@ -184,7 +184,7 @@ bool ConnectionImpl::close()
// we could be dead now // we could be dead now
if (!monitor.valid()) return true; if (!monitor.valid()) return true;
// is this channel waiting for an answer // is this channel waiting for an answer?
if (iter->second->waiting()) waiters++; 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 * @return bool
*/ */
bool ConnectionImpl::waiting() const 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 // loop through the channels
for (auto &iter : _channels) for (auto &iter : _channels)

View File

@ -196,7 +196,7 @@ public:
properties["product"] = "Copernica AMQP library"; properties["product"] = "Copernica AMQP library";
properties["version"] = "Unknown"; properties["version"] = "Unknown";
properties["platform"] = "Unknown"; properties["platform"] = "Unknown";
properties["copyright"] = "Copyright 2014 Copernica BV"; properties["copyright"] = "Copyright 2015 Copernica BV";
properties["information"] = "http://www.copernica.com"; properties["information"] = "http://www.copernica.com";
properties["capabilities"] = capabilities; properties["capabilities"] = capabilities;