From e715f57effceb7fe44679221bf9603be18462008 Mon Sep 17 00:00:00 2001 From: Tom Early Date: Thu, 16 May 2024 14:27:42 -0700 Subject: [PATCH] tweaking how the TC socket deals with errors --- reflector/CodecStream.cpp | 2 +- reflector/TCSocket.cpp | 14 ++++++++------ reflector/TCSocket.h | 5 +++-- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/reflector/CodecStream.cpp b/reflector/CodecStream.cpp index c3693d1..a84f6aa 100644 --- a/reflector/CodecStream.cpp +++ b/reflector/CodecStream.cpp @@ -118,7 +118,7 @@ void CCodecStream::Task(void) { if (g_TCServer.Accept()) // try to get a connection { - std::cerr << "UNRECOVERABLE ERROR!" << std::endl; + std::cerr << "Unrecoverable ERROR! Quiting..." << std::endl; exit(1); } // Either Accept timed out, or it's possile that other Transcoder ports were instead reopened diff --git a/reflector/TCSocket.cpp b/reflector/TCSocket.cpp index ef62f91..3297fdd 100644 --- a/reflector/TCSocket.cpp +++ b/reflector/TCSocket.cpp @@ -227,7 +227,7 @@ bool CTCServer::Open(const std::string &address, const std::string &modules, uin m_Pfd.back().fd = fd; - std::cout << "Waiting for " << m_Modules.size() << " transcoder connection(s) on fd " << fd << "..." << std::endl; + std::cout << "Waiting for " << m_Modules.size() << " transcoder connection(s) on " << ip << "..." << std::endl; return Accept(); } @@ -235,14 +235,14 @@ bool CTCServer::Accept() { while (any_are_closed()) { - if (AcceptOne()) + if (acceptone()) return true; } return false; } -bool CTCServer::AcceptOne() +bool CTCServer::acceptone() { auto rv = poll(&m_Pfd.back(), 1, 10); if (rv < 0) @@ -295,7 +295,7 @@ bool CTCServer::AcceptOne() return false; } -bool CTCClient::Initialize(const std::string &address, const std::string &modules, uint16_t port) +bool CTCClient::Open(const std::string &address, const std::string &modules, uint16_t port) { m_Address.assign(address); m_Modules.assign(modules); @@ -409,12 +409,13 @@ bool CTCClient::Receive(std::queue> &queue, int ms) if (rv < 0) { perror("Receive poll"); - return false; + return true; } if (0 == rv) return false; + bool some_closed = false; for (auto &pfd : m_Pfd) { if (pfd.revents & POLLIN) @@ -434,7 +435,8 @@ bool CTCClient::Receive(std::queue> &queue, int ms) { std::cerr << "IO ERROR on Receive module " << GetMod(pfd.fd) << std::endl; Close(pfd.fd); + some_closed = true; } } - return ! queue.empty(); + return some_closed; } diff --git a/reflector/TCSocket.h b/reflector/TCSocket.h index 47b98bd..cf1f269 100644 --- a/reflector/TCSocket.h +++ b/reflector/TCSocket.h @@ -32,6 +32,7 @@ public: CTCSocket() {} virtual ~CTCSocket() { Close(); } + virtual bool Open(const std::string &address, const std::string &modules, uint16_t port) = 0; void Close(); // close all open sockets void Close(char module); // close a specific module void Close(int fd); // close a specific file descriptor @@ -59,7 +60,7 @@ public: private: bool any_are_closed(); - bool AcceptOne(); + bool acceptone(); }; class CTCClient : public CTCSocket @@ -67,7 +68,7 @@ class CTCClient : public CTCSocket public: CTCClient() : CTCSocket(), m_Port(0) {} ~CTCClient() {} - bool Initialize(const std::string &address, const std::string &modules, uint16_t port); + bool Open(const std::string &address, const std::string &modules, uint16_t port); bool Receive(std::queue> &queue, int ms); bool ReConnect();