diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index bc36c7ff..6d330f7b 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -2,6 +2,10 @@ All changes to this project will be documented in this file. +## [11.0.1] - 2020-11-11 + +(socket) replace a std::vector with an std::array used as a tmp buffer in Socket::readBytes + ## [11.0.0] - 2020-11-11 (openssl security fix) in the client to server connection, peer verification is not done in all cases. See https://github.com/machinezone/IXWebSocket/pull/250 diff --git a/ixwebsocket/IXSocket.cpp b/ixwebsocket/IXSocket.cpp index 46fc1018..bccfe7d9 100644 --- a/ixwebsocket/IXSocket.cpp +++ b/ixwebsocket/IXSocket.cpp @@ -11,6 +11,7 @@ #include "IXSelectInterruptFactory.h" #include "IXSocketConnect.h" #include +#include #include #include #include @@ -18,6 +19,7 @@ #include #include #include +#include #ifdef min #undef min @@ -27,7 +29,6 @@ namespace ix { const int Socket::kDefaultPollNoTimeout = -1; // No poll timeout by default const int Socket::kDefaultPollTimeout = kDefaultPollNoTimeout; - constexpr size_t Socket::kChunkSize; Socket::Socket(int fd) : _sockfd(fd) @@ -364,10 +365,7 @@ namespace ix const OnProgressCallback& onProgressCallback, const CancellationRequest& isCancellationRequested) { - if (_readBuffer.empty()) - { - _readBuffer.resize(kChunkSize); - } + std::array readBuffer; std::vector output; while (output.size() != length) @@ -378,12 +376,12 @@ namespace ix return std::make_pair(false, errorMsg); } - size_t size = std::min(kChunkSize, length - output.size()); - ssize_t ret = recv((char*) &_readBuffer[0], size); + size_t size = std::min(readBuffer.size(), length - output.size()); + ssize_t ret = recv((char*) &readBuffer[0], size); if (ret > 0) { - output.insert(output.end(), _readBuffer.begin(), _readBuffer.begin() + ret); + output.insert(output.end(), readBuffer.begin(), readBuffer.begin() + ret); } else if (ret <= 0 && !Socket::isWaitNeeded()) { diff --git a/ixwebsocket/IXSocket.h b/ixwebsocket/IXSocket.h index e27e2752..4538d63b 100644 --- a/ixwebsocket/IXSocket.h +++ b/ixwebsocket/IXSocket.h @@ -11,7 +11,6 @@ #include #include #include -#include #ifdef _WIN32 #include @@ -102,10 +101,6 @@ namespace ix static const int kDefaultPollTimeout; static const int kDefaultPollNoTimeout; - // Buffer for reading from our socket. That buffer is never resized. - std::vector _readBuffer; - static constexpr size_t kChunkSize = 1 << 15; - SelectInterruptPtr _selectInterrupt; }; } // namespace ix diff --git a/ixwebsocket/IXWebSocketVersion.h b/ixwebsocket/IXWebSocketVersion.h index 3ad641aa..431fcd06 100644 --- a/ixwebsocket/IXWebSocketVersion.h +++ b/ixwebsocket/IXWebSocketVersion.h @@ -6,4 +6,4 @@ #pragma once -#define IX_WEBSOCKET_VERSION "11.0.0" +#define IX_WEBSOCKET_VERSION "11.0.1"