Skip to content

Commit

Permalink
fix: client crashes a program after destructor is called (#14)
Browse files Browse the repository at this point in the history
Co-authored-by: kirkezz <iamkirkezz@gmail.com>
  • Loading branch information
Kirkezz and kirkezz committed Apr 9, 2024
1 parent 763a6af commit d77993b
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 7 deletions.
3 changes: 2 additions & 1 deletion include/rconpp/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <vector>
#include <iostream>
#include <cstring>
#include <atomic>
#include <thread>
#include <condition_variable>
#include "utilities.h"
Expand Down Expand Up @@ -44,7 +45,7 @@ class RCONPP_EXPORT rcon_client {
std::thread queue_runner;

public:
bool connected{false};
std::atomic<bool> connected{false};

std::function<void(const std::string_view& log)> on_log;

Expand Down
6 changes: 0 additions & 6 deletions src/rconpp/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,6 @@ void rconpp::rcon_client::start(bool return_after) {
}

for (const queued_request& request : requests_queued) {
// If we're closing the connection down, we need to back out.
if(!connected)
return;

// Send data to callback if it's been set.
if (request.callback)
request.callback(send_data_sync(request.data, request.id, request.type));
Expand All @@ -256,8 +252,6 @@ void rconpp::rcon_client::start(bool return_after) {
}
});

queue_runner.detach();

if(!return_after) {
block_calling_thread();
}
Expand Down

0 comments on commit d77993b

Please sign in to comment.