summaryrefslogtreecommitdiff
path: root/src/network/core
diff options
context:
space:
mode:
authorPatric Stout <truebrain@openttd.org>2021-05-05 23:21:14 +0200
committerGitHub <noreply@github.com>2021-05-05 23:21:14 +0200
commitf94fb9377910c63fc8e1ea0ede1d96603e4d8862 (patch)
tree9b8041b53749744b4df075520181294806332e07 /src/network/core
parentead30dc725c60cac8bc13c86d18b179dac684bec (diff)
downloadopenttd-f94fb9377910c63fc8e1ea0ede1d96603e4d8862.tar.xz
Codechange: use connection_string in favour of NetworkAddress (#9197)
We now resolve the connection_string to a NetworkAddress in a much later state. This means there are fewer places constructing a NetworkAddress. The main benefit of this is in later PRs that introduce different types of NetworkAddresses. Storing this in things like NetworkGameList is rather complex, especially as NetworkAddress has to be mutable at all times. Additionally, the NetworkAddress is a complex object to store simple information: how to connect to this server.
Diffstat (limited to 'src/network/core')
-rw-r--r--src/network/core/tcp.h2
-rw-r--r--src/network/core/tcp_connect.cpp10
-rw-r--r--src/network/core/tcp_http.cpp4
-rw-r--r--src/network/core/tcp_http.h16
4 files changed, 15 insertions, 17 deletions
diff --git a/src/network/core/tcp.h b/src/network/core/tcp.h
index ffa231497..5acf9d12e 100644
--- a/src/network/core/tcp.h
+++ b/src/network/core/tcp.h
@@ -77,7 +77,7 @@ protected:
NetworkAddress address;
public:
- TCPConnecter(const NetworkAddress &address);
+ TCPConnecter(const std::string &connection_string, uint16 default_port);
/** Silence the warnings */
virtual ~TCPConnecter() {}
diff --git a/src/network/core/tcp_connect.cpp b/src/network/core/tcp_connect.cpp
index b4485cfe9..81c4d8c26 100644
--- a/src/network/core/tcp_connect.cpp
+++ b/src/network/core/tcp_connect.cpp
@@ -13,6 +13,7 @@
#include "../../thread.h"
#include "tcp.h"
+#include "../network_internal.h"
#include "../../safeguards.h"
@@ -21,15 +22,16 @@ static std::vector<TCPConnecter *> _tcp_connecters;
/**
* Create a new connecter for the given address
- * @param address the (un)resolved address to connect to
+ * @param connection_string the address to connect to
*/
-TCPConnecter::TCPConnecter(const NetworkAddress &address) :
+TCPConnecter::TCPConnecter(const std::string &connection_string, uint16 default_port) :
connected(false),
aborted(false),
killed(false),
- sock(INVALID_SOCKET),
- address(address)
+ sock(INVALID_SOCKET)
{
+ this->address = ParseConnectionString(connection_string, default_port);
+
_tcp_connecters.push_back(this);
if (!StartNewThread(nullptr, "ottd:tcp", &TCPConnecter::ThreadEntry, this)) {
this->Connect();
diff --git a/src/network/core/tcp_http.cpp b/src/network/core/tcp_http.cpp
index 4f29df191..3b7579fce 100644
--- a/src/network/core/tcp_http.cpp
+++ b/src/network/core/tcp_http.cpp
@@ -203,11 +203,9 @@ int NetworkHTTPSocketHandler::HandleHeader()
*url = '\0';
- NetworkAddress address = ParseConnectionString(hname, 80);
-
/* Restore the URL. */
*url = '/';
- new NetworkHTTPContentConnecter(address, callback, url, data, depth);
+ new NetworkHTTPContentConnecter(hname, callback, url, data, depth);
return 0;
}
diff --git a/src/network/core/tcp_http.h b/src/network/core/tcp_http.h
index 1a1edaf87..cc9a3adac 100644
--- a/src/network/core/tcp_http.h
+++ b/src/network/core/tcp_http.h
@@ -81,16 +81,14 @@ class NetworkHTTPContentConnecter : TCPConnecter {
public:
/**
* Start the connecting.
- * @param address the address to connect to
- * @param callback the callback for HTTP retrieval
- * @param url the url at the server
- * @param data the data to send
- * @param depth the depth (redirect recursion) of the queries
+ * @param connection_string The address to connect to.
+ * @param callback The callback for HTTP retrieval.
+ * @param url The url at the server.
+ * @param data The data to send.
+ * @param depth The depth (redirect recursion) of the queries.
*/
- NetworkHTTPContentConnecter(const NetworkAddress &address,
- HTTPCallback *callback, const char *url,
- const char *data = nullptr, int depth = 0) :
- TCPConnecter(address),
+ NetworkHTTPContentConnecter(const std::string &connection_string, HTTPCallback *callback, const char *url, const char *data = nullptr, int depth = 0) :
+ TCPConnecter(connection_string, 80),
callback(callback),
url(stredup(url)),
data(data),