[IPCHandler] Only run worker for the first instance

This commit is contained in:
momo5502 2017-01-29 11:02:29 +01:00
parent 7a9bda58c2
commit adedc4088f

View File

@ -20,6 +20,7 @@ namespace Components
void IPCHandler::SendWorker(std::string message, std::string data) void IPCHandler::SendWorker(std::string message, std::string data)
{ {
IPCHandler::InitChannels(); IPCHandler::InitChannels();
if (!Singleton::IsFirstInstance()) return;
Proto::IPC::Command command; Proto::IPC::Command command;
command.set_name(message); command.set_name(message);
@ -50,11 +51,14 @@ namespace Components
} }
void IPCHandler::InitChannels() void IPCHandler::InitChannels()
{
if (Singleton::IsFirstInstance())
{ {
if (!IPCHandler::WorkerChannel) if (!IPCHandler::WorkerChannel)
{ {
IPCHandler::WorkerChannel.reset(new Utils::IPC::BidirectionalChannel("IW4x-Worker-Channel", !Worker::IsWorker())); IPCHandler::WorkerChannel.reset(new Utils::IPC::BidirectionalChannel("IW4x-Worker-Channel", !Worker::IsWorker()));
} }
}
if (!IPCHandler::ClientChannel) if (!IPCHandler::ClientChannel)
{ {
@ -64,6 +68,8 @@ namespace Components
void IPCHandler::StartWorker() void IPCHandler::StartWorker()
{ {
if (!Singleton::IsFirstInstance()) return;
STARTUPINFOA sInfo; STARTUPINFOA sInfo;
PROCESS_INFORMATION pInfo; PROCESS_INFORMATION pInfo;
@ -99,6 +105,7 @@ namespace Components
void IPCHandler::HandleWorker() void IPCHandler::HandleWorker()
{ {
IPCHandler::InitChannels(); IPCHandler::InitChannels();
if (!Singleton::IsFirstInstance()) return;
std::string packet; std::string packet;
if (IPCHandler::WorkerChannel->receive(&packet)) if (IPCHandler::WorkerChannel->receive(&packet))