mirror of
https://github.com/nostar/urfd.git
synced 2026-11-08 04:19:39 +00:00
tweaking how the TC socket deals with errors
This commit is contained in:
1 parent
8698c70ab8
commit
e715f57eff
3 files changed
+12
-9
No files matched your search
@@ -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();
|
||||
|
||||
|
||||
Reference in new issue
Block a user