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

@ -508,7 +508,7 @@ public:
* @return bool * @return bool
*/ */
bool reject(uint64_t deliveryTag, int flags); bool reject(uint64_t deliveryTag, int flags);
/** /**
* Recover messages that were not yet ack'ed * Recover messages that were not yet ack'ed
* @param flags optional flags * @param flags optional flags

View File

@ -94,6 +94,15 @@ public:
return _implementation.vhost(); 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 * Parse data that was recevied from RabbitMQ
* *
@ -195,15 +204,6 @@ public:
return _implementation.waiting(); 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 * Some classes have access to private properties
*/ */

View File

@ -51,6 +51,10 @@ public:
* alternative heartbeat interval, you can override this method * alternative heartbeat interval, you can override this method
* to use an other interval. You should return 0 if you want to * to use an other interval. You should return 0 if you want to
* disable heartbeats. * 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 connection The connection that suggested a heartbeat interval
* @param interval The suggested interval from the server * @param interval The suggested interval from the server

View File

@ -124,12 +124,6 @@ protected:
*/ */
std::queue<CopiedBuffer> _queue; std::queue<CopiedBuffer> _queue;
/**
* Heartbeat delay
* @var uint16_t
*/
uint16_t _heartbeat = 0;
/** /**
* Helper method to send the close frame * Helper method to send the close frame
* Return value tells if the connection is still valid * Return value tells if the connection is still valid
@ -413,15 +407,6 @@ public:
return _channels.size(); return _channels.size();
} }
/**
* Heartbeat delay
* @return uint16_t
*/
uint16_t heartbeat() const
{
return _heartbeat;
}
/** /**
* Set the heartbeat delay * Set the heartbeat delay
* @param heartbeat suggested heartbeat by server * @param heartbeat suggested heartbeat by server
@ -430,7 +415,7 @@ public:
uint16_t setHeartbeat(uint16_t heartbeat) uint16_t setHeartbeat(uint16_t heartbeat)
{ {
// pass to the handler // pass to the handler
return _heartbeat = _handler->onNegotiate(_parent, heartbeat); return _handler->onNegotiate(_parent, heartbeat);
} }
/** /**
@ -441,6 +426,12 @@ public:
// pass to handler // pass to handler
_handler->onHeartbeat(_parent); _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 * The actual connection is a friend and can construct this class

View File

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

View File

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

View File

@ -3,7 +3,7 @@
* *
* Implementation of an AMQP connection * Implementation of an AMQP connection
* *
* @copyright 2014 - 2016 Copernica BV * @copyright 2014 - 2017 Copernica BV
*/ */
#include "includes.h" #include "includes.h"
#include "protocolheaderframe.h" #include "protocolheaderframe.h"
@ -11,6 +11,7 @@
#include "connectioncloseframe.h" #include "connectioncloseframe.h"
#include "reducedbuffer.h" #include "reducedbuffer.h"
#include "passthroughbuffer.h" #include "passthroughbuffer.h"
#include "heartbeatframe.h"
/** /**
* set namespace * set namespace
@ -374,6 +375,16 @@ bool ConnectionImpl::send(CopiedBuffer &&buffer)
return true; 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 * End of namspace
*/ */

View File

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