summaryrefslogtreecommitdiff
path: root/src/network/core/tcp.h
diff options
context:
space:
mode:
authorPatric Stout <truebrain@openttd.org>2021-05-08 14:45:23 +0200
committerPatric Stout <github@truebrain.nl>2021-05-08 17:26:10 +0200
commit1b75a29d123db7aace2e8c2bf9c976e9ff8e89e3 (patch)
treedb650cc8ec079eefdae15c7afb2602507b901856 /src/network/core/tcp.h
parent664a8c3e85cef684610e0fa65fb2ea587e46232f (diff)
downloadopenttd-1b75a29d123db7aace2e8c2bf9c976e9ff8e89e3.tar.xz
Fix: destroying a TCPConnecter that was still resolving made illegal writes
Basically, we should join the resolve thread before we destruct the object.
Diffstat (limited to 'src/network/core/tcp.h')
-rw-r--r--src/network/core/tcp.h5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/network/core/tcp.h b/src/network/core/tcp.h
index 1eddec6a4..46e3af8c6 100644
--- a/src/network/core/tcp.h
+++ b/src/network/core/tcp.h
@@ -18,6 +18,7 @@
#include <atomic>
#include <chrono>
#include <map>
+#include <thread>
/** The states of sending the packets. */
enum SendPacketsState {
@@ -65,6 +66,9 @@ public:
*/
class TCPConnecter {
private:
+ std::thread resolve_thread; ///< Thread used during resolving.
+ std::atomic<bool> is_resolved = false; ///< Whether resolving is done.
+
addrinfo *ai = nullptr; ///< getaddrinfo() allocated linked-list of resolved addresses.
std::vector<addrinfo *> addresses; ///< Addresses we can connect to.
std::map<SOCKET, NetworkAddress> sock_to_address; ///< Mapping of a socket to the real address it is connecting to. USed for DEBUG statements.
@@ -73,7 +77,6 @@ private:
std::vector<SOCKET> sockets; ///< Pending connect() attempts.
std::chrono::steady_clock::time_point last_attempt; ///< Time we last tried to connect.
- std::atomic<bool> is_resolved = false; ///< Whether resolving is done.
std::string connection_string; ///< Current address we are connecting to (before resolving).
void Resolve();