MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / GetNetMsg

Method GetNetMsg

src/test/util/net.cpp:286–322  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

284}
285
286std::optional<CNetMessage> DynSock::Pipe::GetNetMsg()
287{
288 V1Transport transport{NodeId{0}};
289
290 {
291 WAIT_LOCK(m_mutex, lock);
292
293 WaitForDataOrEof(lock);
294 if (m_eof && m_data.empty()) {
295 return std::nullopt;
296 }
297
298 for (;;) {
299 std::span<const uint8_t> s{m_data};
300 if (!transport.ReceivedBytes(s)) { // Consumed bytes are removed from the front of s.
301 return std::nullopt;
302 }
303 m_data.erase(m_data.begin(), m_data.begin() + m_data.size() - s.size());
304 if (transport.ReceivedMessageComplete()) {
305 break;
306 }
307 if (m_data.empty()) {
308 WaitForDataOrEof(lock);
309 if (m_eof && m_data.empty()) {
310 return std::nullopt;
311 }
312 }
313 }
314 }
315
316 bool reject{false};
317 CNetMessage msg{transport.GetReceivedMessage(/*time=*/{}, reject)};
318 if (reject) {
319 return std::nullopt;
320 }
321 return std::make_optional<CNetMessage>(std::move(msg));
322}
323
324void DynSock::Pipe::PushBytes(const void* buf, size_t len)
325{

Callers

nothing calls this directly

Calls 7

ReceivedBytesMethod · 0.80
GetReceivedMessageMethod · 0.80
emptyMethod · 0.45
eraseMethod · 0.45
beginMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected