Permalink
Browse files

Allocate receive buffers in on the fl

  • Loading branch information...
Tranz5 committed Aug 15, 2014
1 parent 4bbc2be commit 9bedcab60c912aab11cd9b602d81aaabb9d1e7f4
Showing with 5 additions and 1 deletion.
  1. +5 −1 src/net.cpp
@@ -685,7 +685,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;
}
@@ -695,6 +694,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;

0 comments on commit 9bedcab

Please sign in to comment.