fix: determine connection id in network thread, see #33
Dieser Commit ist enthalten in:
Ursprung
cdac489b11
Commit
1e9ef650c2
@ -31,20 +31,10 @@
|
||||
#define IS_SERVER_THREAD (std::this_thread::get_id() == m_server.threadId())
|
||||
#endif
|
||||
|
||||
std::string connectionId(const boost::asio::ip::tcp::socket& socket)
|
||||
{
|
||||
return
|
||||
std::string("connection[")
|
||||
.append(socket.remote_endpoint().address().to_string())
|
||||
.append(":")
|
||||
.append(std::to_string(socket.remote_endpoint().port()))
|
||||
.append("]");
|
||||
}
|
||||
|
||||
Connection::Connection(Server& server, std::unique_ptr<boost::asio::ip::tcp::socket> socket)
|
||||
Connection::Connection(Server& server, std::unique_ptr<boost::asio::ip::tcp::socket> socket, std::string id)
|
||||
: m_server{server}
|
||||
, m_socket(std::move(socket))
|
||||
, m_id{connectionId(*m_socket)}
|
||||
, m_id{std::move(id)}
|
||||
, m_authenticated{false}
|
||||
{
|
||||
assert(isEventLoopThread());
|
||||
|
||||
@ -62,7 +62,7 @@ class Connection : public std::enable_shared_from_this<Connection>
|
||||
void connectionLost();
|
||||
|
||||
public:
|
||||
Connection(Server& server, std::unique_ptr<boost::asio::ip::tcp::socket> socket);
|
||||
Connection(Server& server, std::unique_ptr<boost::asio::ip::tcp::socket> socket, std::string id);
|
||||
virtual ~Connection();
|
||||
|
||||
void disconnect();
|
||||
|
||||
@ -207,12 +207,18 @@ void Server::doAccept()
|
||||
{
|
||||
if(!ec)
|
||||
{
|
||||
const auto connectionId = std::string("connection[")
|
||||
.append(m_socketTCP->remote_endpoint().address().to_string())
|
||||
.append(":")
|
||||
.append(std::to_string(m_socketTCP->remote_endpoint().port()))
|
||||
.append("]");
|
||||
|
||||
EventLoop::call(
|
||||
[this]()
|
||||
[this, connectionId]()
|
||||
{
|
||||
try
|
||||
{
|
||||
m_connections.emplace_back(std::make_shared<Connection>(*this, std::move(m_socketTCP)));
|
||||
m_connections.emplace_back(std::make_shared<Connection>(*this, std::move(m_socketTCP), connectionId));
|
||||
}
|
||||
catch(const std::exception& e)
|
||||
{
|
||||
|
||||
Laden…
x
In neuem Issue referenzieren
Einen Benutzer sperren