From 74a1a175530b8dc54f8f969d71113d6f05d9d1cc Mon Sep 17 00:00:00 2001 From: Sebastian Melinat Date: Wed, 21 Oct 2015 15:26:53 +0200 Subject: [PATCH] During the handshake the heartbeat duration the server wants is stored in the connection so that clients can retrieve and use it for error detection --- include/connection.h | 9 +++++++++ include/connectionimpl.h | 23 +++++++++++++++++++++++ src/connectiontuneframe.h | 3 +++ 3 files changed, 35 insertions(+) diff --git a/include/connection.h b/include/connection.h index 64e63e1..ad8c52e 100644 --- a/include/connection.h +++ b/include/connection.h @@ -153,6 +153,15 @@ public: return _implementation.channels(); } + /** + * Retrieve the heartbeat delay used by this connection + * @return uint16_t + */ + uint16_t heartbeat() const + { + return _implementation.heartbeat(); + } + /** * Some classes have access to private properties */ diff --git a/include/connectionimpl.h b/include/connectionimpl.h index ced61dd..945d8ac 100644 --- a/include/connectionimpl.h +++ b/include/connectionimpl.h @@ -93,6 +93,12 @@ protected: */ std::queue _queue; + /** + * Heartbeat delay + * @var uint16_t + */ + uint16_t _heartbeat = 0; + /** * Helper method to send the close frame * Return value tells if the connection is still valid @@ -342,6 +348,23 @@ public: return _channels.size(); } + /** + * Heartbeat delay + * @return uint16_t + */ + uint16_t heartbeat() const + { + return _heartbeat; + } + + /** + * Set the heartbeat delay + */ + void setHeartbeat(uint16_t heartbeat) + { + _heartbeat = heartbeat; + } + /** * The actual connection is a friend and can construct this class */ diff --git a/src/connectiontuneframe.h b/src/connectiontuneframe.h index eac4b72..7887ab3 100644 --- a/src/connectiontuneframe.h +++ b/src/connectiontuneframe.h @@ -137,6 +137,9 @@ public: // theoretically it is possible that the connection object gets destructed between sending the messages Monitor monitor(connection); + // store the heartbeat the server wants + connection->setHeartbeat(heartbeat()); + // send it back connection->send(ConnectionTuneOKFrame(channelMax(), frameMax(), heartbeat()));