Merge remote-tracking branch 'cvuchener/server-accept-fix' into myk_remote_server

develop
Myk Taylor 2023-11-20 00:07:00 -08:00
commit ba872902c8
No known key found for this signature in database
1 changed files with 16 additions and 26 deletions

@ -475,38 +475,28 @@ void ServerMainImpl::threadFn(std::promise<bool> promise, int port)
{ {
ServerMainImpl server{std::move(promise), port}; ServerMainImpl server{std::move(promise), port};
CActiveSocket *client = nullptr; server.socket.SetBlocking();
try { try {
for (int acceptFail = 0; server.socket.IsSocketValid() && acceptFail < 5; acceptFail++) while (server.socket.IsSocketValid()) {
{ if (std::unique_ptr<CActiveSocket> client{server.socket.Accept()}) {
if ((client = server.socket.Accept()) != NULL)
{
BlockGuard lock; BlockGuard lock;
ServerConnection::Accepted(client); ServerConnection::Accepted(client.release());
client = nullptr;
acceptFail = 0;
} }
else else switch (server.socket.GetSocketError()) {
{ case CSimpleSocket::SocketInvalidSocket:
WARN(socket).print("Connection failure: %s (%d of %d)\n", server.socket.DescribeError(), acceptFail + 1, 5); WARN(socket).print("Listening socket invalid, shutting down RemoteServer\n");
server.socket.Close();
break;
case CSimpleSocket::SocketFirewallError:
case CSimpleSocket::SocketProtocolError:
WARN(socket).print("Connection failed: %s\n", server.socket.DescribeError());
break;
default:
break;
} }
} }
} }
catch(BlockedException &) { catch(BlockedException &) {
if (client)
client->Close();
delete client;
WARN(socket).print("Connection failure: unexpectedly blocked");
}
if (server.socket.IsSocketValid())
{
WARN(socket).print("Too many failed accepts, shutting down RemoteServer\n");
}
else
{
WARN(socket).print("Listening socket invalid, shutting down RemoteServer\n");
} }
} }