Merge pull request #4381

806fd19 Allocate receive buffers in on the fly (Pieter Wuille)
This commit is contained in:
Pieter Wuille 2014-06-22 17:42:01 +02:00
commit 6b40eabbcf
No known key found for this signature in database
GPG key ID: 8F653255C87992E0

View file

@ -678,7 +678,6 @@ int CNetMessage::readHeader(const char *pch, unsigned int nBytes)
// switch state to reading message data
in_data = true;
vRecv.resize(hdr.nMessageSize);
return nCopy;
}
@ -688,6 +687,11 @@ int CNetMessage::readData(const char *pch, unsigned int nBytes)
unsigned int nRemaining = hdr.nMessageSize - nDataPos;
unsigned int nCopy = std::min(nRemaining, nBytes);
if (vRecv.size() < nDataPos + nCopy) {
// Allocate up to 256 KiB ahead, but never more than the total message size.
vRecv.resize(std::min(hdr.nMessageSize, nDataPos + nCopy + 256 * 1024));
}
memcpy(&vRecv[nDataPos], pch, nCopy);
nDataPos += nCopy;