]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
msg/msg_types: add entity_addrvec_t::legacy_addr() helper
authorSage Weil <sage@redhat.com>
Wed, 23 May 2018 16:45:57 +0000 (11:45 -0500)
committerSage Weil <sage@redhat.com>
Sun, 27 May 2018 22:26:25 +0000 (17:26 -0500)
Signed-off-by: Sage Weil <sage@redhat.com>
src/msg/msg_types.cc
src/msg/msg_types.h

index 525661e52d9b0ad4f3b183c12f501bea95138cd8..1b8b167fc7ce5d04c9196696eae6082519553dcf 100644 (file)
@@ -245,18 +245,7 @@ void entity_addrvec_t::encode(bufferlist& bl, uint64_t features) const
   using ceph::encode;
   if ((features & CEPH_FEATURE_MSG_ADDR2) == 0) {
     // encode a single legacy entity_addr_t for unfeatured peers
-    if (v.size() > 0) {
-      for (vector<entity_addr_t>::const_iterator p = v.begin();
-           p != v.end(); ++p) {
-        if ((*p).type == entity_addr_t::TYPE_LEGACY) {
-         encode(*p, bl, 0);
-         return;
-       }
-      }
-      encode(v[0], bl, 0);
-    } else {
-      encode(entity_addr_t(), bl, 0);
-    }
+    encode(legacy_addr(), bl, 0);
     return;
   }
   encode((__u8)2, bl);
index 07d69c480cf87be44f537f17b53f95838c3f2bd0..77f6c59642b7d4b986b2f5721ae9f57e9c12ebae 100644 (file)
@@ -535,6 +535,15 @@ struct entity_addrvec_t {
   unsigned size() const { return v.size(); }
   bool empty() const { return v.empty(); }
 
+  entity_addr_t legacy_addr() const {
+    for (auto& a : v) {
+      if (a.type == entity_addr_t::TYPE_LEGACY) {
+       return a;
+      }
+    }
+    return entity_addr_t();
+  }
+
   bool parse(const char *s, const char **end = 0);
 
   void encode(bufferlist& bl, uint64_t features) const;