From d4ad8a2e9ced8e96565aaa75639801c124c6e3e0 Mon Sep 17 00:00:00 2001 From: Tom Early Date: Sat, 18 May 2024 10:16:24 -0700 Subject: [PATCH] RT Stats bug (pass pointers) --- reflector/CodecStream.cpp | 4 ++-- reflector/TCPacketDef.h | 4 ---- reflector/TCSocket.cpp | 12 ++++++------ reflector/TCSocket.h | 4 ++-- 4 files changed, 10 insertions(+), 14 deletions(-) diff --git a/reflector/CodecStream.cpp b/reflector/CodecStream.cpp index ba8457c..c53e851 100644 --- a/reflector/CodecStream.cpp +++ b/reflector/CodecStream.cpp @@ -127,10 +127,10 @@ void CCodecStream::Task(void) } STCPacket pack; - if (g_TCServer.Receive(m_CSModule, pack, 8)) + if (g_TCServer.Receive(m_CSModule, &pack, 8)) { // update statistics - double rt = pack.rt_timer.time(); // the round-trip time + auto rt = pack.rt_timer.time(); // the round-trip time if (0 == m_RTCount) { m_RTMin = rt; diff --git a/reflector/TCPacketDef.h b/reflector/TCPacketDef.h index 43abf5c..203da46 100644 --- a/reflector/TCPacketDef.h +++ b/reflector/TCPacketDef.h @@ -19,10 +19,6 @@ #include "Timer.h" -// unix socket names -#define TC2REF "TC2URFMod" -#define REF2TC "URF2TC" - enum class ECodecType : std::uint8_t { none = 0, dstar = 1, dmr = 2, c2_1600 = 3, c2_3200 = 4, p25 = 5, usrp = 6 }; using STCPacket = struct tcpacket_tag { diff --git a/reflector/TCSocket.cpp b/reflector/TCSocket.cpp index f16cb50..0c1bf75 100644 --- a/reflector/TCSocket.cpp +++ b/reflector/TCSocket.cpp @@ -127,9 +127,9 @@ bool CTCSocket::Send(const STCPacket *packet) return false; } -bool CTCSocket::receive(int fd, STCPacket &packet) +bool CTCSocket::receive(int fd, STCPacket *packet) { - auto n = recv(fd, &packet, sizeof(STCPacket), MSG_WAITALL); + auto n = recv(fd, packet, sizeof(STCPacket), MSG_WAITALL); if (n < 0) { perror("Receive recv"); @@ -139,18 +139,18 @@ bool CTCSocket::receive(int fd, STCPacket &packet) if (0 == n) { - std::cerr << "recv() returned zero bytes from mdule '" << GetMod(fd) << "'"; + std::cerr << "recv(): Module '" << GetMod(fd) << "' has been closed on the server" << std::endl; Close(fd); return true; } if (n != sizeof(STCPacket)) - std::cout << "WARNING: Receive only read " << n << " bytes of the transcoder packet from module '" << GetMod(fd) << "'" << std::endl; + std::cout << "receive() only read " << n << " bytes of the transcoder packet from module '" << GetMod(fd) << "'" << std::endl; return false; } // returns true if there is data to return -bool CTCServer::Receive(char module, STCPacket &packet, int ms) +bool CTCServer::Receive(char module, STCPacket *packet, int ms) { bool rv = false; const auto pos = m_Modules.find(module); @@ -432,7 +432,7 @@ bool CTCClient::Receive(std::queue> &queue, int ms) if (pfd.revents & POLLIN) { auto p_tcpack = std::make_unique(); - if (receive(pfd.fd, *p_tcpack)) + if (receive(pfd.fd, p_tcpack.get())) { p_tcpack.reset(); } diff --git a/reflector/TCSocket.h b/reflector/TCSocket.h index 3a612d4..6ef5788 100644 --- a/reflector/TCSocket.h +++ b/reflector/TCSocket.h @@ -37,7 +37,7 @@ public: void Close(); // close all open sockets void Close(char module); // close a specific module void Close(int fd); // close a specific file descriptor - bool receive(int fd, STCPacket &packet); + bool receive(int fd, STCPacket *packet); // All bool functions, except Server Receive, return true if there was an error bool Send(const STCPacket *packet); @@ -57,7 +57,7 @@ public: ~CTCServer() {} bool Open(const std::string &address, const std::string &modules, uint16_t port); // Returns true if there is data - bool Receive(char module, STCPacket &packet, int ms); + bool Receive(char module, STCPacket *packet, int ms); bool Accept(); private: