mirror of
https://github.com/qicosmos/rest_rpc.git
synced 2026-08-29 08:34:47 +08:00
fix close
This commit is contained in:
@@ -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_);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user