when user calls connection.heartbeat() we now always send out the heartbeat (AMQP-CPP no longer tries to be smart about skipping heartbeats, because that could lead to timeouts if the user is a little late with its call, or when there is network congestion)

This commit is contained in:
Emiel Bruijntjes 2018-11-28 13:52:00 +01:00
parent 3373cec5a2
commit 53f994d61d
2 changed files with 6 additions and 31 deletions

View File

@ -125,12 +125,6 @@ protected:
*/
std::queue<CopiedBuffer> _queue;
/**
* Is the connection idle (meaning: a heartbeat is necessary)
* @var bool
*/
bool _idle = true;
/**
* Helper method to send the close frame
* Return value tells if the connection is still valid
@ -432,9 +426,9 @@ public:
}
/**
* Set the heartbeat delay
* @param heartbeat suggested heartbeat by server
* @return uint16_t accepted heartbeat by client
* Set the heartbeat timeout
* @param heartbeat suggested heartbeat timeout by server
* @return uint16_t accepted heartbeat timeout from client
*/
uint16_t setHeartbeat(uint16_t heartbeat)
{
@ -453,11 +447,9 @@ public:
/**
* Send a heartbeat to keep the connection alive
* By default, this function does nothing if the connection is not in an idle state
* @param force always send the heartbeat, even if the connection is not idle
* @return bool
*/
bool heartbeat(bool force=false);
bool heartbeat();
/**
* The actual connection is a friend and can construct this class

View File

@ -327,9 +327,6 @@ void ConnectionImpl::setReady()
// get the next message
const auto &buffer = _queue.front();
// data is going to be sent, thus connection is not idle
_idle = false;
// send it
_handler->onData(_parent, buffer.data(), buffer.size());
@ -397,9 +394,6 @@ bool ConnectionImpl::send(const Frame &frame)
// are we still setting up the connection?
if ((_state == state_connected && _queue.empty()) || frame.partOfHandshake())
{
// the data will be sent, so connection is not idle
_idle = false;
// we need an output buffer (this will immediately send the data)
PassthroughBuffer buffer(_parent, _handler, frame);
}
@ -426,9 +420,6 @@ bool ConnectionImpl::send(CopiedBuffer &&buffer)
// are we waiting for other frames to be sent before us?
if (_queue.empty())
{
// data will be sent, thus connection is not empty
_idle = false;
// send it directly
_handler->onData(_parent, buffer.data(), buffer.size());
}
@ -444,20 +435,12 @@ bool ConnectionImpl::send(CopiedBuffer &&buffer)
/**
* Send a ping / heartbeat frame to keep the connection alive
* @param force also send heartbeat if connection is not idle
* @return bool
*/
bool ConnectionImpl::heartbeat(bool force)
bool ConnectionImpl::heartbeat()
{
// do nothing if the connection is not idle (but we do reset the idle state to ensure
// that the next heartbeat will be sent if nothing is going to change from now on)
if (!force && !_idle) return _idle = true;
// send a frame
if (!send(HeartbeatFrame())) return false;
// frame has been sent, we treat the connection as idle now until some other data is sent over it
return _idle = true;
return send(HeartbeatFrame());
}
/**