Merge branch 'master' into jgrpp
# Conflicts: # src/autoreplace_cmd.cpp # src/company_base.h # src/company_gui.cpp # src/cpu.cpp # src/debug.h # src/group.h # src/group_cmd.cpp # src/house.h # src/industry.h # src/newgrf_house.cpp # src/news_type.h # src/openttd.cpp # src/saveload/company_sl.cpp # src/settings_type.h # src/sl/oldloader_sl.cpp # src/story.cpp # src/table/town_land.h # src/viewport.cpp
This commit is contained in:
@@ -113,6 +113,8 @@ private:
|
||||
NetworkAddress bind_address; ///< Address we're binding to, if any.
|
||||
int family = AF_UNSPEC; ///< Family we are using to connect with.
|
||||
|
||||
static std::vector<std::shared_ptr<TCPConnecter>> connecters; ///< List of connections that are currently being created.
|
||||
|
||||
void Resolve();
|
||||
void OnResolved(addrinfo *ai);
|
||||
bool TryNextAddress();
|
||||
@@ -145,6 +147,18 @@ public:
|
||||
|
||||
static void CheckCallbacks();
|
||||
static void KillAll();
|
||||
|
||||
/**
|
||||
* Create the connecter, and initiate connecting by putting it in the collection of TCP connections to make.
|
||||
* @tparam T The type of connecter to create.
|
||||
* @param args The arguments to the constructor of T.
|
||||
* @return Shared pointer to the connecter.
|
||||
*/
|
||||
template <class T, typename... Args>
|
||||
static std::shared_ptr<TCPConnecter> Create(Args&& ... args)
|
||||
{
|
||||
return TCPConnecter::connecters.emplace_back(std::make_shared<T>(std::forward<Args>(args)...));
|
||||
}
|
||||
};
|
||||
|
||||
class TCPServerConnecter : public TCPConnecter {
|
||||
|
@@ -19,8 +19,7 @@
|
||||
|
||||
#include "../../safeguards.h"
|
||||
|
||||
/** List of connections that are currently being created */
|
||||
static std::vector<TCPConnecter *> _tcp_connecters;
|
||||
/* static */ std::vector<std::shared_ptr<TCPConnecter>> TCPConnecter::connecters;
|
||||
|
||||
/**
|
||||
* Create a new connecter for the given address.
|
||||
@@ -33,8 +32,6 @@ TCPConnecter::TCPConnecter(const std::string &connection_string, uint16_t defaul
|
||||
family(family)
|
||||
{
|
||||
this->connection_string = NormalizeConnectionString(connection_string, default_port);
|
||||
|
||||
_tcp_connecters.push_back(this);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -58,8 +55,6 @@ TCPServerConnecter::TCPServerConnecter(const std::string &connection_string, uin
|
||||
default:
|
||||
NOT_REACHED();
|
||||
}
|
||||
|
||||
_tcp_connecters.push_back(this);
|
||||
}
|
||||
|
||||
TCPConnecter::~TCPConnecter()
|
||||
@@ -469,24 +464,14 @@ void TCPServerConnecter::SetFailure()
|
||||
*/
|
||||
/* static */ void TCPConnecter::CheckCallbacks()
|
||||
{
|
||||
for (auto iter = _tcp_connecters.begin(); iter < _tcp_connecters.end(); /* nothing */) {
|
||||
TCPConnecter *cur = *iter;
|
||||
|
||||
if (cur->CheckActivity()) {
|
||||
iter = _tcp_connecters.erase(iter);
|
||||
delete cur;
|
||||
} else {
|
||||
iter++;
|
||||
}
|
||||
}
|
||||
TCPConnecter::connecters.erase(
|
||||
std::remove_if(TCPConnecter::connecters.begin(), TCPConnecter::connecters.end(),
|
||||
[](auto &connecter) { return connecter->CheckActivity(); }),
|
||||
TCPConnecter::connecters.end());
|
||||
}
|
||||
|
||||
/** Kill all connection attempts. */
|
||||
/* static */ void TCPConnecter::KillAll()
|
||||
{
|
||||
for (auto iter = _tcp_connecters.begin(); iter < _tcp_connecters.end(); /* nothing */) {
|
||||
TCPConnecter *cur = *iter;
|
||||
iter = _tcp_connecters.erase(iter);
|
||||
delete cur;
|
||||
}
|
||||
TCPConnecter::connecters.clear();
|
||||
}
|
||||
|
Reference in New Issue
Block a user