MCPcopy Create free account
hub / github.com/bitcoinxt/bitcoinxt / readHeader

Method readHeader

src/net.cpp:611–640  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

609}
610
611int CNetMessage::readHeader(const char *pch, unsigned int nBytes)
612{
613 // copy data to temporary parsing buffer
614 unsigned int nRemaining = 24 - nHdrPos;
615 unsigned int nCopy = std::min(nRemaining, nBytes);
616
617 memcpy(&hdrbuf[nHdrPos], pch, nCopy);
618 nHdrPos += nCopy;
619
620 // if header incomplete, exit
621 if (nHdrPos < 24)
622 return nCopy;
623
624 // deserialize to CMessageHeader
625 try {
626 hdrbuf >> hdr;
627 }
628 catch (const std::exception&) {
629 return -1;
630 }
631
632 // reject messages larger than MAX_SIZE
633 if (hdr.nMessageSize > MAX_SIZE)
634 return -1;
635
636 // switch state to reading message data
637 in_data = true;
638
639 return nCopy;
640}
641
642int CNetMessage::readData(const char *pch, unsigned int nBytes)
643{

Callers 1

ReceiveMsgBytesMethod · 0.80

Calls 1

memcpyFunction · 0.85

Tested by

no test coverage detected