Merge pull request #4046 from myk002/myk_remote_server

RemoteServer PR merge
develop
Myk 2023-11-20 00:15:54 -08:00 committed by GitHub
commit 3c58240ceb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 24 deletions

@ -57,6 +57,7 @@ Template for new versions:
## Fixes ## Fixes
- `buildingplan`: fix choosing the wrong mechanism (or something that isn't a mechanism) when linking a lever and manually choosing a mechanism, but then canceling the selection - `buildingplan`: fix choosing the wrong mechanism (or something that isn't a mechanism) when linking a lever and manually choosing a mechanism, but then canceling the selection
- RemoteServer: don't shut down the socket prematurely, allowing continuing connections from, for example, dfhack-run
## Misc Improvements ## Misc Improvements
- `buildingplan`: save magma safe mechanisms for when magma safety is requested when linking levers and pressure plates to targets - `buildingplan`: save magma safe mechanisms for when magma safety is requested when linking levers and pressure plates to targets

@ -80,7 +80,7 @@ namespace {
struct BlockedException : std::exception { struct BlockedException : std::exception {
const char* what() const noexcept override const char* what() const noexcept override
{ {
return "Core has blocked all connection. This should have been catched."; return "Core has blocked all connection. This should have been caught.";
} }
}; };
} }
@ -475,35 +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;
} }
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 &) {
if (client)
client->Close();
delete client;
}
if (server.socket.IsSocketValid())
{
WARN(socket).print("Too many failed accepts, shutting down RemoteServer\n");
} }
else catch(BlockedException &) {
{
WARN(socket).print("Listening socket invalid, shutting down RemoteServer\n");
} }
} }