From 8f5134528bba47d9a39ba48227be7bb0c426d97b Mon Sep 17 00:00:00 2001 From: Benjamin Sergeant Date: Sun, 15 Nov 2020 09:56:37 -0800 Subject: [PATCH] (ixwebsocket) use a C++11 compatible make_unique shim --- docs/CHANGELOG.md | 4 ++ ixwebsocket/IXSelectInterruptFactory.cpp | 5 +- ixwebsocket/IXSocketConnect.cpp | 3 +- ixwebsocket/IXSocketFactory.cpp | 9 ++-- ixwebsocket/IXSocketOpenSSL.cpp | 3 +- ixwebsocket/IXUniquePtr.h | 18 +++++++ ixwebsocket/IXWebSocket.cpp | 53 ++++++++++---------- ixwebsocket/IXWebSocketPerMessageDeflate.cpp | 5 +- ixwebsocket/IXWebSocketTransport.cpp | 5 +- ixwebsocket/IXWebSocketVersion.h | 2 +- 10 files changed, 68 insertions(+), 39 deletions(-) create mode 100644 ixwebsocket/IXUniquePtr.h diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 6d330f7b..e934b362 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.2] - 2020-11-15 + +(ixwebsocket) use a C++11 compatible make_unique shim + ## [11.0.1] - 2020-11-11 (socket) replace a std::vector with an std::array used as a tmp buffer in Socket::readBytes diff --git a/ixwebsocket/IXSelectInterruptFactory.cpp b/ixwebsocket/IXSelectInterruptFactory.cpp index 0cd4a278..9018810d 100644 --- a/ixwebsocket/IXSelectInterruptFactory.cpp +++ b/ixwebsocket/IXSelectInterruptFactory.cpp @@ -6,6 +6,7 @@ #include "IXSelectInterruptFactory.h" +#include "IXUniquePtr.h" #if defined(__linux__) || defined(__APPLE__) #include "IXSelectInterruptPipe.h" #else @@ -17,9 +18,9 @@ namespace ix SelectInterruptPtr createSelectInterrupt() { #if defined(__linux__) || defined(__APPLE__) - return std::make_unique(); + return ix::make_unique(); #else - return std::make_unique(); + return ix::make_unique(); #endif } } // namespace ix diff --git a/ixwebsocket/IXSocketConnect.cpp b/ixwebsocket/IXSocketConnect.cpp index fea01897..a11fb3b7 100644 --- a/ixwebsocket/IXSocketConnect.cpp +++ b/ixwebsocket/IXSocketConnect.cpp @@ -10,6 +10,7 @@ #include "IXNetSystem.h" #include "IXSelectInterrupt.h" #include "IXSocket.h" +#include "IXUniquePtr.h" #include #include #include @@ -65,7 +66,7 @@ namespace ix int timeoutMs = 10; bool readyToRead = false; - auto selectInterrupt = std::make_unique(); + auto selectInterrupt = ix::make_unique(); PollResultType pollResult = Socket::poll(readyToRead, timeoutMs, fd, selectInterrupt); if (pollResult == PollResultType::Timeout) diff --git a/ixwebsocket/IXSocketFactory.cpp b/ixwebsocket/IXSocketFactory.cpp index bf2d24fe..0273d683 100644 --- a/ixwebsocket/IXSocketFactory.cpp +++ b/ixwebsocket/IXSocketFactory.cpp @@ -6,6 +6,7 @@ #include "IXSocketFactory.h" +#include "IXUniquePtr.h" #ifdef IXWEBSOCKET_USE_TLS #ifdef IXWEBSOCKET_USE_MBED_TLS @@ -35,17 +36,17 @@ namespace ix if (!tls) { - socket = std::make_unique(fd); + socket = ix::make_unique(fd); } else { #ifdef IXWEBSOCKET_USE_TLS #if defined(IXWEBSOCKET_USE_MBED_TLS) - socket = std::make_unique(tlsOptions, fd); + socket = ix::make_unique(tlsOptions, fd); #elif defined(IXWEBSOCKET_USE_OPEN_SSL) - socket = std::make_unique(tlsOptions, fd); + socket = ix::make_unique(tlsOptions, fd); #elif defined(__APPLE__) - socket = std::make_unique(tlsOptions, fd); + socket = ix::make_unique(tlsOptions, fd); #endif #else errorMsg = "TLS support is not enabled on this platform."; diff --git a/ixwebsocket/IXSocketOpenSSL.cpp b/ixwebsocket/IXSocketOpenSSL.cpp index 5ae93e67..2a14ef6d 100644 --- a/ixwebsocket/IXSocketOpenSSL.cpp +++ b/ixwebsocket/IXSocketOpenSSL.cpp @@ -10,6 +10,7 @@ #include "IXSocketOpenSSL.h" #include "IXSocketConnect.h" +#include "IXUniquePtr.h" #include #include #ifdef _WIN32 @@ -86,7 +87,7 @@ namespace ix std::atomic SocketOpenSSL::_openSSLInitializationSuccessful(false); std::once_flag SocketOpenSSL::_openSSLInitFlag; std::unique_ptr SocketOpenSSL::_openSSLMutexes = - std::make_unique(CRYPTO_num_locks()); + ix::make_unique(CRYPTO_num_locks()); SocketOpenSSL::SocketOpenSSL(const SocketTLSOptions& tlsOptions, int fd) : Socket(fd) diff --git a/ixwebsocket/IXUniquePtr.h b/ixwebsocket/IXUniquePtr.h new file mode 100644 index 00000000..d88ce9bd --- /dev/null +++ b/ixwebsocket/IXUniquePtr.h @@ -0,0 +1,18 @@ +/* + * IXUniquePtr.h + * Author: Benjamin Sergeant + * Copyright (c) 2020 Machine Zone, Inc. All rights reserved. + */ + +#pragma once + +#include + +namespace ix +{ + template + std::unique_ptr make_unique(Args&&... args) + { + return std::unique_ptr(new T(std::forward(args)...)); + } +} // namespace ix diff --git a/ixwebsocket/IXWebSocket.cpp b/ixwebsocket/IXWebSocket.cpp index 6d27e7f9..0d1cfa01 100644 --- a/ixwebsocket/IXWebSocket.cpp +++ b/ixwebsocket/IXWebSocket.cpp @@ -8,6 +8,7 @@ #include "IXExponentialBackoff.h" #include "IXSetThreadName.h" +#include "IXUniquePtr.h" #include "IXUtf8Validator.h" #include "IXWebSocketHandshake.h" #include @@ -34,12 +35,12 @@ namespace ix _ws.setOnCloseCallback( [this](uint16_t code, const std::string& reason, size_t wireSize, bool remote) { _onMessageCallback( - std::make_unique(WebSocketMessageType::Close, - "", - wireSize, - WebSocketErrorInfo(), - WebSocketOpenInfo(), - WebSocketCloseInfo(code, reason, remote))); + ix::make_unique(WebSocketMessageType::Close, + "", + wireSize, + WebSocketErrorInfo(), + WebSocketOpenInfo(), + WebSocketCloseInfo(code, reason, remote))); }); } @@ -195,7 +196,7 @@ namespace ix return status; } - _onMessageCallback(std::make_unique( + _onMessageCallback(ix::make_unique( WebSocketMessageType::Open, "", 0, @@ -227,12 +228,12 @@ namespace ix } _onMessageCallback( - std::make_unique(WebSocketMessageType::Open, - "", - 0, - WebSocketErrorInfo(), - WebSocketOpenInfo(status.uri, status.headers), - WebSocketCloseInfo())); + ix::make_unique(WebSocketMessageType::Open, + "", + 0, + WebSocketErrorInfo(), + WebSocketOpenInfo(status.uri, status.headers), + WebSocketCloseInfo())); if (_pingIntervalSecs > 0) { @@ -312,12 +313,12 @@ namespace ix connectErr.reason = status.errorStr; connectErr.http_status = status.http_status; - _onMessageCallback(std::make_unique(WebSocketMessageType::Error, - "", - 0, - connectErr, - WebSocketOpenInfo(), - WebSocketCloseInfo())); + _onMessageCallback(ix::make_unique(WebSocketMessageType::Error, + "", + 0, + connectErr, + WebSocketOpenInfo(), + WebSocketCloseInfo())); } } } @@ -388,13 +389,13 @@ namespace ix bool binary = messageKind == WebSocketTransport::MessageKind::MSG_BINARY; - _onMessageCallback(std::make_unique(webSocketMessageType, - msg, - wireSize, - webSocketErrorInfo, - WebSocketOpenInfo(), - WebSocketCloseInfo(), - binary)); + _onMessageCallback(ix::make_unique(webSocketMessageType, + msg, + wireSize, + webSocketErrorInfo, + WebSocketOpenInfo(), + WebSocketCloseInfo(), + binary)); WebSocket::invokeTrafficTrackerCallback(wireSize, true); }); diff --git a/ixwebsocket/IXWebSocketPerMessageDeflate.cpp b/ixwebsocket/IXWebSocketPerMessageDeflate.cpp index 6392768b..80435870 100644 --- a/ixwebsocket/IXWebSocketPerMessageDeflate.cpp +++ b/ixwebsocket/IXWebSocketPerMessageDeflate.cpp @@ -48,14 +48,15 @@ #include "IXWebSocketPerMessageDeflate.h" +#include "IXUniquePtr.h" #include "IXWebSocketPerMessageDeflateCodec.h" #include "IXWebSocketPerMessageDeflateOptions.h" namespace ix { WebSocketPerMessageDeflate::WebSocketPerMessageDeflate() - : _compressor(std::make_unique()) - , _decompressor(std::make_unique()) + : _compressor(ix::make_unique()) + , _decompressor(ix::make_unique()) { ; } diff --git a/ixwebsocket/IXWebSocketTransport.cpp b/ixwebsocket/IXWebSocketTransport.cpp index 186c064f..1133ea30 100644 --- a/ixwebsocket/IXWebSocketTransport.cpp +++ b/ixwebsocket/IXWebSocketTransport.cpp @@ -36,6 +36,7 @@ #include "IXSocketFactory.h" #include "IXSocketTLSOptions.h" +#include "IXUniquePtr.h" #include "IXUrlParser.h" #include "IXUtf8Validator.h" #include "IXWebSocketHandshake.h" @@ -124,7 +125,7 @@ namespace ix std::string errorMsg; bool tls = protocol == "wss"; _socket = createSocket(tls, -1, errorMsg, _socketTLSOptions); - _perMessageDeflate = std::make_unique(); + _perMessageDeflate = ix::make_unique(); if (!_socket) { @@ -177,7 +178,7 @@ namespace ix _blockingSend = true; _socket = std::move(socket); - _perMessageDeflate = std::make_unique(); + _perMessageDeflate = ix::make_unique(); WebSocketHandshake webSocketHandshake(_requestInitCancellation, _socket, diff --git a/ixwebsocket/IXWebSocketVersion.h b/ixwebsocket/IXWebSocketVersion.h index 431fcd06..a7e75df7 100644 --- a/ixwebsocket/IXWebSocketVersion.h +++ b/ixwebsocket/IXWebSocketVersion.h @@ -6,4 +6,4 @@ #pragma once -#define IX_WEBSOCKET_VERSION "11.0.1" +#define IX_WEBSOCKET_VERSION "11.0.2"