mirror of
https://github.com/SChernykh/p2pool.git
synced 2025-01-03 17:29:24 +00:00
Fix: always check before closing TCP handles
This commit is contained in:
parent
4c5144b37f
commit
14e26f5c17
2 changed files with 16 additions and 5 deletions
|
@ -216,8 +216,10 @@ void JSONRPCRequest::on_read(const char* data, size_t size)
|
||||||
|
|
||||||
void JSONRPCRequest::close()
|
void JSONRPCRequest::close()
|
||||||
{
|
{
|
||||||
uv_tcp_t* s = &m_socket;
|
uv_handle_t* h = reinterpret_cast<uv_handle_t*>(&m_socket);
|
||||||
uv_close(reinterpret_cast<uv_handle_t*>(s), on_close);
|
if (!uv_is_closing(h)) {
|
||||||
|
uv_close(h, on_close);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void JSONRPCRequest::on_close(uv_handle_t* handle)
|
void JSONRPCRequest::on_close(uv_handle_t* handle)
|
||||||
|
|
|
@ -385,10 +385,16 @@ void TCPServer<READ_BUF_SIZE, WRITE_BUF_SIZE>::close_sockets(bool listen_sockets
|
||||||
|
|
||||||
if (listen_sockets) {
|
if (listen_sockets) {
|
||||||
for (uv_tcp_t* s : m_listenSockets6) {
|
for (uv_tcp_t* s : m_listenSockets6) {
|
||||||
uv_close(reinterpret_cast<uv_handle_t*>(s), [](uv_handle_t* h) { delete reinterpret_cast<uv_tcp_t*>(h); });
|
uv_handle_t* h = reinterpret_cast<uv_handle_t*>(s);
|
||||||
|
if (!uv_is_closing(h)) {
|
||||||
|
uv_close(h, [](uv_handle_t* h) { delete reinterpret_cast<uv_tcp_t*>(h); });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
for (uv_tcp_t* s : m_listenSockets) {
|
for (uv_tcp_t* s : m_listenSockets) {
|
||||||
uv_close(reinterpret_cast<uv_handle_t*>(s), [](uv_handle_t* h) { delete reinterpret_cast<uv_tcp_t*>(h); });
|
uv_handle_t* h = reinterpret_cast<uv_handle_t*>(s);
|
||||||
|
if (!uv_is_closing(h)) {
|
||||||
|
uv_close(h, [](uv_handle_t* h) { delete reinterpret_cast<uv_tcp_t*>(h); });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -621,7 +627,10 @@ void TCPServer<READ_BUF_SIZE, WRITE_BUF_SIZE>::on_connect(uv_connect_t* req, int
|
||||||
LOGWARN(5, "failed to connect to " << static_cast<char*>(client->m_addrString) << ", error " << uv_err_name(status));
|
LOGWARN(5, "failed to connect to " << static_cast<char*>(client->m_addrString) << ", error " << uv_err_name(status));
|
||||||
}
|
}
|
||||||
server->on_connect_failed(client->m_isV6, client->m_addr, client->m_port);
|
server->on_connect_failed(client->m_isV6, client->m_addr, client->m_port);
|
||||||
uv_close(reinterpret_cast<uv_handle_t*>(&client->m_socket), nullptr);
|
uv_handle_t* h = reinterpret_cast<uv_handle_t*>(&client->m_socket);
|
||||||
|
if (!uv_is_closing(h)) {
|
||||||
|
uv_close(h, nullptr);
|
||||||
|
}
|
||||||
server->m_preallocatedClients.push_back(client);
|
server->m_preallocatedClients.push_back(client);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue