diff --git a/include/amqpcpp/connectionimpl.h b/include/amqpcpp/connectionimpl.h index 7f8e1b7..aa040b3 100644 --- a/include/amqpcpp/connectionimpl.h +++ b/include/amqpcpp/connectionimpl.h @@ -125,12 +125,6 @@ protected: */ std::queue _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 diff --git a/src/connectionimpl.cpp b/src/connectionimpl.cpp index bc06c4d..9ef5ce0 100644 --- a/src/connectionimpl.cpp +++ b/src/connectionimpl.cpp @@ -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()); } /**