From fe5770f500d30061a0b38798b4b4f7f4b6b7c4b2 Mon Sep 17 00:00:00 2001 From: Haomai Wang Date: Fri, 1 Jul 2016 23:44:46 +0800 Subject: [PATCH] msg/async/AsyncConnection: simplify shutdown socket flow Let cleanup resources things all in shutdown_socket Signed-off-by: Haomai Wang --- src/msg/async/AsyncConnection.cc | 7 +------ src/msg/async/AsyncConnection.h | 10 +++++++++- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/msg/async/AsyncConnection.cc b/src/msg/async/AsyncConnection.cc index 18d480da43df4..f2eb152e988eb 100644 --- a/src/msg/async/AsyncConnection.cc +++ b/src/msg/async/AsyncConnection.cc @@ -2180,12 +2180,7 @@ void AsyncConnection::fault() } write_lock.Lock(); - if (sd >= 0) { - shutdown_socket(); - center->delete_file_event(sd, EVENT_READABLE|EVENT_WRITABLE); - ::close(sd); - sd = -1; - } + shutdown_socket(); can_write = WriteStatus::NOWRITE; open_write = false; diff --git a/src/msg/async/AsyncConnection.h b/src/msg/async/AsyncConnection.h index 4b9205926f8a3..de81e6c5fcb9d 100644 --- a/src/msg/async/AsyncConnection.h +++ b/src/msg/async/AsyncConnection.h @@ -104,8 +104,16 @@ class AsyncConnection : public Connection { return !out_q.empty() || outcoming_bl.length(); } void shutdown_socket() { - if (sd >= 0) + for (auto &&t : register_time_events) + center->delete_time_event(t); + register_time_events.clear(); + center->delete_time_event(last_tick_id); + if (sd >= 0) { + center->delete_file_event(sd, EVENT_READABLE|EVENT_WRITABLE); ::shutdown(sd, SHUT_RDWR); + ::close(sd); + sd = -1; + } } Message *_get_next_outgoing(bufferlist *bl) { assert(write_lock.is_locked()); -- 2.39.5