mirror of
https://github.com/kvazar-network/kevacoin.git
synced 2025-01-11 15:48:05 +00:00
Allocate receive buffers in on the fly
This commit is contained in:
parent
aaacfa0898
commit
806fd19ecb
@ -678,7 +678,6 @@ int CNetMessage::readHeader(const char *pch, unsigned int nBytes)
|
|||||||
|
|
||||||
// switch state to reading message data
|
// switch state to reading message data
|
||||||
in_data = true;
|
in_data = true;
|
||||||
vRecv.resize(hdr.nMessageSize);
|
|
||||||
|
|
||||||
return nCopy;
|
return nCopy;
|
||||||
}
|
}
|
||||||
@ -688,6 +687,11 @@ int CNetMessage::readData(const char *pch, unsigned int nBytes)
|
|||||||
unsigned int nRemaining = hdr.nMessageSize - nDataPos;
|
unsigned int nRemaining = hdr.nMessageSize - nDataPos;
|
||||||
unsigned int nCopy = std::min(nRemaining, nBytes);
|
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);
|
memcpy(&vRecv[nDataPos], pch, nCopy);
|
||||||
nDataPos += nCopy;
|
nDataPos += nCopy;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user