Skip to content

Commit d77993b

Browse files
authoredApr 9, 2024··
fix: client crashes a program after destructor is called (#14)
Co-authored-by: kirkezz <iamkirkezz@gmail.com>
1 parent 763a6af commit d77993b

File tree

2 files changed

+2
-7
lines changed

2 files changed

+2
-7
lines changed
 

‎include/rconpp/client.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <vector>
1717
#include <iostream>
1818
#include <cstring>
19+
#include <atomic>
1920
#include <thread>
2021
#include <condition_variable>
2122
#include "utilities.h"
@@ -44,7 +45,7 @@ class RCONPP_EXPORT rcon_client {
4445
std::thread queue_runner;
4546

4647
public:
47-
bool connected{false};
48+
std::atomic<bool> connected{false};
4849

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

‎src/rconpp/client.cpp

-6
Original file line numberDiff line numberDiff line change
@@ -241,10 +241,6 @@ void rconpp::rcon_client::start(bool return_after) {
241241
}
242242

243243
for (const queued_request& request : requests_queued) {
244-
// If we're closing the connection down, we need to back out.
245-
if(!connected)
246-
return;
247-
248244
// Send data to callback if it's been set.
249245
if (request.callback)
250246
request.callback(send_data_sync(request.data, request.id, request.type));
@@ -256,8 +252,6 @@ void rconpp::rcon_client::start(bool return_after) {
256252
}
257253
});
258254

259-
queue_runner.detach();
260-
261255
if(!return_after) {
262256
block_calling_thread();
263257
}

1 commit comments

Comments
 (1)

artemka-sh commented on Nov 16, 2024

@artemka-sh

Thank you for this library! I used it in my discord bot to update information about the online game servers of the project

Please sign in to comment.