diff --git a/cpp/s2p/s2p_thread.cpp b/cpp/s2p/s2p_thread.cpp index 551c0365..2deb7257 100644 --- a/cpp/s2p/s2p_thread.cpp +++ b/cpp/s2p/s2p_thread.cpp @@ -44,20 +44,26 @@ bool S2pThread::IsRunning() const void S2pThread::Execute() const { + int fd = -1; while (server.IsRunning()) { - if (const int fd = server.Accept(); fd != -1) { - ExecuteCommand(fd); + if (fd == -1) { + fd = server.Accept(); + } + + if (fd != -1 && !ExecuteCommand(fd)) { close(fd); + fd = -1; } } } -void S2pThread::ExecuteCommand(int fd) const +bool S2pThread::ExecuteCommand(int fd) const { CommandContext context(fd, *s2p_logger); try { if (context.ReadCommand()) { exec(context); + return true; } } catch (const IoException &e) { @@ -73,4 +79,6 @@ void S2pThread::ExecuteCommand(int fd) const // Ignore } } + + return false; } diff --git a/cpp/s2p/s2p_thread.h b/cpp/s2p/s2p_thread.h index 5709cf7d..ac7dea28 100644 --- a/cpp/s2p/s2p_thread.h +++ b/cpp/s2p/s2p_thread.h @@ -34,7 +34,7 @@ class S2pThread private: void Execute() const; - void ExecuteCommand(int) const; + bool ExecuteCommand(int) const; callback exec;