| 609 | } |
| 610 | |
| 611 | int 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 | |
| 642 | int CNetMessage::readData(const char *pch, unsigned int nBytes) |
| 643 | { |
no test coverage detected