commit
0e608b2844
@ -25,15 +25,6 @@ cSocket::cSocket(xSocket a_Socket)
|
||||
|
||||
|
||||
|
||||
cSocket::~cSocket()
|
||||
{
|
||||
// Do NOT close the socket; this class is an API wrapper, not a RAII!
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
cSocket::operator cSocket::xSocket() const
|
||||
{
|
||||
return m_Socket;
|
||||
|
@ -41,7 +41,6 @@ public:
|
||||
|
||||
cSocket(void) : m_Socket(INVALID_SOCKET) {}
|
||||
cSocket(xSocket a_Socket);
|
||||
~cSocket();
|
||||
|
||||
bool IsValid(void) const { return IsValidSocket(m_Socket); }
|
||||
void CloseSocket(void);
|
||||
|
10
src/Root.cpp
10
src/Root.cpp
@ -30,8 +30,6 @@
|
||||
#include <mach/mach.h>
|
||||
#endif
|
||||
|
||||
extern bool g_TERMINATE_EVENT_RAISED;
|
||||
|
||||
|
||||
|
||||
|
||||
@ -79,7 +77,7 @@ void cRoot::InputThread(void * a_Params)
|
||||
|
||||
cLogCommandOutputCallback Output;
|
||||
|
||||
while (!self.m_bStop && !self.m_bRestart && !g_TERMINATE_EVENT_RAISED && std::cin.good())
|
||||
while (!self.m_bStop && !self.m_bRestart && !m_TerminateEventRaised && std::cin.good())
|
||||
{
|
||||
AString Command;
|
||||
std::getline(std::cin, Command);
|
||||
@ -89,7 +87,7 @@ void cRoot::InputThread(void * a_Params)
|
||||
}
|
||||
}
|
||||
|
||||
if (g_TERMINATE_EVENT_RAISED || !std::cin.good())
|
||||
if (m_TerminateEventRaised || !std::cin.good())
|
||||
{
|
||||
// We have come here because the std::cin has received an EOF / a terminate signal has been sent, and the server is still running; stop the server:
|
||||
self.m_bStop = true;
|
||||
@ -205,12 +203,12 @@ void cRoot::Start(void)
|
||||
EnableMenuItem(hmenu, SC_CLOSE, MF_ENABLED); // Re-enable close button
|
||||
#endif
|
||||
|
||||
while (!m_bStop && !m_bRestart && !g_TERMINATE_EVENT_RAISED) // These are modified by external threads
|
||||
while (!m_bStop && !m_bRestart && !m_TerminateEventRaised) // These are modified by external threads
|
||||
{
|
||||
cSleep::MilliSleep(1000);
|
||||
}
|
||||
|
||||
if (g_TERMINATE_EVENT_RAISED)
|
||||
if (m_TerminateEventRaised)
|
||||
{
|
||||
m_bStop = true;
|
||||
}
|
||||
|
@ -40,6 +40,8 @@ namespace Json
|
||||
class cRoot
|
||||
{
|
||||
public:
|
||||
static bool m_TerminateEventRaised;
|
||||
|
||||
static cRoot * Get() { return s_Root; }
|
||||
// tolua_end
|
||||
|
||||
|
14
src/main.cpp
14
src/main.cpp
@ -11,9 +11,9 @@
|
||||
#include <dbghelp.h>
|
||||
#endif // _MSC_VER
|
||||
|
||||
// Here, we have some ALL CAPS variables, to give the impression that this is deeeep, gritty programming :P
|
||||
bool g_TERMINATE_EVENT_RAISED = false; // If something has told the server to stop; checked periodically in cRoot
|
||||
bool g_SERVER_TERMINATED = false; // Set to true when the server terminates, so our CTRL handler can then tell Windows to close the console
|
||||
|
||||
bool cRoot::m_TerminateEventRaised = false; // If something has told the server to stop; checked periodically in cRoot
|
||||
static bool g_ServerTerminated = false; // Set to true when the server terminates, so our CTRL handler can then tell the OS to close the console
|
||||
|
||||
|
||||
|
||||
@ -52,7 +52,7 @@ bool g_ShouldLogCommOut;
|
||||
void NonCtrlHandler(int a_Signal)
|
||||
{
|
||||
LOGD("Terminate event raised from std::signal");
|
||||
g_TERMINATE_EVENT_RAISED = true;
|
||||
cRoot::m_TerminateEventRaised = true;
|
||||
|
||||
switch (a_Signal)
|
||||
{
|
||||
@ -155,12 +155,12 @@ LONG WINAPI LastChanceExceptionFilter(__in struct _EXCEPTION_POINTERS * a_Except
|
||||
// Handle CTRL events in windows, including console window close
|
||||
BOOL CtrlHandler(DWORD fdwCtrlType)
|
||||
{
|
||||
g_TERMINATE_EVENT_RAISED = true;
|
||||
cRoot::m_TerminateEventRaised = true;
|
||||
LOGD("Terminate event raised from the Windows CtrlHandler");
|
||||
|
||||
if (fdwCtrlType == CTRL_CLOSE_EVENT) // Console window closed via 'x' button, Windows will try to close immediately, therefore...
|
||||
{
|
||||
while (!g_SERVER_TERMINATED) { cSleep::MilliSleep(100); } // Delay as much as possible to try to get the server to shut down cleanly
|
||||
while (!g_ServerTerminated) { cSleep::MilliSleep(100); } // Delay as much as possible to try to get the server to shut down cleanly
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
@ -296,7 +296,7 @@ int main( int argc, char **argv )
|
||||
DeinitLeakFinder();
|
||||
#endif
|
||||
|
||||
g_SERVER_TERMINATED = true;
|
||||
g_ServerTerminated = true;
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user