diff --git a/docs/changelog.txt b/docs/changelog.txt index c53d05662..6f2e0d8f7 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -64,6 +64,7 @@ Template for new versions: - `stockpiles`: hide configure and help buttons when the overlay panel is minimized - `caravan`: price of vermin swarms correctly adjusted down. a stack of 10000 bees is worth 10, not 10000 - `sort`: when filtering out already-established temples in the location assignment screen, also filter out the "No specific deity" option if a non-denominational temple has already been established +- RemoteServer: continue to accept connections as long as the listening socket is valid instead of closing the socket after the first disconnect ## Misc Improvements - `buildingplan`: display how many items are available on the planner panel diff --git a/library/RemoteServer.cpp b/library/RemoteServer.cpp index 77510d63a..72f2a29b5 100644 --- a/library/RemoteServer.cpp +++ b/library/RemoteServer.cpp @@ -51,6 +51,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "PassiveSocket.h" #include "PluginManager.h" #include "MiscUtils.h" +#include "Debug.h" #include #include @@ -85,6 +86,7 @@ namespace { } namespace DFHack { + DBG_DECLARE(core, socket, DebugCategory::LINFO); struct BlockGuard { std::lock_guard lock; @@ -476,17 +478,33 @@ void ServerMainImpl::threadFn(std::promise promise, int port) CActiveSocket *client = nullptr; try { - while ((client = server.socket.Accept()) != NULL) + for (int acceptFail = 0 ; server.socket.IsSocketValid() && acceptFail < 5 ; acceptFail++) { - BlockGuard lock; - ServerConnection::Accepted(client); - client = nullptr; + if ((client = server.socket.Accept()) != NULL) + { + BlockGuard lock; + ServerConnection::Accepted(client); + client = nullptr; + } + else + { + WARN(socket).print("Connection failure: %s (%d of %d)\n", server.socket.DescribeError(), acceptFail + 1, 5); + } } } catch(BlockedException &) { if (client) client->Close(); delete client; } + + 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"); + } } void ServerMain::block()