summaryrefslogtreecommitdiffstats
path: root/src/Root.cpp
diff options
context:
space:
mode:
authorpeterbell10 <peterbell10@live.co.uk>2017-09-12 08:41:39 +0200
committerAlexander Harkness <me@bearbin.net>2017-09-12 08:41:39 +0200
commit3ec9e6ec87e5db3fb7fcc7b6a6cd41219d41cf93 (patch)
treeccb65d78f91bdba0b21ce27a0db24473ffe078df /src/Root.cpp
parentReplace ItemCallbacks with lambdas (#3993) (diff)
downloadcuberite-3ec9e6ec87e5db3fb7fcc7b6a6cd41219d41cf93.tar
cuberite-3ec9e6ec87e5db3fb7fcc7b6a6cd41219d41cf93.tar.gz
cuberite-3ec9e6ec87e5db3fb7fcc7b6a6cd41219d41cf93.tar.bz2
cuberite-3ec9e6ec87e5db3fb7fcc7b6a6cd41219d41cf93.tar.lz
cuberite-3ec9e6ec87e5db3fb7fcc7b6a6cd41219d41cf93.tar.xz
cuberite-3ec9e6ec87e5db3fb7fcc7b6a6cd41219d41cf93.tar.zst
cuberite-3ec9e6ec87e5db3fb7fcc7b6a6cd41219d41cf93.zip
Diffstat (limited to 'src/Root.cpp')
-rw-r--r--src/Root.cpp36
1 files changed, 26 insertions, 10 deletions
diff --git a/src/Root.cpp b/src/Root.cpp
index 1de5d9b7c..9c92a10b9 100644
--- a/src/Root.cpp
+++ b/src/Root.cpp
@@ -82,11 +82,35 @@ cRoot::~cRoot()
void cRoot::InputThread(cRoot & a_Params)
{
cLogCommandOutputCallback Output;
+ AString Command;
while (a_Params.m_InputThreadRunFlag.test_and_set() && std::cin.good())
{
- AString Command;
+ #ifndef _WIN32
+ static const std::chrono::microseconds PollPeriod = std::chrono::milliseconds{ 100 };
+
+ timeval Timeout{ 0, 0 };
+ Timeout.tv_usec = PollPeriod.count();
+
+ fd_set ReadSet;
+ FD_ZERO(&ReadSet);
+ FD_SET(STDIN_FILENO, &ReadSet);
+
+ if (select(STDIN_FILENO + 1, &ReadSet, nullptr, nullptr, &Timeout) <= 0)
+ {
+ // Don't call getline because there's nothing to read
+ continue;
+ }
+ #endif
+
std::getline(std::cin, Command);
+
+ if (!a_Params.m_InputThreadRunFlag.test_and_set())
+ {
+ // Already shutting down, can't execute commands
+ break;
+ }
+
if (!Command.empty())
{
// Execute and clear command string when submitted
@@ -323,15 +347,7 @@ void cRoot::Start(std::unique_ptr<cSettingsRepositoryInterface> a_OverridesRepo)
m_InputThread.join();
}
#else
- if (m_InputThread.get_id() != std::thread::id())
- {
- if (pthread_kill(m_InputThread.native_handle(), SIGKILL) != 0)
- {
- LOGWARN("Couldn't notify the input thread; the server will hang before shutdown!");
- m_TerminateEventRaised = true;
- m_InputThread.detach();
- }
- }
+ m_InputThread.join();
#endif
if (m_TerminateEventRaised)