Use more C++17 features
Mainly structured bindings, inline variables, and class template
argument deduction, plus many more smaller things.
Change-Id: I810d17e0adb470426e4e30c898e03b3140ad052f
diff --git a/daemon/face/lp-reassembler.cpp b/daemon/face/lp-reassembler.cpp
index 77a7120..a4b255b 100644
--- a/daemon/face/lp-reassembler.cpp
+++ b/daemon/face/lp-reassembler.cpp
@@ -45,8 +45,6 @@
{
BOOST_ASSERT(packet.has<lp::FragmentField>());
- static auto FALSE_RETURN = std::make_tuple(false, Block(), lp::Packet());
-
// read and check FragIndex and FragCount
uint64_t fragIndex = 0;
uint64_t fragCount = 1;
@@ -59,12 +57,12 @@
if (fragIndex >= fragCount) {
NFD_LOG_FACE_WARN("reassembly error, FragIndex>=FragCount: DROP");
- return FALSE_RETURN;
+ return {false, {}, {}};
}
if (fragCount > m_options.nMaxFragments) {
NFD_LOG_FACE_WARN("reassembly error, FragCount over limit: DROP");
- return FALSE_RETURN;
+ return {false, {}, {}};
}
// check for fast path
@@ -77,10 +75,11 @@
// check Sequence and compute message identifier
if (!packet.has<lp::SequenceField>()) {
NFD_LOG_FACE_WARN("reassembly error, Sequence missing: DROP");
- return FALSE_RETURN;
+ return {false, {}, {}};
}
+
lp::Sequence messageIdentifier = packet.get<lp::SequenceField>() - fragIndex;
- Key key = std::make_tuple(remoteEndpoint, messageIdentifier);
+ Key key(remoteEndpoint, messageIdentifier);
// add to PartialPacket
PartialPacket& pp = m_partialPackets[key];
@@ -92,13 +91,13 @@
else {
if (fragCount != pp.fragCount) {
NFD_LOG_FACE_WARN("reassembly error, FragCount changed: DROP");
- return FALSE_RETURN;
+ return {false, {}, {}};
}
}
if (pp.fragments[fragIndex].has<lp::SequenceField>()) {
NFD_LOG_FACE_TRACE("fragment already received: DROP");
- return FALSE_RETURN;
+ return {false, {}, {}};
}
pp.fragments[fragIndex] = packet;
@@ -109,13 +108,13 @@
Block reassembled = doReassembly(key);
lp::Packet firstFrag(std::move(pp.fragments[0]));
m_partialPackets.erase(key);
- return std::make_tuple(true, reassembled, firstFrag);
+ return {true, reassembled, firstFrag};
}
// set drop timer
pp.dropTimer = getScheduler().schedule(m_options.reassemblyTimeout, [=] { timeoutPartialPacket(key); });
- return FALSE_RETURN;
+ return {false, {}, {}};
}
Block
@@ -125,20 +124,16 @@
size_t payloadSize = std::accumulate(pp.fragments.begin(), pp.fragments.end(), 0U,
[&] (size_t sum, const lp::Packet& pkt) -> size_t {
- ndn::Buffer::const_iterator fragBegin, fragEnd;
- std::tie(fragBegin, fragEnd) = pkt.get<lp::FragmentField>();
+ auto [fragBegin, fragEnd] = pkt.get<lp::FragmentField>();
return sum + std::distance(fragBegin, fragEnd);
});
ndn::Buffer fragBuffer(payloadSize);
auto it = fragBuffer.begin();
-
for (const lp::Packet& frag : pp.fragments) {
- ndn::Buffer::const_iterator fragBegin, fragEnd;
- std::tie(fragBegin, fragEnd) = frag.get<lp::FragmentField>();
+ auto [fragBegin, fragEnd] = frag.get<lp::FragmentField>();
it = std::copy(fragBegin, fragEnd, it);
}
-
return Block(fragBuffer);
}