Use list instead of vector for clients

This commit is contained in:
Joshua Ashton 2020-07-29 15:34:10 +01:00
parent 5abdafc614
commit c2b100428d
5 changed files with 13 additions and 5 deletions

View File

@ -27,9 +27,9 @@ namespace Feather
clients.emplace_back(std::move(client)); clients.emplace_back(std::move(client));
} }
void DedicatedServer::OnClientDisconnect(Network::TCPClient& client) void DedicatedServer::OnClientDisconnect(const Network::TCPClient& client)
{ {
auto [clients, lock] = m_clients.borrow(); auto [clients, lock] = m_clients.borrow();
//clients.erase(std::remove(clients.begin(), clients.end(), client), clients.end()); clients.remove(client);
} }
} }

View File

@ -15,13 +15,13 @@ namespace Feather
~DedicatedServer(); ~DedicatedServer();
void OnClientConnect(Network::TCPClient&& client) override; void OnClientConnect(Network::TCPClient&& client) override;
void OnClientDisconnect(Network::TCPClient& client) override; void OnClientDisconnect(const Network::TCPClient& client) override;
private: private:
ServerProperties* m_properties; ServerProperties* m_properties;
Network::TCPListener m_listener; Network::TCPListener m_listener;
Network::ServerStatus m_status; Network::ServerStatus m_status;
LockableVector<Network::TCPClient> m_clients; LockableList<Network::TCPClient> m_clients;
}; };
} }

View File

@ -2,6 +2,7 @@
#include <mutex> #include <mutex>
#include <vector> #include <vector>
#include <list>
namespace Feather namespace Feather
{ {
@ -18,4 +19,7 @@ namespace Feather
template <typename T> template <typename T>
using LockableVector = Lockable<std::vector<T>>; using LockableVector = Lockable<std::vector<T>>;
template <typename T>
using LockableList = Lockable<std::list<T>>;
} }

View File

@ -10,6 +10,6 @@ namespace Feather::Network
{ {
public: public:
virtual void OnClientConnect(TCPClient&& client) = 0; virtual void OnClientConnect(TCPClient&& client) = 0;
virtual void OnClientDisconnect(TCPClient& client) = 0; virtual void OnClientDisconnect(const TCPClient& client) = 0;
}; };
} }

View File

@ -24,6 +24,10 @@ namespace Feather::Network
private: private:
std::unique_ptr<TCPListenerClient> m_client; std::unique_ptr<TCPListenerClient> m_client;
}; };
// TODO: Can we eliminate the move constructor + overloads?
// Kinda unclean.
inline bool operator==(const TCPClient& a, const TCPClient& b) { return &a == &b; }
inline bool operator!=(const TCPClient& a, const TCPClient& b) { return &a != &b; }
class TCPListener class TCPListener
{ {