summaryrefslogtreecommitdiff
path: root/src/network/core/tcp.h
diff options
context:
space:
mode:
authorPatric Stout <truebrain@openttd.org>2021-07-11 12:08:03 +0200
committerPatric Stout <github@truebrain.nl>2021-07-11 20:38:42 +0200
commit1baec41542780cf4fc898df7d2fc9925d823fb44 (patch)
tree57aa8bc38997fc9d39a4ae66af7b912712e1830e /src/network/core/tcp.h
parentcee8174d02e38542548fc74de93450cfebefaa91 (diff)
downloadopenttd-1baec41542780cf4fc898df7d2fc9925d823fb44.tar.xz
Change: groundwork to allow ServerAddress to use invite codes
Normally TCPConnecter will do a DNS resolving of the connection_string and connect to it. But for SERVER_ADDRESS_INVITE_CODE this is different: the Game Coordinator does the "resolving". This means we need to allow TCPConnecter to not setup a connection and allow it to be told when a connection has been setup by an external (to TCPConnecter) part of the code. We do this by telling the (active) socket for the connection. This means the rest of the code doesn't need to know the TCPConnecter is not doing a simple resolve+connect. The rest of the code only cares the connection is established; not how it was established.
Diffstat (limited to 'src/network/core/tcp.h')
-rw-r--r--src/network/core/tcp.h14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/network/core/tcp.h b/src/network/core/tcp.h
index 379ef8b92..bbd0bc2a9 100644
--- a/src/network/core/tcp.h
+++ b/src/network/core/tcp.h
@@ -82,10 +82,12 @@ private:
RESOLVING, ///< The hostname is being resolved (threaded).
FAILURE, ///< Resolving failed.
CONNECTING, ///< We are currently connecting.
+ CONNECTED, ///< The connection is established.
};
std::thread resolve_thread; ///< Thread used during resolving.
std::atomic<Status> status = Status::INIT; ///< The current status of the connecter.
+ std::atomic<bool> killed = false; ///< Whether this connecter is marked as killed.
addrinfo *ai = nullptr; ///< getaddrinfo() allocated linked-list of resolved addresses.
std::vector<addrinfo *> addresses; ///< Addresses we can connect to.
@@ -101,7 +103,7 @@ private:
void OnResolved(addrinfo *ai);
bool TryNextAddress();
void Connect(addrinfo *address);
- bool CheckActivity();
+ virtual bool CheckActivity();
/* We do not want any other derived classes from this class being able to
* access these private members, but it is okay for TCPServerConnecter. */
@@ -125,15 +127,25 @@ public:
*/
virtual void OnFailure() {}
+ void Kill();
+
static void CheckCallbacks();
static void KillAll();
};
class TCPServerConnecter : public TCPConnecter {
+private:
+ SOCKET socket = INVALID_SOCKET; ///< The socket when a connection is established.
+
+ bool CheckActivity() override;
+
public:
ServerAddress server_address; ///< Address we are connecting to.
TCPServerConnecter(const std::string &connection_string, uint16 default_port);
+
+ void SetConnected(SOCKET sock);
+ void SetFailure();
};
#endif /* NETWORK_CORE_TCP_H */