From: Radoslaw Zarzynski Date: Fri, 8 Mar 2019 04:11:04 +0000 (+0100) Subject: msg/async, v2: rx continuations use buffer::ptr_node. X-Git-Tag: v14.2.0~23^2~14 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=367bba9b5b1aed6e310b5308d29fedb3da6e85bc;p=ceph.git msg/async, v2: rx continuations use buffer::ptr_node. Signed-off-by: Radoslaw Zarzynski --- diff --git a/src/msg/async/Protocol.h b/src/msg/async/Protocol.h index 556c9ef1470..cccba183567 100644 --- a/src/msg/async/Protocol.h +++ b/src/msg/async/Protocol.h @@ -46,24 +46,18 @@ public: } }; -using rx_buffer_t = ceph::bufferptr; -// FIXME: std::function in AsyncConnection requires us to be copy- -// constructible just in the case - even if nobody actually copies -// the std::functions there. This inhibits usage of unique_ptr of -// ptr_node inside. Reworking the callback mechanism might help but -// for now we can go with regular bptr. -// -// std::unique_ptr; +using rx_buffer_t = + std::unique_ptr; template class CtRxNode : public Ct { using fn_t = Ct *(C::*)(rx_buffer_t&&, int r); fn_t _f; +public: mutable rx_buffer_t node; int r; -public: CtRxNode(fn_t f) : _f(f) {} void setParams(rx_buffer_t &&node, int r) { this->node = std::move(node); diff --git a/src/msg/async/ProtocolV2.cc b/src/msg/async/ProtocolV2.cc index 4f810fd962d..9d7ce00facd 100644 --- a/src/msg/async/ProtocolV2.cc +++ b/src/msg/async/ProtocolV2.cc @@ -717,16 +717,17 @@ CtPtr ProtocolV2::read(CONTINUATION_RX_TYPE &next, CtPtr ProtocolV2::read(CONTINUATION_RXBPTR_TYPE &next, rx_buffer_t &&buffer) { - const auto len = buffer.length(); - const auto buf = buffer.c_str(); + const auto len = buffer->length(); + const auto buf = buffer->c_str(); + next.node = std::move(buffer); ssize_t r = connection->read(len, buf, - [&next, this, bufnode = std::move(buffer)](char *buffer, int r) mutable { - next.setParams(std::move(bufnode), r); + [&next, this](char *buffer, int r) { + next.r = r; run_continuation(next); }); if (r <= 0) { // error or done synchronously - next.setParams(rx_buffer_t(), r); + next.r = r; return &next; } @@ -1098,8 +1099,8 @@ CtPtr ProtocolV2::read_frame_segment() { const auto& cur_rx_desc = rx_segments_desc.at(rx_segments_data.size()); rx_buffer_t rx_buffer; try { - rx_buffer = buffer::create_aligned( - get_onwire_size(cur_rx_desc.length), cur_rx_desc.alignment); + rx_buffer = buffer::ptr_node::create(buffer::create_aligned( + get_onwire_size(cur_rx_desc.length), cur_rx_desc.alignment)); } catch (std::bad_alloc&) { // Catching because of potential issues with satisfying alignment. ldout(cct, 20) << __func__ << " can't allocate aligned rx_buffer "