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

Method readHeader

src/net.cpp:820–849  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

818
819
820int CNetMessage::readHeader(const char *pch, unsigned int nBytes)
821{
822 // copy data to temporary parsing buffer
823 unsigned int nRemaining = 24 - nHdrPos;
824 unsigned int nCopy = std::min(nRemaining, nBytes);
825
826 memcpy(&hdrbuf[nHdrPos], pch, nCopy);
827 nHdrPos += nCopy;
828
829 // if header incomplete, exit
830 if (nHdrPos < 24)
831 return nCopy;
832
833 // deserialize to CMessageHeader
834 try {
835 hdrbuf >> hdr;
836 }
837 catch (const std::exception&) {
838 return -1;
839 }
840
841 // reject messages larger than MAX_SIZE
842 if (hdr.nMessageSize > MAX_SIZE)
843 return -1;
844
845 // switch state to reading message data
846 in_data = true;
847
848 return nCopy;
849}
850
851int CNetMessage::readData(const char *pch, unsigned int nBytes)
852{

Callers 1

ReceiveMsgBytesMethod · 0.80

Calls 1

memcpyFunction · 0.85

Tested by

no test coverage detected