From 924fd4b7bd6ef91f37f3c3d0106719e2f7ee8cd8 Mon Sep 17 00:00:00 2001 From: SChernykh Date: Wed, 25 Aug 2021 13:58:00 +0200 Subject: [PATCH] TCPServer: better tracking of used sockets --- src/tcp_server.inl | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/tcp_server.inl b/src/tcp_server.inl index a87efc6..24c4dfd 100644 --- a/src/tcp_server.inl +++ b/src/tcp_server.inl @@ -143,6 +143,7 @@ void TCPServer::start_listening(const std::string LOGERR(1, "failed to create tcp server handle, error " << uv_err_name(err)); panic(); } + socket->data = this; err = uv_tcp_nodelay(socket, 1); if (err) { @@ -179,7 +180,6 @@ void TCPServer::start_listening(const std::string } } - socket->data = this; err = uv_listen(reinterpret_cast(socket), DEFAULT_BACKLOG, on_new_connection); if (err) { LOGERR(1, "failed to listen on tcp server socket, error " << uv_err_name(err)); @@ -325,6 +325,7 @@ bool TCPServer::connect_to_peer_nolock(Client* cl m_preallocatedClients.push_back(client); return false; } + client->m_socket.data = client; err = uv_tcp_nodelay(&client->m_socket, 1); if (err) { @@ -541,7 +542,9 @@ void TCPServer::on_connection_close(uv_handle_t* } } else { + LOGERR(5, "internal error: can't find TCPServer instance for peer " << log::Gray() << static_cast(client->m_addrString) << ", deallocating it"); client->reset(); + delete client; } } @@ -603,6 +606,8 @@ void TCPServer::on_new_client(uv_stream_t* server m_preallocatedClients.push_back(client); return; } + client->m_socket.data = client; + client->m_owner = this; err = uv_tcp_nodelay(&client->m_socket, 1); if (err) { @@ -633,9 +638,6 @@ void TCPServer::on_new_client_nolock(uv_stream_t* ++m_numConnections; client->m_isIncoming = false; - client->m_owner = this; - client->m_socket.data = client; - sockaddr_storage peer_addr; int peer_addr_len = static_cast(sizeof(peer_addr)); int err = uv_tcp_getpeername(&client->m_socket, reinterpret_cast(&peer_addr), &peer_addr_len);