| 818 | |
| 819 | |
| 820 | int 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 | |
| 851 | int CNetMessage::readData(const char *pch, unsigned int nBytes) |
| 852 | { |
no test coverage detected