diff options
author | MarcoFalke <falke.marco@gmail.com> | 2022-03-24 11:44:08 +0100 |
---|---|---|
committer | MarcoFalke <falke.marco@gmail.com> | 2022-03-24 11:37:34 +0100 |
commit | fae679065e4ef0c6383bbdd1876aaed6c1e40104 (patch) | |
tree | 2dc006d210f1a64e91f5c908509c8c4f953e94c1 /src | |
parent | fabb7c4ba629ecdea80a23674e2659d3d391565f (diff) | |
download | bitcoin-fae679065e4ef0c6383bbdd1876aaed6c1e40104.tar.xz |
Add CSerializedNetMsg::Copy() helper
This makes code that uses the helper less verbose.
Moreover, this makes net_processing C++20 compliant. Otherwise, it would
lead to a compile error (see below). C++20 disables aggregate
initialization when any constructor is declared. See
http://open-std.org/JTC1/SC22/WG21/docs/papers/2018/p1008r1.pdf
net_processing.cpp:1627:42: error: no matching constructor for initialization of 'CSerializedNetMsg'
m_connman.PushMessage(pnode, CSerializedNetMsg{ser_cmpctblock.data, ser_cmpctblock.m_type});
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Diffstat (limited to 'src')
-rw-r--r-- | src/net.h | 13 | ||||
-rw-r--r-- | src/net_processing.cpp | 2 |
2 files changed, 11 insertions, 4 deletions
@@ -99,15 +99,22 @@ struct AddedNodeInfo class CNodeStats; class CClientUIInterface; -struct CSerializedNetMsg -{ +struct CSerializedNetMsg { CSerializedNetMsg() = default; CSerializedNetMsg(CSerializedNetMsg&&) = default; CSerializedNetMsg& operator=(CSerializedNetMsg&&) = default; - // No copying, only moves. + // No implicit copying, only moves. CSerializedNetMsg(const CSerializedNetMsg& msg) = delete; CSerializedNetMsg& operator=(const CSerializedNetMsg&) = delete; + CSerializedNetMsg Copy() const + { + CSerializedNetMsg copy; + copy.data = data; + copy.m_type = m_type; + return copy; + } + std::vector<unsigned char> data; std::string m_type; }; diff --git a/src/net_processing.cpp b/src/net_processing.cpp index 77efac3364..34dd7991be 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -1624,7 +1624,7 @@ void PeerManagerImpl::NewPoWValidBlock(const CBlockIndex *pindex, const std::sha hashBlock.ToString(), pnode->GetId()); const CSerializedNetMsg& ser_cmpctblock{lazy_ser.get()}; - m_connman.PushMessage(pnode, CSerializedNetMsg{ser_cmpctblock.data, ser_cmpctblock.m_type}); + m_connman.PushMessage(pnode, ser_cmpctblock.Copy()); state.pindexBestHeaderSent = pindex; } }); |