add counter for socket accept fails

Signed-off-by: Kent Gustavsson <kent@minoris.se>
develop
Kent Gustavsson 2023-06-26 22:40:13 +02:00
parent e68aa50f43
commit 09148698c8
1 changed files with 11 additions and 2 deletions

@ -478,7 +478,7 @@ void ServerMainImpl::threadFn(std::promise<bool> promise, int port)
CActiveSocket *client = nullptr; CActiveSocket *client = nullptr;
try { try {
while (server.socket.IsSocketValid()) for (int acceptFail = 0 ; server.socket.IsSocketValid() && acceptFail < 5 ; acceptFail++)
{ {
if ((client = server.socket.Accept()) != NULL) if ((client = server.socket.Accept()) != NULL)
{ {
@ -488,7 +488,7 @@ void ServerMainImpl::threadFn(std::promise<bool> promise, int port)
} }
else else
{ {
WARN(socket).print("Accepting connection error: %s\n", server.socket.DescribeError()); WARN(socket).print("Accepting connection error: %s %d of %d\n", server.socket.DescribeError(), acceptFail + 1, 5);
} }
} }
} catch(BlockedException &) { } catch(BlockedException &) {
@ -496,6 +496,15 @@ void ServerMainImpl::threadFn(std::promise<bool> promise, int port)
client->Close(); client->Close();
delete client; delete client;
} }
if (server.socket.IsSocketValid())
{
WARN(socket).print("To many failed accept, shutting down RemoteServer \n");
}
else
{
WARN(socket).print("Listening socket invalid, shutting down RemoteServer\n");
}
} }
void ServerMain::block() void ServerMain::block()