(ixwebsocket) use a C++11 compatible make_unique shim
This commit is contained in:
parent
738c6040f7
commit
8f5134528b
@ -2,6 +2,10 @@
|
|||||||
|
|
||||||
All changes to this project will be documented in this file.
|
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
|
## [11.0.1] - 2020-11-11
|
||||||
|
|
||||||
(socket) replace a std::vector with an std::array used as a tmp buffer in Socket::readBytes
|
(socket) replace a std::vector with an std::array used as a tmp buffer in Socket::readBytes
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
#include "IXSelectInterruptFactory.h"
|
#include "IXSelectInterruptFactory.h"
|
||||||
|
|
||||||
|
#include "IXUniquePtr.h"
|
||||||
#if defined(__linux__) || defined(__APPLE__)
|
#if defined(__linux__) || defined(__APPLE__)
|
||||||
#include "IXSelectInterruptPipe.h"
|
#include "IXSelectInterruptPipe.h"
|
||||||
#else
|
#else
|
||||||
@ -17,9 +18,9 @@ namespace ix
|
|||||||
SelectInterruptPtr createSelectInterrupt()
|
SelectInterruptPtr createSelectInterrupt()
|
||||||
{
|
{
|
||||||
#if defined(__linux__) || defined(__APPLE__)
|
#if defined(__linux__) || defined(__APPLE__)
|
||||||
return std::make_unique<SelectInterruptPipe>();
|
return ix::make_unique<SelectInterruptPipe>();
|
||||||
#else
|
#else
|
||||||
return std::make_unique<SelectInterrupt>();
|
return ix::make_unique<SelectInterrupt>();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
} // namespace ix
|
} // namespace ix
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
#include "IXNetSystem.h"
|
#include "IXNetSystem.h"
|
||||||
#include "IXSelectInterrupt.h"
|
#include "IXSelectInterrupt.h"
|
||||||
#include "IXSocket.h"
|
#include "IXSocket.h"
|
||||||
|
#include "IXUniquePtr.h"
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
@ -65,7 +66,7 @@ namespace ix
|
|||||||
|
|
||||||
int timeoutMs = 10;
|
int timeoutMs = 10;
|
||||||
bool readyToRead = false;
|
bool readyToRead = false;
|
||||||
auto selectInterrupt = std::make_unique<SelectInterrupt>();
|
auto selectInterrupt = ix::make_unique<SelectInterrupt>();
|
||||||
PollResultType pollResult = Socket::poll(readyToRead, timeoutMs, fd, selectInterrupt);
|
PollResultType pollResult = Socket::poll(readyToRead, timeoutMs, fd, selectInterrupt);
|
||||||
|
|
||||||
if (pollResult == PollResultType::Timeout)
|
if (pollResult == PollResultType::Timeout)
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
#include "IXSocketFactory.h"
|
#include "IXSocketFactory.h"
|
||||||
|
|
||||||
|
#include "IXUniquePtr.h"
|
||||||
#ifdef IXWEBSOCKET_USE_TLS
|
#ifdef IXWEBSOCKET_USE_TLS
|
||||||
|
|
||||||
#ifdef IXWEBSOCKET_USE_MBED_TLS
|
#ifdef IXWEBSOCKET_USE_MBED_TLS
|
||||||
@ -35,17 +36,17 @@ namespace ix
|
|||||||
|
|
||||||
if (!tls)
|
if (!tls)
|
||||||
{
|
{
|
||||||
socket = std::make_unique<Socket>(fd);
|
socket = ix::make_unique<Socket>(fd);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
#ifdef IXWEBSOCKET_USE_TLS
|
#ifdef IXWEBSOCKET_USE_TLS
|
||||||
#if defined(IXWEBSOCKET_USE_MBED_TLS)
|
#if defined(IXWEBSOCKET_USE_MBED_TLS)
|
||||||
socket = std::make_unique<SocketMbedTLS>(tlsOptions, fd);
|
socket = ix::make_unique<SocketMbedTLS>(tlsOptions, fd);
|
||||||
#elif defined(IXWEBSOCKET_USE_OPEN_SSL)
|
#elif defined(IXWEBSOCKET_USE_OPEN_SSL)
|
||||||
socket = std::make_unique<SocketOpenSSL>(tlsOptions, fd);
|
socket = ix::make_unique<SocketOpenSSL>(tlsOptions, fd);
|
||||||
#elif defined(__APPLE__)
|
#elif defined(__APPLE__)
|
||||||
socket = std::make_unique<SocketAppleSSL>(tlsOptions, fd);
|
socket = ix::make_unique<SocketAppleSSL>(tlsOptions, fd);
|
||||||
#endif
|
#endif
|
||||||
#else
|
#else
|
||||||
errorMsg = "TLS support is not enabled on this platform.";
|
errorMsg = "TLS support is not enabled on this platform.";
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
#include "IXSocketOpenSSL.h"
|
#include "IXSocketOpenSSL.h"
|
||||||
|
|
||||||
#include "IXSocketConnect.h"
|
#include "IXSocketConnect.h"
|
||||||
|
#include "IXUniquePtr.h"
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
@ -86,7 +87,7 @@ namespace ix
|
|||||||
std::atomic<bool> SocketOpenSSL::_openSSLInitializationSuccessful(false);
|
std::atomic<bool> SocketOpenSSL::_openSSLInitializationSuccessful(false);
|
||||||
std::once_flag SocketOpenSSL::_openSSLInitFlag;
|
std::once_flag SocketOpenSSL::_openSSLInitFlag;
|
||||||
std::unique_ptr<std::mutex[]> SocketOpenSSL::_openSSLMutexes =
|
std::unique_ptr<std::mutex[]> SocketOpenSSL::_openSSLMutexes =
|
||||||
std::make_unique<std::mutex[]>(CRYPTO_num_locks());
|
ix::make_unique<std::mutex[]>(CRYPTO_num_locks());
|
||||||
|
|
||||||
SocketOpenSSL::SocketOpenSSL(const SocketTLSOptions& tlsOptions, int fd)
|
SocketOpenSSL::SocketOpenSSL(const SocketTLSOptions& tlsOptions, int fd)
|
||||||
: Socket(fd)
|
: Socket(fd)
|
||||||
|
18
ixwebsocket/IXUniquePtr.h
Normal file
18
ixwebsocket/IXUniquePtr.h
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
/*
|
||||||
|
* IXUniquePtr.h
|
||||||
|
* Author: Benjamin Sergeant
|
||||||
|
* Copyright (c) 2020 Machine Zone, Inc. All rights reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
namespace ix
|
||||||
|
{
|
||||||
|
template<typename T, typename... Args>
|
||||||
|
std::unique_ptr<T> make_unique(Args&&... args)
|
||||||
|
{
|
||||||
|
return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
|
||||||
|
}
|
||||||
|
} // namespace ix
|
@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
#include "IXExponentialBackoff.h"
|
#include "IXExponentialBackoff.h"
|
||||||
#include "IXSetThreadName.h"
|
#include "IXSetThreadName.h"
|
||||||
|
#include "IXUniquePtr.h"
|
||||||
#include "IXUtf8Validator.h"
|
#include "IXUtf8Validator.h"
|
||||||
#include "IXWebSocketHandshake.h"
|
#include "IXWebSocketHandshake.h"
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
@ -34,12 +35,12 @@ namespace ix
|
|||||||
_ws.setOnCloseCallback(
|
_ws.setOnCloseCallback(
|
||||||
[this](uint16_t code, const std::string& reason, size_t wireSize, bool remote) {
|
[this](uint16_t code, const std::string& reason, size_t wireSize, bool remote) {
|
||||||
_onMessageCallback(
|
_onMessageCallback(
|
||||||
std::make_unique<WebSocketMessage>(WebSocketMessageType::Close,
|
ix::make_unique<WebSocketMessage>(WebSocketMessageType::Close,
|
||||||
"",
|
"",
|
||||||
wireSize,
|
wireSize,
|
||||||
WebSocketErrorInfo(),
|
WebSocketErrorInfo(),
|
||||||
WebSocketOpenInfo(),
|
WebSocketOpenInfo(),
|
||||||
WebSocketCloseInfo(code, reason, remote)));
|
WebSocketCloseInfo(code, reason, remote)));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -195,7 +196,7 @@ namespace ix
|
|||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
_onMessageCallback(std::make_unique<WebSocketMessage>(
|
_onMessageCallback(ix::make_unique<WebSocketMessage>(
|
||||||
WebSocketMessageType::Open,
|
WebSocketMessageType::Open,
|
||||||
"",
|
"",
|
||||||
0,
|
0,
|
||||||
@ -227,12 +228,12 @@ namespace ix
|
|||||||
}
|
}
|
||||||
|
|
||||||
_onMessageCallback(
|
_onMessageCallback(
|
||||||
std::make_unique<WebSocketMessage>(WebSocketMessageType::Open,
|
ix::make_unique<WebSocketMessage>(WebSocketMessageType::Open,
|
||||||
"",
|
"",
|
||||||
0,
|
0,
|
||||||
WebSocketErrorInfo(),
|
WebSocketErrorInfo(),
|
||||||
WebSocketOpenInfo(status.uri, status.headers),
|
WebSocketOpenInfo(status.uri, status.headers),
|
||||||
WebSocketCloseInfo()));
|
WebSocketCloseInfo()));
|
||||||
|
|
||||||
if (_pingIntervalSecs > 0)
|
if (_pingIntervalSecs > 0)
|
||||||
{
|
{
|
||||||
@ -312,12 +313,12 @@ namespace ix
|
|||||||
connectErr.reason = status.errorStr;
|
connectErr.reason = status.errorStr;
|
||||||
connectErr.http_status = status.http_status;
|
connectErr.http_status = status.http_status;
|
||||||
|
|
||||||
_onMessageCallback(std::make_unique<WebSocketMessage>(WebSocketMessageType::Error,
|
_onMessageCallback(ix::make_unique<WebSocketMessage>(WebSocketMessageType::Error,
|
||||||
"",
|
"",
|
||||||
0,
|
0,
|
||||||
connectErr,
|
connectErr,
|
||||||
WebSocketOpenInfo(),
|
WebSocketOpenInfo(),
|
||||||
WebSocketCloseInfo()));
|
WebSocketCloseInfo()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -388,13 +389,13 @@ namespace ix
|
|||||||
|
|
||||||
bool binary = messageKind == WebSocketTransport::MessageKind::MSG_BINARY;
|
bool binary = messageKind == WebSocketTransport::MessageKind::MSG_BINARY;
|
||||||
|
|
||||||
_onMessageCallback(std::make_unique<WebSocketMessage>(webSocketMessageType,
|
_onMessageCallback(ix::make_unique<WebSocketMessage>(webSocketMessageType,
|
||||||
msg,
|
msg,
|
||||||
wireSize,
|
wireSize,
|
||||||
webSocketErrorInfo,
|
webSocketErrorInfo,
|
||||||
WebSocketOpenInfo(),
|
WebSocketOpenInfo(),
|
||||||
WebSocketCloseInfo(),
|
WebSocketCloseInfo(),
|
||||||
binary));
|
binary));
|
||||||
|
|
||||||
WebSocket::invokeTrafficTrackerCallback(wireSize, true);
|
WebSocket::invokeTrafficTrackerCallback(wireSize, true);
|
||||||
});
|
});
|
||||||
|
@ -48,14 +48,15 @@
|
|||||||
|
|
||||||
#include "IXWebSocketPerMessageDeflate.h"
|
#include "IXWebSocketPerMessageDeflate.h"
|
||||||
|
|
||||||
|
#include "IXUniquePtr.h"
|
||||||
#include "IXWebSocketPerMessageDeflateCodec.h"
|
#include "IXWebSocketPerMessageDeflateCodec.h"
|
||||||
#include "IXWebSocketPerMessageDeflateOptions.h"
|
#include "IXWebSocketPerMessageDeflateOptions.h"
|
||||||
|
|
||||||
namespace ix
|
namespace ix
|
||||||
{
|
{
|
||||||
WebSocketPerMessageDeflate::WebSocketPerMessageDeflate()
|
WebSocketPerMessageDeflate::WebSocketPerMessageDeflate()
|
||||||
: _compressor(std::make_unique<WebSocketPerMessageDeflateCompressor>())
|
: _compressor(ix::make_unique<WebSocketPerMessageDeflateCompressor>())
|
||||||
, _decompressor(std::make_unique<WebSocketPerMessageDeflateDecompressor>())
|
, _decompressor(ix::make_unique<WebSocketPerMessageDeflateDecompressor>())
|
||||||
{
|
{
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
@ -36,6 +36,7 @@
|
|||||||
|
|
||||||
#include "IXSocketFactory.h"
|
#include "IXSocketFactory.h"
|
||||||
#include "IXSocketTLSOptions.h"
|
#include "IXSocketTLSOptions.h"
|
||||||
|
#include "IXUniquePtr.h"
|
||||||
#include "IXUrlParser.h"
|
#include "IXUrlParser.h"
|
||||||
#include "IXUtf8Validator.h"
|
#include "IXUtf8Validator.h"
|
||||||
#include "IXWebSocketHandshake.h"
|
#include "IXWebSocketHandshake.h"
|
||||||
@ -124,7 +125,7 @@ namespace ix
|
|||||||
std::string errorMsg;
|
std::string errorMsg;
|
||||||
bool tls = protocol == "wss";
|
bool tls = protocol == "wss";
|
||||||
_socket = createSocket(tls, -1, errorMsg, _socketTLSOptions);
|
_socket = createSocket(tls, -1, errorMsg, _socketTLSOptions);
|
||||||
_perMessageDeflate = std::make_unique<WebSocketPerMessageDeflate>();
|
_perMessageDeflate = ix::make_unique<WebSocketPerMessageDeflate>();
|
||||||
|
|
||||||
if (!_socket)
|
if (!_socket)
|
||||||
{
|
{
|
||||||
@ -177,7 +178,7 @@ namespace ix
|
|||||||
_blockingSend = true;
|
_blockingSend = true;
|
||||||
|
|
||||||
_socket = std::move(socket);
|
_socket = std::move(socket);
|
||||||
_perMessageDeflate = std::make_unique<WebSocketPerMessageDeflate>();
|
_perMessageDeflate = ix::make_unique<WebSocketPerMessageDeflate>();
|
||||||
|
|
||||||
WebSocketHandshake webSocketHandshake(_requestInitCancellation,
|
WebSocketHandshake webSocketHandshake(_requestInitCancellation,
|
||||||
_socket,
|
_socket,
|
||||||
|
@ -6,4 +6,4 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#define IX_WEBSOCKET_VERSION "11.0.1"
|
#define IX_WEBSOCKET_VERSION "11.0.2"
|
||||||
|
Loading…
Reference in New Issue
Block a user