Skip to content

Commit fae6790

Browse files
author
MarcoFalke
committed
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}); ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 parent fabb7c4 commit fae6790

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/net.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,22 @@ struct AddedNodeInfo
9999
class CNodeStats;
100100
class CClientUIInterface;
101101

102-
struct CSerializedNetMsg
103-
{
102+
struct CSerializedNetMsg {
104103
CSerializedNetMsg() = default;
105104
CSerializedNetMsg(CSerializedNetMsg&&) = default;
106105
CSerializedNetMsg& operator=(CSerializedNetMsg&&) = default;
107-
// No copying, only moves.
106+
// No implicit copying, only moves.
108107
CSerializedNetMsg(const CSerializedNetMsg& msg) = delete;
109108
CSerializedNetMsg& operator=(const CSerializedNetMsg&) = delete;
110109

110+
CSerializedNetMsg Copy() const
111+
{
112+
CSerializedNetMsg copy;
113+
copy.data = data;
114+
copy.m_type = m_type;
115+
return copy;
116+
}
117+
111118
std::vector<unsigned char> data;
112119
std::string m_type;
113120
};

src/net_processing.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1624,7 +1624,7 @@ void PeerManagerImpl::NewPoWValidBlock(const CBlockIndex *pindex, const std::sha
16241624
hashBlock.ToString(), pnode->GetId());
16251625

16261626
const CSerializedNetMsg& ser_cmpctblock{lazy_ser.get()};
1627-
m_connman.PushMessage(pnode, CSerializedNetMsg{ser_cmpctblock.data, ser_cmpctblock.m_type});
1627+
m_connman.PushMessage(pnode, ser_cmpctblock.Copy());
16281628
state.pindexBestHeaderSent = pindex;
16291629
}
16301630
});

0 commit comments

Comments
 (0)