| 640 | } |
| 641 | |
| 642 | int CNetMessage::readData(const char *pch, unsigned int nBytes) |
| 643 | { |
| 644 | unsigned int nRemaining = hdr.nMessageSize - nDataPos; |
| 645 | unsigned int nCopy = std::min(nRemaining, nBytes); |
| 646 | |
| 647 | if (vRecv.size() < nDataPos + nCopy) { |
| 648 | // Allocate up to 256 KiB ahead, but never more than the total message size. |
| 649 | vRecv.resize(std::min(hdr.nMessageSize, nDataPos + nCopy + 256 * 1024)); |
| 650 | } |
| 651 | |
| 652 | memcpy(&vRecv[nDataPos], pch, nCopy); |
| 653 | nDataPos += nCopy; |
| 654 | |
| 655 | return nCopy; |
| 656 | } |
| 657 | |
| 658 | |
| 659 |
no test coverage detected