diff --git a/ixwebsocket/IXWebSocketPerMessageDeflateCodec.cpp b/ixwebsocket/IXWebSocketPerMessageDeflateCodec.cpp index 913b9a04..d641c47c 100644 --- a/ixwebsocket/IXWebSocketPerMessageDeflateCodec.cpp +++ b/ixwebsocket/IXWebSocketPerMessageDeflateCodec.cpp @@ -16,8 +16,6 @@ namespace // is treated as a char* and the null termination (\x00) makes it // look like an empty string. const std::string kEmptyUncompressedBlock = std::string("\x00\x00\xff\xff", 4); - - const int kBufferSize = 1 << 14; } // namespace namespace ix @@ -26,7 +24,6 @@ namespace ix // Compressor // WebSocketPerMessageDeflateCompressor::WebSocketPerMessageDeflateCompressor() - : _compressBufferSize(kBufferSize) { #ifdef IXWEBSOCKET_USE_ZLIB memset(&_deflateState, 0, sizeof(_deflateState)); @@ -57,8 +54,6 @@ namespace ix if (ret != Z_OK) return false; - _compressBuffer = std::make_unique(_compressBufferSize); - _flush = (clientNoContextTakeOver) ? Z_FULL_FLUSH : Z_SYNC_FLUSH; return true; @@ -145,14 +140,14 @@ namespace ix do { // Output to local buffer - _deflateState.avail_out = (uInt) _compressBufferSize; - _deflateState.next_out = _compressBuffer.get(); + _deflateState.avail_out = (uInt) _compressBuffer.size(); + _deflateState.next_out = &_compressBuffer.front(); deflate(&_deflateState, _flush); - output = _compressBufferSize - _deflateState.avail_out; + output = _compressBuffer.size() - _deflateState.avail_out; - out.insert(out.end(), _compressBuffer.get(), _compressBuffer.get() + output); + out.insert(out.end(), _compressBuffer.begin(), _compressBuffer.begin() + output); } while (_deflateState.avail_out == 0); if (endsWithEmptyUnCompressedBlock(out)) @@ -170,7 +165,6 @@ namespace ix // Decompressor // WebSocketPerMessageDeflateDecompressor::WebSocketPerMessageDeflateDecompressor() - : _compressBufferSize(kBufferSize) { #ifdef IXWEBSOCKET_USE_ZLIB memset(&_inflateState, 0, sizeof(_inflateState)); @@ -198,8 +192,6 @@ namespace ix if (ret != Z_OK) return false; - _compressBuffer = std::make_unique(_compressBufferSize); - _flush = (clientNoContextTakeOver) ? Z_FULL_FLUSH : Z_SYNC_FLUSH; return true; @@ -232,8 +224,8 @@ namespace ix do { - _inflateState.avail_out = (uInt) _compressBufferSize; - _inflateState.next_out = _compressBuffer.get(); + _inflateState.avail_out = (uInt) _compressBuffer.size(); + _inflateState.next_out = &_compressBuffer.front(); int ret = inflate(&_inflateState, Z_SYNC_FLUSH); @@ -242,8 +234,8 @@ namespace ix return false; // zlib error } - out.append(reinterpret_cast(_compressBuffer.get()), - _compressBufferSize - _inflateState.avail_out); + out.append(reinterpret_cast(&_compressBuffer.front()), + _compressBuffer.size() - _inflateState.avail_out); } while (_inflateState.avail_out == 0); return true; diff --git a/ixwebsocket/IXWebSocketPerMessageDeflateCodec.h b/ixwebsocket/IXWebSocketPerMessageDeflateCodec.h index 89673f48..2d06517c 100644 --- a/ixwebsocket/IXWebSocketPerMessageDeflateCodec.h +++ b/ixwebsocket/IXWebSocketPerMessageDeflateCodec.h @@ -9,7 +9,7 @@ #ifdef IXWEBSOCKET_USE_ZLIB #include "zlib.h" #endif -#include +#include #include #include @@ -34,8 +34,7 @@ namespace ix bool endsWithEmptyUnCompressedBlock(const T& value); int _flush; - size_t _compressBufferSize; - std::unique_ptr _compressBuffer; + std::array _compressBuffer; #ifdef IXWEBSOCKET_USE_ZLIB z_stream _deflateState; @@ -53,8 +52,7 @@ namespace ix private: int _flush; - size_t _compressBufferSize; - std::unique_ptr _compressBuffer; + std::array _compressBuffer; #ifdef IXWEBSOCKET_USE_ZLIB z_stream _inflateState;