mirror of
https://github.com/nostar/urfd.git
synced 2026-11-08 04:19:39 +00:00
Send an unused TCPacket periodically from tcd to urfd as a simple keepalive solution
This commit is contained in:
1 parent
6fe69ec68c
commit
d1d51938ef
2 files changed
+29
-6
No files matched your search
@@ -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;
|
||||
|
||||
+28
-5
@@ -116,11 +116,18 @@ 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)
|
||||
{
|
||||
std::cerr << "Can't Send() this packet to unconfigured module '" << packet->module << "'" << std::endl;
|
||||
return true;
|
||||
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;
|
||||
@@ -214,7 +221,11 @@ bool CTCServer::Receive(char module, STCPacket *packet, int ms)
|
||||
|
||||
if (rv)
|
||||
Close(pfds->fd);
|
||||
return ! rv;
|
||||
|
||||
if(packet->codec_in == ECodecType::ping)
|
||||
return false;
|
||||
else
|
||||
return !rv;
|
||||
}
|
||||
|
||||
bool CTCServer::Open(const std::string &address, const std::string &modules, uint16_t port)
|
||||
@@ -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)
|
||||
|
||||
Reference in new issue
Block a user