diff options
Diffstat (limited to 'backends')
-rw-r--r-- | backends/networking/sdl_net/localwebserver.cpp | 13 | ||||
-rw-r--r-- | backends/networking/sdl_net/localwebserver.h | 2 |
2 files changed, 14 insertions, 1 deletions
diff --git a/backends/networking/sdl_net/localwebserver.cpp b/backends/networking/sdl_net/localwebserver.cpp index d6033d1db1..1cfbbb8819 100644 --- a/backends/networking/sdl_net/localwebserver.cpp +++ b/backends/networking/sdl_net/localwebserver.cpp @@ -69,6 +69,7 @@ void LocalWebserver::stopTimer() { } void LocalWebserver::start() { + _handleMutex.lock(); _stopOnIdle = false; if (_timerStarted) return; startTimer(); @@ -93,9 +94,11 @@ void LocalWebserver::start() { if (numused == -1) { error("SDLNet_AddSocket: %s\n", SDLNet_GetError()); } + _handleMutex.unlock(); } void LocalWebserver::stop() { + _handleMutex.lock(); if (_timerStarted) stopTimer(); if (_serverSocket) { @@ -112,6 +115,7 @@ void LocalWebserver::stop() { SDLNet_FreeSocketSet(_set); _set = nullptr; } + _handleMutex.unlock(); } void LocalWebserver::stopOnIdle() { _stopOnIdle = true; } @@ -129,6 +133,7 @@ void LocalWebserver::removePathHandler(Common::String path) { IndexPageHandler &LocalWebserver::indexPageHandler() { return _indexPageHandler; } void LocalWebserver::handle() { + _handleMutex.lock(); int numready = SDLNet_CheckSockets(_set, 0); if (numready == -1) { error("SDLNet_CheckSockets: %s\n", SDLNet_GetError()); @@ -145,7 +150,13 @@ void LocalWebserver::handle() { if (_clients == 0) ++_idlingFrames; else _idlingFrames = 0; - if (_idlingFrames > FRAMES_PER_SECOND && _stopOnIdle) stop(); + if (_idlingFrames > FRAMES_PER_SECOND && _stopOnIdle) { + _handleMutex.unlock(); + stop(); + return; + } + + _handleMutex.unlock(); } void LocalWebserver::handleClient(uint32 i) { diff --git a/backends/networking/sdl_net/localwebserver.h b/backends/networking/sdl_net/localwebserver.h index f51c33b418..2bd8daff5d 100644 --- a/backends/networking/sdl_net/localwebserver.h +++ b/backends/networking/sdl_net/localwebserver.h @@ -27,6 +27,7 @@ #include "backends/networking/sdl_net/indexpagehandler.h" #include "common/callback.h" #include "common/hash-str.h" +#include "common/mutex.h" #include "common/singleton.h" #include "common/scummsys.h" @@ -57,6 +58,7 @@ class LocalWebserver : public Common::Singleton<LocalWebserver> { Common::HashMap<Common::String, ClientHandler> _pathHandlers; IndexPageHandler _indexPageHandler; uint32 _idlingFrames; + Common::Mutex _handleMutex; void startTimer(int interval = TIMER_INTERVAL); void stopTimer(); |