mirror of
https://github.com/BeamMP/BeamMP-Launcher.git
synced 2026-06-22 08:31:07 +00:00
- fixed IPC timeout on inactivity
This commit is contained in:
@@ -14,7 +14,7 @@ class BeamNG {
|
|||||||
public:
|
public:
|
||||||
static void EntryPoint();
|
static void EntryPoint();
|
||||||
static void SendIPC(const std::string& Data);
|
static void SendIPC(const std::string& Data);
|
||||||
|
static inline bool Terminate = false;
|
||||||
private:
|
private:
|
||||||
static inline std::unique_ptr<Hook<def::update_function>> UpdateDetour;
|
static inline std::unique_ptr<Hook<def::update_function>> UpdateDetour;
|
||||||
static inline std::unique_ptr<Hook<def::lua_open_jit>> OpenJITDetour;
|
static inline std::unique_ptr<Hook<def::lua_open_jit>> OpenJITDetour;
|
||||||
|
|||||||
+15
-10
@@ -6,6 +6,7 @@
|
|||||||
#include "Memory/BeamNG.h"
|
#include "Memory/BeamNG.h"
|
||||||
#include "Memory/Memory.h"
|
#include "Memory/Memory.h"
|
||||||
#include "atomic_queue.h"
|
#include "atomic_queue.h"
|
||||||
|
#include <csignal>
|
||||||
|
|
||||||
std::unique_ptr<atomic_queue<std::string, 1000>> RCVQueue, SendQueue;
|
std::unique_ptr<atomic_queue<std::string, 1000>> RCVQueue, SendQueue;
|
||||||
|
|
||||||
@@ -28,7 +29,16 @@ uint64_t BeamNG::update_D(lua_State* State) {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SignalHandler(int sig) {
|
||||||
|
Memory::Print( "Got termination signal (" + std::to_string(sig) +")");
|
||||||
|
BeamNG::Terminate = true;
|
||||||
|
}
|
||||||
|
|
||||||
void BeamNG::EntryPoint() {
|
void BeamNG::EntryPoint() {
|
||||||
|
signal(SIGINT, SignalHandler);
|
||||||
|
signal(SIGTERM, SignalHandler);
|
||||||
|
signal(SIGABRT, SignalHandler);
|
||||||
|
signal(SIGBREAK, SignalHandler);
|
||||||
RCVQueue = std::make_unique<atomic_queue<std::string, 1000>>();
|
RCVQueue = std::make_unique<atomic_queue<std::string, 1000>>();
|
||||||
SendQueue = std::make_unique<atomic_queue<std::string, 1000>>();
|
SendQueue = std::make_unique<atomic_queue<std::string, 1000>>();
|
||||||
uint32_t PID = Memory::GetPID();
|
uint32_t PID = Memory::GetPID();
|
||||||
@@ -102,30 +112,25 @@ void BeamNG::SendIPC(const std::string& Data) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void BeamNG::IPCListener() {
|
void BeamNG::IPCListener() {
|
||||||
int TimeOuts = 0;
|
while (!Terminate) {
|
||||||
while (TimeOuts < 20) {
|
|
||||||
IPCFromLauncher->receive();
|
IPCFromLauncher->receive();
|
||||||
if (!IPCFromLauncher->receive_timed_out()) {
|
if (!IPCFromLauncher->receive_timed_out()) {
|
||||||
TimeOuts = 0;
|
|
||||||
RCVQueue->push(IPCFromLauncher->msg());
|
RCVQueue->push(IPCFromLauncher->msg());
|
||||||
IPCFromLauncher->confirm_receive();
|
IPCFromLauncher->confirm_receive();
|
||||||
} else TimeOuts++;
|
|
||||||
}
|
}
|
||||||
Memory::Print("IPC Listener System shutting down (timeout)");
|
}
|
||||||
|
Memory::Print("IPC Listener System shutting down (terminate)");
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t BeamNG::IPCSender(void* LP) {
|
uint32_t BeamNG::IPCSender(void* LP) {
|
||||||
std::string result;
|
std::string result;
|
||||||
int TimeOuts = 0;
|
while (!Terminate) {
|
||||||
while (TimeOuts < 20) {
|
|
||||||
if (SendQueue->try_pop(result)) {
|
if (SendQueue->try_pop(result)) {
|
||||||
IPCToLauncher->send(result);
|
IPCToLauncher->send(result);
|
||||||
if (!IPCToLauncher->send_timed_out()) TimeOuts = 0;
|
|
||||||
else TimeOuts++;
|
|
||||||
} else {
|
} else {
|
||||||
Sleep(1); //TODO look into possibly have it wake up on a new message instead
|
Sleep(1); //TODO look into possibly have it wake up on a new message instead
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Memory::Print("IPC Sender System shutting down (timeout)");
|
Memory::Print("IPC Sender System shutting down (terminate)");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user