delete extra IPC thread, update simple-ipc
This commit is contained in:
parent
89bf29f17d
commit
d643b133cc
@ -1 +1 @@
|
||||
Subproject commit 94b3e53b00ac5be465ebe44ea5fe1b1fbc18aa8f
|
||||
Subproject commit 98934e7579ac276ba1a1972db3e1eb741c789068
|
@ -427,6 +427,9 @@ void FrameStageNotify_hook(void* _this, int stage) {
|
||||
static Timer ipc_timer {};
|
||||
if (ipc_timer.test_and_set(1000)) {
|
||||
if (ipc::peer) {
|
||||
if (ipc::peer->HasCommands()) {
|
||||
ipc::peer->ProcessCommands();
|
||||
}
|
||||
ipc::Heartbeat();
|
||||
ipc::UpdateTemporaryData();
|
||||
}
|
||||
|
21
src/ipc.cpp
21
src/ipc.cpp
@ -16,19 +16,6 @@
|
||||
|
||||
namespace ipc {
|
||||
|
||||
std::atomic<bool> thread_running(false);
|
||||
pthread_t listener_thread { 0 };
|
||||
|
||||
void* listen(void*) {
|
||||
while (thread_running) {
|
||||
if (peer->HasCommands()) {
|
||||
peer->ProcessCommands();
|
||||
}
|
||||
usleep(10000);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
CatCommand fix_deadlock("ipc_fix_deadlock", "Fix deadlock", []() {
|
||||
if (peer) {
|
||||
pthread_mutex_unlock(&peer->memory->mutex);
|
||||
@ -36,7 +23,7 @@ CatCommand fix_deadlock("ipc_fix_deadlock", "Fix deadlock", []() {
|
||||
});
|
||||
|
||||
CatCommand connect("ipc_connect", "Connect to IPC server", []() {
|
||||
if (peer || thread_running) {
|
||||
if (peer) {
|
||||
logging::Info("Already connected!");
|
||||
return;
|
||||
}
|
||||
@ -60,8 +47,6 @@ CatCommand connect("ipc_connect", "Connect to IPC server", []() {
|
||||
data.total_score = o_total_score;
|
||||
StoreClientData();
|
||||
Heartbeat();
|
||||
thread_running = true;
|
||||
pthread_create(&listener_thread, nullptr, listen, nullptr);
|
||||
} catch (std::exception& error) {
|
||||
logging::Info("Runtime error: %s", error.what());
|
||||
delete peer;
|
||||
@ -83,10 +68,7 @@ CatCommand lobby("ipc_lobby", "Join a lobby", [](const CCommand& args) {
|
||||
peer->SendMessage(format("connect_lobby ", lobby64).c_str(), 0, ipc::commands::execute_client_cmd, 0, 0);
|
||||
});
|
||||
CatCommand disconnect("ipc_disconnect", "Disconnect from IPC server", []() {
|
||||
thread_running = false;
|
||||
pthread_join(listener_thread, nullptr);
|
||||
if (peer) delete peer;
|
||||
listener_thread = 0;
|
||||
peer = nullptr;
|
||||
});
|
||||
CatCommand exec("ipc_exec", "Execute command (first argument = bot ID)", [](const CCommand& args) {
|
||||
@ -163,7 +145,6 @@ void UpdateServerAddress(bool shutdown) {
|
||||
s_addr = g_IEngine->GetNetChannelInfo()->GetAddress();
|
||||
}
|
||||
|
||||
peer_t::MutexLock lock(peer);
|
||||
user_data_s& data = peer->memory->peer_user_data[peer->client_id];
|
||||
data.friendid = g_ISteamUser->GetSteamID().GetAccountID();
|
||||
strncpy(data.server, s_addr, sizeof(data.server));
|
||||
|
Reference in New Issue
Block a user