Skip to content

Commit

Permalink
Merge pull request #4381
Browse files Browse the repository at this point in the history
806fd19 Allocate receive buffers in on the fly (Pieter Wuille)
  • Loading branch information
sipa committed Jun 22, 2014
2 parents 8f59251 + 806fd19 commit 6b40eab
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;

Expand Down

0 comments on commit 6b40eab

Please sign in to comment.