]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
msg/async, v2: rework the class hierarchy - introduce MessageFrame.
authorRadoslaw Zarzynski <rzarzyns@redhat.com>
Mon, 4 Mar 2019 21:43:03 +0000 (22:43 +0100)
committerRadoslaw Zarzynski <rzarzyns@redhat.com>
Sat, 9 Mar 2019 23:44:34 +0000 (00:44 +0100)
Signed-off-by: Radoslaw Zarzynski <rzarzyns@redhat.com>
src/msg/async/ProtocolV2.cc
src/msg/async/frames_v2.h

index b57ba66e1838ca339cb37363d951a61d8a0ecefc..bdb32c27e01203c04b8612db136e4162263ec8dc 100644 (file)
@@ -497,7 +497,7 @@ ssize_t ProtocolV2::write_message(Message *m, bool more) {
                            footer.flags,      header.compat_version,
                            header.reserved};
 
-  auto message = MessageHeaderFrame::Encode(session_stream_handlers,
+  auto message = MessageFrame::Encode(session_stream_handlers,
                             header2,
                             m->get_payload(),
                             m->get_middle(),
@@ -1290,7 +1290,7 @@ CtPtr ProtocolV2::handle_message() {
 #endif
   recv_stamp = ceph_clock_now();
 
-  auto header_frame = MessageHeaderFrame::Decode(
+  auto header_frame = MessageFrame::Decode(
     std::move(rx_segments_data[SegmentIndex::Msg::HEADER]));
   // XXX: paranoid copy just to avoid oops
   ceph_msg_header2 current_header = header_frame.header();
index 6d709bf50c512be02d4f4f4cc7735688bdd66215..41d2826bfbb0ed2e344ff1836ec54ff2ef6ede91 100644 (file)
@@ -646,22 +646,27 @@ protected:
 // This class is used for encoding/decoding header of the message frame.
 // Body is processed almost independently with the sole junction point
 // being the `extra_payload_len` passed to get_buffer().
-struct MessageHeaderFrame
-    : public ControlFrame<MessageHeaderFrame, ceph_msg_header2> {
+struct MessageFrame
+    : public Frame<MessageFrame, 4 /* four segments */> {
   static const Tag tag = Tag::MESSAGE;
 
+  ceph::bufferlist &get_payload_segment() {
+    return this->segments[SegmentIndex::Msg::HEADER];
+  }
+
   ceph::bufferlist &get_buffer() {
     // In contrast to Frame::get_buffer() we don't fill preamble here.
     return this->get_payload_segment();
   }
 
-  static MessageHeaderFrame Encode(ceph::crypto::onwire::rxtx_t &session_stream_handlers,
-                                   const ceph_msg_header2 &msg_header,
-                                   const ceph::bufferlist& front,
-                                   const ceph::bufferlist& middle,
-                                   const ceph::bufferlist& data) {
-    MessageHeaderFrame f =
-        ControlFrame<MessageHeaderFrame, ceph_msg_header2>::Encode(msg_header);
+  static MessageFrame Encode(ceph::crypto::onwire::rxtx_t &session_stream_handlers,
+                             const ceph_msg_header2 &msg_header,
+                             const ceph::bufferlist& front,
+                             const ceph::bufferlist& middle,
+                             const ceph::bufferlist& data) {
+    MessageFrame f;
+    f.segments[SegmentIndex::Msg::HEADER].append(
+        reinterpret_cast<const char*>(&msg_header), sizeof(msg_header));
 
     f.fill_preamble({
       segment_t{ f.get_payload_segment().length() - FRAME_PREAMBLE_SIZE,
@@ -736,16 +741,19 @@ struct MessageHeaderFrame
     return f;
   }
 
-  static MessageHeaderFrame Decode(ceph::bufferlist&& text) {
-    MessageHeaderFrame f;
-    f.decode_frame(text);
+  static MessageFrame Decode(ceph::bufferlist&& text) {
+    MessageFrame f;
+    f.segments[SegmentIndex::Msg::HEADER] = std::move(text);
     return f;
   }
 
-  inline ceph_msg_header2 &header() { return get_val<0>(); }
+  inline const ceph_msg_header2 &header() {
+    auto& hdrbl = segments[SegmentIndex::Msg::HEADER];
+    return reinterpret_cast<const ceph_msg_header2&>(*hdrbl.c_str());
+  }
 
 protected:
-  using ControlFrame::ControlFrame;
+  using Frame::Frame;
 };
 
 } // namespace ceph::msgr::v2