fix close

This commit is contained in:
qicosmos
2025-10-09 16:48:40 +08:00
parent 09e5f1b708
commit c26fcfe033
3 changed files with 31 additions and 4 deletions
+1 -2
View File
@@ -51,7 +51,6 @@ public:
: socket_(std::move(socket)), conn_id_(conn_id), router_(router),
cross_ending_(cross_ending) {}
~rpc_connection() { close(); }
asio::awaitable<void> start() {
rest_rpc_header header;
auto self = this->shared_from_this();
@@ -164,7 +163,7 @@ public:
std::error_code ec;
socket_.shutdown(asio::socket_base::shutdown_both, ec);
socket_.close(ec);
REST_LOG_INFO << "close socket " << need_cb;
REST_LOG_INFO << "close connection, id " << conn_id_;
if (need_cb && quit_cb_) {
quit_cb_(conn_id_);
}
+10 -2
View File
@@ -195,8 +195,16 @@ private:
auto mtx = weak.lock();
if (mtx) {
std::scoped_lock lock(*mtx);
if (!conns_.empty())
conns_.erase(id);
if (!conns_.empty()) {
std::erase_if(conns_, [id](const auto &pair) {
if (pair.first == id) {
pair.second->close(false);
return true;
}
return false;
});
}
}
});