aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPieter Wuille <pieter.wuille@gmail.com>2014-06-22 17:42:01 +0200
committerPieter Wuille <pieter.wuille@gmail.com>2014-06-22 17:43:40 +0200
commit6b40eabbcfe82ae3d890d9c6fd02d3d51aa1b977 (patch)
treef111b3c1b51dee27917198bbe44d537a3ec0bfa7 /src
parent8f59251b83cd9c862aee53dd50ce32bcab12ed6d (diff)
parent806fd19ecba0d58bf238a7b6f78e080da03eb9c7 (diff)
downloadbitcoin-6b40eabbcfe82ae3d890d9c6fd02d3d51aa1b977.tar.xz
Merge pull request #4381
806fd19 Allocate receive buffers in on the fly (Pieter Wuille)
Diffstat (limited to 'src')
-rw-r--r--src/net.cpp6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/net.cpp b/src/net.cpp
index 757a06aaed..707f58f8a6 100644
--- a/src/net.cpp
+++ b/src/net.cpp
@@ -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;