tweaking how the TC socket deals with errors

pull/3/head
Tom Early 2 years ago
parent 8698c70ab8
commit e715f57eff

@ -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

@ -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<std::unique_ptr<STCPacket>> &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<std::unique_ptr<STCPacket>> &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;
}

@ -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<std::unique_ptr<STCPacket>> &queue, int ms);
bool ReConnect();

Loading…
Cancel
Save

Powered by TurnKey Linux.