From 8fb922e8c61a72b967ae37c69c09640897455dc3 Mon Sep 17 00:00:00 2001 From: zhangwen <3466561528@qq.com> Date: Wed, 15 Oct 2025 13:36:31 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E4=BA=86=E8=AE=BE=E5=A4=87?= =?UTF-8?q?=E7=9A=84=E7=A7=BB=E9=99=A4=E6=9C=BA=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LFtid1056/client2.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/LFtid1056/client2.cpp b/LFtid1056/client2.cpp index a507cd6..412be7b 100644 --- a/LFtid1056/client2.cpp +++ b/LFtid1056/client2.cpp @@ -73,7 +73,7 @@ void ClientContext::stop_timers() { void ClientContext::close_handles() { if (!uv_is_closing((uv_handle_t*)&client)) { - uv_close((uv_handle_t*)&client, nullptr); + uv_close((uv_handle_t*)&client, on_close); } if (!uv_is_closing((uv_handle_t*)&timer)) { uv_close((uv_handle_t*)&timer, nullptr); @@ -775,8 +775,19 @@ void ClientManager::remove_device(const std::string& device_id) { return; } - // 关闭连接并移除 + auto& ctx = it->second; it->second->shutdown = true; + + // 确保所有定时器都停止 + ctx->stop_timers(); + { + std::lock_guard state_lock(ctx->state_mutex_); + std::queue empty; + std::swap(ctx->action_queue_, empty); + ctx->current_state_ = DeviceState::IDLE; + } + + // 关闭连接并移除 it->second->close_handles(); clients_.erase(it); std::cout << "[Device " << device_id << "] Removed successfully\n";