From b3f1e56d6c89e0b07b7b6091651e1b7ff36a3468 Mon Sep 17 00:00:00 2001 From: Yingxin Cheng Date: Wed, 7 Aug 2019 22:36:28 +0800 Subject: [PATCH] crimson/net: is_queued() to check if there's any pending writes Signed-off-by: Yingxin Cheng --- src/crimson/net/Protocol.cc | 6 +++--- src/crimson/net/Protocol.h | 6 ++++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/crimson/net/Protocol.cc b/src/crimson/net/Protocol.cc index 65bfe2d1b79..4e53c7bfbdc 100644 --- a/src/crimson/net/Protocol.cc +++ b/src/crimson/net/Protocol.cc @@ -100,7 +100,7 @@ seastar::future Protocol::do_write_dispatch_sweep() case write_state_t::open: { size_t num_msgs = conn.out_q.size(); // we must have something to write... - ceph_assert(num_msgs || need_keepalive || keepalive_ack.has_value()); + ceph_assert(is_queued()); MessageRef front_msg; if (likely(num_msgs)) { front_msg = conn.out_q.front(); @@ -118,10 +118,10 @@ seastar::future Protocol::do_write_dispatch_sweep() // and the out_q was not reset during socket write conn.out_q.erase(conn.out_q.begin(), conn.out_q.begin()+num_msgs); } - if (conn.out_q.empty() && !keepalive_ack.has_value()) { + if (!is_queued()) { // good, we have nothing pending to send now. return socket->flush().then([this] { - if (conn.out_q.empty() && !need_keepalive && !keepalive_ack.has_value()) { + if (!is_queued()) { // still nothing pending to send after flush, // the dispatching can ONLY stop now ceph_assert(write_dispatching); diff --git a/src/crimson/net/Protocol.h b/src/crimson/net/Protocol.h index c65ddc7e6a1..fe3598f19d4 100644 --- a/src/crimson/net/Protocol.h +++ b/src/crimson/net/Protocol.h @@ -84,6 +84,12 @@ class Protocol { void notify_keepalive_ack(utime_t keepalive_ack); + bool is_queued() const { + return (!conn.out_q.empty() || + need_keepalive || + keepalive_ack.has_value()); + } + private: write_state_t write_state = write_state_t::none; // wait until current state changed -- 2.39.5