Send an unused TCPacket periodically from tcd to urfd as a simple keepalive solution

pull/8/head
Doug McLain 1 year ago
parent 6fe69ec68c
commit d1d51938ef

@ -17,7 +17,7 @@
#include <cstdint>
enum class ECodecType : std::uint8_t { none = 0, dstar = 1, dmr = 2, c2_1600 = 3, c2_3200 = 4, p25 = 5, usrp = 6 };
enum class ECodecType : std::uint8_t { none = 0, dstar = 1, dmr = 2, c2_1600 = 3, c2_3200 = 4, p25 = 5, usrp = 6, ping = 0xff };
using STCPacket = struct tcpacket_tag {
uint32_t sequence;

@ -116,12 +116,19 @@ bool CTCServer::AnyAreClosed() const
bool CTCSocket::Send(const STCPacket *packet)
{
const auto pos = m_Modules.find(packet->module);
auto pos = m_Modules.find(packet->module);
if (pos == std::string::npos)
{
if(packet->codec_in == ECodecType::ping)
{
pos = 0; // There is at least one transcoding module, use it to send the ping
}
else
{
std::cerr << "Can't Send() this packet to unconfigured module '" << packet->module << "'" << std::endl;
return true;
}
}
unsigned count = 0;
auto data = (const unsigned char *)packet;
do {
@ -214,6 +221,10 @@ bool CTCServer::Receive(char module, STCPacket *packet, int ms)
if (rv)
Close(pfds->fd);
if(packet->codec_in == ECodecType::ping)
return false;
else
return !rv;
}
@ -434,8 +445,12 @@ bool CTCClient::Connect(char module)
return false;
}
void CTCClient::ReConnect()
void CTCClient::ReConnect() // and sometimes ping
{
static std::chrono::system_clock::time_point start = std::chrono::system_clock::now();
auto now = std::chrono::system_clock::now();
std::chrono::duration<double> secs = now - start;
for (char m : m_Modules)
{
if (0 > GetFD(m))
@ -447,6 +462,14 @@ void CTCClient::ReConnect()
}
}
}
if(secs.count() > 5.0)
{
STCPacket ping;
ping.codec_in = ECodecType::ping;
Send(&ping);
start = now;
}
}
void CTCClient::Receive(std::queue<std::unique_ptr<STCPacket>> &queue, int ms)

Loading…
Cancel
Save

Powered by TurnKey Linux.