diff options
author | Patric Stout <truebrain@openttd.org> | 2021-05-13 08:13:48 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-13 08:13:48 +0200 |
commit | d7ce61f10674567c97a1edd78ea1baf4e08153f2 (patch) | |
tree | d8709dad58e6be2a36ba6f3ec1685b8ee31c64ca /src/network/core/tcp.h | |
parent | 38c97e14926f4bc538c20b24f8a3decdef1668f9 (diff) | |
download | openttd-d7ce61f10674567c97a1edd78ea1baf4e08153f2.tar.xz |
Fix #9255: [Network] TCPConnecter crashes when hostname not found (#9259)
Diffstat (limited to 'src/network/core/tcp.h')
-rw-r--r-- | src/network/core/tcp.h | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/src/network/core/tcp.h b/src/network/core/tcp.h index 46e3af8c6..44316bfca 100644 --- a/src/network/core/tcp.h +++ b/src/network/core/tcp.h @@ -66,8 +66,22 @@ public: */ class TCPConnecter { private: + /** + * The current status of the connecter. + * + * We track the status like this to ensure everything is executed from the + * game-thread, and not at another random time where we might not have the + * lock on the game-state. + */ + enum class Status { + INIT, ///< TCPConnecter is created but resolving hasn't started. + RESOLVING, ///< The hostname is being resolved (threaded). + FAILURE, ///< Resolving failed. + CONNECTING, ///< We are currently connecting. + }; + std::thread resolve_thread; ///< Thread used during resolving. - std::atomic<bool> is_resolved = false; ///< Whether resolving is done. + std::atomic<Status> status = Status::INIT; ///< The current status of the connecter. addrinfo *ai = nullptr; ///< getaddrinfo() allocated linked-list of resolved addresses. std::vector<addrinfo *> addresses; ///< Addresses we can connect to. |