mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 01:58:19 +00:00
handle SIGINT in server to properly shutdown everything
This commit is contained in:
parent
ca07c0a92f
commit
eecd13476c
|
@ -48,6 +48,10 @@
|
|||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#include <signal.h>
|
||||
|
||||
volatile bool InterruptSignaled = false;
|
||||
|
||||
CSnapIDPool::CSnapIDPool()
|
||||
{
|
||||
Reset();
|
||||
|
@ -2714,6 +2718,11 @@ int CServer::Run()
|
|||
|
||||
PacketWaiting = x > 0 ? net_socket_read_wait(m_NetServer.Socket(), x) : true;
|
||||
}
|
||||
if(InterruptSignaled)
|
||||
{
|
||||
Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", "interrupted");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
const char *pDisconnectReason = "Server shutdown";
|
||||
|
@ -3596,6 +3605,11 @@ void CServer::SnapSetStaticsize(int ItemType, int Size)
|
|||
|
||||
static CServer *CreateServer() { return new CServer(); }
|
||||
|
||||
void HandleSigInt(int Param)
|
||||
{
|
||||
InterruptSignaled = true;
|
||||
}
|
||||
|
||||
int main(int argc, const char **argv) // ignore_convention
|
||||
{
|
||||
cmdline_fix(&argc, &argv);
|
||||
|
@ -3624,6 +3638,8 @@ int main(int argc, const char **argv) // ignore_convention
|
|||
return -1;
|
||||
}
|
||||
|
||||
signal(SIGINT, HandleSigInt);
|
||||
|
||||
CServer *pServer = CreateServer();
|
||||
IKernel *pKernel = IKernel::Create();
|
||||
|
||||
|
|
Loading…
Reference in a new issue