added connection::heartbeat() method, userspace programs are responsible for calling this method once every 60 seconds

This commit is contained in:
Emiel Bruijntjes 2017-06-16 10:14:42 +01:00
parent 399d78dfe5
commit a091921e88
8 changed files with 34 additions and 34 deletions

View File

@ -94,6 +94,15 @@ public:
return _implementation.vhost();
}
/**
* Send a ping/heartbeat to the channel to keep it alive
* @return bool
*/
bool ping()
{
return _implementation.ping();
}
/**
* Parse data that was recevied from RabbitMQ
*
@ -195,15 +204,6 @@ public:
return _implementation.waiting();
}
/**
* 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
*/

View File

@ -52,6 +52,10 @@ public:
* to use an other interval. You should return 0 if you want to
* disable heartbeats.
*
* If heartbeats are enabled, you yourself are responsible to send
* out a heartbeat every *interval* number of seconds by calling
* the Connection::heartbeat() method.
*
* @param connection The connection that suggested a heartbeat interval
* @param interval The suggested interval from the server
* @return uint16_t The interval to use

View File

@ -124,12 +124,6 @@ protected:
*/
std::queue<CopiedBuffer> _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
@ -413,15 +407,6 @@ public:
return _channels.size();
}
/**
* Heartbeat delay
* @return uint16_t
*/
uint16_t heartbeat() const
{
return _heartbeat;
}
/**
* Set the heartbeat delay
* @param heartbeat suggested heartbeat by server
@ -430,7 +415,7 @@ public:
uint16_t setHeartbeat(uint16_t heartbeat)
{
// pass to the handler
return _heartbeat = _handler->onNegotiate(_parent, heartbeat);
return _handler->onNegotiate(_parent, heartbeat);
}
/**
@ -442,6 +427,12 @@ public:
_handler->onHeartbeat(_parent);
}
/**
* Send a heartbeat to keep the connection alive
* @return bool
*/
bool heartbeat();
/**
* The actual connection is a friend and can construct this class
*/

View File

@ -33,7 +33,7 @@ public:
/**
* Destructor
*/
virtual ~TcpHandler() {}
virtual ~TcpHandler() = default;
/**
* Method that is called when the heartbeat frequency is negotiated
@ -96,8 +96,6 @@ public:
* @param flags Should the object be monitored for readability or writability?
*/
virtual void monitor(TcpConnection *connection, int fd, int flags) = 0;
};
/**

View File

@ -39,7 +39,6 @@
#include "basicrejectframe.h"
#include "basicgetframe.h"
/**
* Set up namespace
*/

View File

@ -3,7 +3,7 @@
*
* Implementation of an AMQP connection
*
* @copyright 2014 - 2016 Copernica BV
* @copyright 2014 - 2017 Copernica BV
*/
#include "includes.h"
#include "protocolheaderframe.h"
@ -11,6 +11,7 @@
#include "connectioncloseframe.h"
#include "reducedbuffer.h"
#include "passthroughbuffer.h"
#include "heartbeatframe.h"
/**
* set namespace
@ -374,6 +375,16 @@ bool ConnectionImpl::send(CopiedBuffer &&buffer)
return true;
}
/**
* Send a ping / heartbeat frame to keep the connection alive
* @return bool
*/
bool ConnectionImpl::heartbeat()
{
// send a frame
return send(HeartbeatFrame());
}
/**
* End of namspace
*/

View File

@ -60,9 +60,6 @@ public:
// notify the connection-handler
connection->reportHeartbeat();
// send back the same frame
connection->send(*this);
// done
return true;
}