From 597f5478a20836fb25cbec4cc8e8c627e0f716a3 Mon Sep 17 00:00:00 2001 From: Patrick Donnelly Date: Tue, 13 May 2025 12:26:48 -0400 Subject: [PATCH] msg: add interface to shutdown Connection Unfortunately this doesn't work as-is because I couldn't find primitives to flush the out_queue. It's left as a to-do for now. Signed-off-by: Patrick Donnelly (cherry picked from commit 05e3b36fa2d877b2d7451ccda9ce6da73690ba50) --- src/mon/Monitor.cc | 3 +++ src/msg/Connection.h | 6 ++++++ src/msg/async/AsyncConnection.cc | 6 ++++++ src/msg/async/AsyncConnection.h | 1 + 4 files changed, 16 insertions(+) diff --git a/src/mon/Monitor.cc b/src/mon/Monitor.cc index 78d1e4fb3e2..46a5568836d 100644 --- a/src/mon/Monitor.cc +++ b/src/mon/Monitor.cc @@ -4188,6 +4188,9 @@ struct AnonConnection : public Connection { void mark_down() override { // silently ignore } + void shutdown() override { + // silengtly ignore + } void mark_disposable() override { // silengtly ignore } diff --git a/src/msg/Connection.h b/src/msg/Connection.h index 801d3fa200f..14d732973d3 100644 --- a/src/msg/Connection.h +++ b/src/msg/Connection.h @@ -157,6 +157,12 @@ public: */ virtual void mark_disposable() = 0; + /* + * Politely shutdown the connection. Finish sending any messages. This + * queues a connection reset event. + */ + virtual void shutdown() = 0; + // WARNING / FIXME: this is not populated for loopback connections AuthCapsInfo& get_peer_caps_info() { return peer_caps_info; diff --git a/src/msg/async/AsyncConnection.cc b/src/msg/async/AsyncConnection.cc index 2f247535dea..3eea7ba80e4 100644 --- a/src/msg/async/AsyncConnection.cc +++ b/src/msg/async/AsyncConnection.cc @@ -759,6 +759,12 @@ void AsyncConnection::stop(bool queue_reset) { if (need_queue_reset) dispatch_queue->queue_reset(this); } +void AsyncConnection::shutdown() +{ + /* FIXME: stop() discards out queue so this doesn't actually flush sent messages */ + return stop(true); +} + void AsyncConnection::cleanup() { shutdown_socket(); delete read_handler; diff --git a/src/msg/async/AsyncConnection.h b/src/msg/async/AsyncConnection.h index 553c6a1bff1..53b8dfd5fd6 100644 --- a/src/msg/async/AsyncConnection.h +++ b/src/msg/async/AsyncConnection.h @@ -235,6 +235,7 @@ private: void process(); void wakeup_from(uint64_t id); void tick(uint64_t id); + void shutdown() override; void stop(bool queue_reset); void cleanup(); PerfCounters *get_perf_counter() { -- 2.39.5