added connection::heartbeat() method, userspace programs are responsible for calling this method once every 60 seconds
This commit is contained in:
parent
399d78dfe5
commit
a091921e88
|
|
@ -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
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -52,6 +52,10 @@ public:
|
||||||
* 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
|
||||||
* @return uint16_t The interval to use
|
* @return uint16_t The interval to use
|
||||||
|
|
|
||||||
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -442,6 +427,12 @@ public:
|
||||||
_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
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,6 @@
|
||||||
#include "basicrejectframe.h"
|
#include "basicrejectframe.h"
|
||||||
#include "basicgetframe.h"
|
#include "basicgetframe.h"
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set up namespace
|
* Set up namespace
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -60,9 +60,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;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue