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:
parent
f3955bcd51
commit
189d6c9ef1
|
|
@ -145,7 +145,7 @@ 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
|
||||
|
|
@ -153,6 +153,16 @@ public:
|
|||
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
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue