mirror of
https://github.com/BeamMP/BeamMP-Launcher.git
synced 2025-07-02 16:06:35 +00:00
- fixed IPC timeout on inactivity
This commit is contained in:
parent
4a4204932d
commit
58e9fef53f
@ -14,7 +14,7 @@ class BeamNG {
|
||||
public:
|
||||
static void EntryPoint();
|
||||
static void SendIPC(const std::string& Data);
|
||||
|
||||
static inline bool Terminate = false;
|
||||
private:
|
||||
static inline std::unique_ptr<Hook<def::update_function>> UpdateDetour;
|
||||
static inline std::unique_ptr<Hook<def::lua_open_jit>> OpenJITDetour;
|
||||
|
@ -6,6 +6,7 @@
|
||||
#include "Memory/BeamNG.h"
|
||||
#include "Memory/Memory.h"
|
||||
#include "atomic_queue.h"
|
||||
#include <csignal>
|
||||
|
||||
std::unique_ptr<atomic_queue<std::string, 1000>> RCVQueue, SendQueue;
|
||||
|
||||
@ -28,7 +29,16 @@ uint64_t BeamNG::update_D(lua_State* State) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
void SignalHandler(int sig) {
|
||||
Memory::Print( "Got termination signal (" + std::to_string(sig) +")");
|
||||
BeamNG::Terminate = true;
|
||||
}
|
||||
|
||||
void BeamNG::EntryPoint() {
|
||||
signal(SIGINT, SignalHandler);
|
||||
signal(SIGTERM, SignalHandler);
|
||||
signal(SIGABRT, SignalHandler);
|
||||
signal(SIGBREAK, SignalHandler);
|
||||
RCVQueue = std::make_unique<atomic_queue<std::string, 1000>>();
|
||||
SendQueue = std::make_unique<atomic_queue<std::string, 1000>>();
|
||||
uint32_t PID = Memory::GetPID();
|
||||
@ -102,30 +112,25 @@ void BeamNG::SendIPC(const std::string& Data) {
|
||||
}
|
||||
|
||||
void BeamNG::IPCListener() {
|
||||
int TimeOuts = 0;
|
||||
while (TimeOuts < 20) {
|
||||
while (!Terminate) {
|
||||
IPCFromLauncher->receive();
|
||||
if (!IPCFromLauncher->receive_timed_out()) {
|
||||
TimeOuts = 0;
|
||||
RCVQueue->push(IPCFromLauncher->msg());
|
||||
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) {
|
||||
std::string result;
|
||||
int TimeOuts = 0;
|
||||
while (TimeOuts < 20) {
|
||||
while (!Terminate) {
|
||||
if (SendQueue->try_pop(result)) {
|
||||
IPCToLauncher->send(result);
|
||||
if (!IPCToLauncher->send_timed_out()) TimeOuts = 0;
|
||||
else TimeOuts++;
|
||||
} else {
|
||||
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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user