C++14 + use make_unique and make_shared to make shared pointers
This commit is contained in:
parent
7fabd14a63
commit
a0f15bfb56
@ -6,7 +6,7 @@
|
||||
cmake_minimum_required(VERSION 3.4.1)
|
||||
project(ixwebsocket C CXX)
|
||||
|
||||
set (CMAKE_CXX_STANDARD 11)
|
||||
set (CMAKE_CXX_STANDARD 14)
|
||||
set (CXX_STANDARD_REQUIRED ON)
|
||||
set (CMAKE_CXX_EXTENSIONS OFF)
|
||||
|
||||
|
@ -11,7 +11,7 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic -Wshorten-64-to-
|
||||
|
||||
set (OPENSSL_PREFIX /usr/local/opt/openssl) # Homebrew openssl
|
||||
|
||||
set (CMAKE_CXX_STANDARD 11)
|
||||
set (CMAKE_CXX_STANDARD 14)
|
||||
|
||||
option(USE_TLS "Add TLS support" ON)
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
||||
cmake_minimum_required (VERSION 3.4.1)
|
||||
project (cmd_websocket_chat)
|
||||
|
||||
set (CMAKE_CXX_STANDARD 11)
|
||||
set (CMAKE_CXX_STANDARD 14)
|
||||
|
||||
option(USE_TLS "Add TLS support" ON)
|
||||
|
||||
|
@ -11,7 +11,7 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic -Wshorten-64-to-
|
||||
|
||||
set (OPENSSL_PREFIX /usr/local/opt/openssl) # Homebrew openssl
|
||||
|
||||
set (CMAKE_CXX_STANDARD 11)
|
||||
set (CMAKE_CXX_STANDARD 14)
|
||||
|
||||
option(USE_TLS "Add TLS support" ON)
|
||||
|
||||
|
@ -11,7 +11,7 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic -Wshorten-64-to-
|
||||
|
||||
set (OPENSSL_PREFIX /usr/local/opt/openssl) # Homebrew openssl
|
||||
|
||||
set (CMAKE_CXX_STANDARD 11)
|
||||
set (CMAKE_CXX_STANDARD 14)
|
||||
|
||||
option(USE_TLS "Add TLS support" ON)
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
cmake_minimum_required (VERSION 3.4.1)
|
||||
project (ping_pong)
|
||||
|
||||
set (CMAKE_CXX_STANDARD 11)
|
||||
set (CMAKE_CXX_STANDARD 14)
|
||||
|
||||
option(USE_TLS "Add TLS support" ON)
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
cmake_minimum_required (VERSION 3.4.1)
|
||||
project (ws_connect)
|
||||
|
||||
set (CMAKE_CXX_STANDARD 11)
|
||||
set (CMAKE_CXX_STANDARD 14)
|
||||
|
||||
option(USE_TLS "Add TLS support" ON)
|
||||
|
||||
|
@ -51,16 +51,16 @@
|
||||
|
||||
namespace ix
|
||||
{
|
||||
WebSocketPerMessageDeflate::WebSocketPerMessageDeflate()
|
||||
WebSocketPerMessageDeflate::WebSocketPerMessageDeflate() :
|
||||
_compressor(std::make_unique<WebSocketPerMessageDeflateCompressor>()),
|
||||
_decompressor(std::make_unique<WebSocketPerMessageDeflateDecompressor>())
|
||||
{
|
||||
_compressor.reset(new WebSocketPerMessageDeflateCompressor());
|
||||
_decompressor.reset(new WebSocketPerMessageDeflateDecompressor());
|
||||
;
|
||||
}
|
||||
|
||||
WebSocketPerMessageDeflate::~WebSocketPerMessageDeflate()
|
||||
{
|
||||
_compressor.reset();
|
||||
_decompressor.reset();
|
||||
;
|
||||
}
|
||||
|
||||
bool WebSocketPerMessageDeflate::init(const WebSocketPerMessageDeflateOptions& perMessageDeflateOptions)
|
||||
|
@ -54,7 +54,7 @@ namespace ix
|
||||
bool decompress(const std::string& in, std::string& out);
|
||||
|
||||
private:
|
||||
std::shared_ptr<WebSocketPerMessageDeflateCompressor> _compressor;
|
||||
std::shared_ptr<WebSocketPerMessageDeflateDecompressor> _decompressor;
|
||||
std::unique_ptr<WebSocketPerMessageDeflateCompressor> _compressor;
|
||||
std::unique_ptr<WebSocketPerMessageDeflateDecompressor> _decompressor;
|
||||
};
|
||||
}
|
||||
|
@ -55,7 +55,8 @@ namespace ix
|
||||
|
||||
if (ret != Z_OK) return false;
|
||||
|
||||
_compressBuffer.reset(new unsigned char[_compressBufferSize]);
|
||||
_compressBuffer = std::make_unique<unsigned char[]>(_compressBufferSize);
|
||||
|
||||
_flush = (clientNoContextTakeOver)
|
||||
? Z_FULL_FLUSH
|
||||
: Z_SYNC_FLUSH;
|
||||
@ -153,7 +154,8 @@ namespace ix
|
||||
|
||||
if (ret != Z_OK) return false;
|
||||
|
||||
_compressBuffer.reset(new unsigned char[_compressBufferSize]);
|
||||
_compressBuffer = std::make_unique<unsigned char[]>(_compressBufferSize);
|
||||
|
||||
_flush = (clientNoContextTakeOver)
|
||||
? Z_FULL_FLUSH
|
||||
: Z_SYNC_FLUSH;
|
||||
|
@ -51,7 +51,7 @@ namespace ix
|
||||
|
||||
void WebSocketServer::handleConnection(int fd)
|
||||
{
|
||||
std::shared_ptr<WebSocket> webSocket(new WebSocket);
|
||||
auto webSocket = std::make_shared<WebSocket>();
|
||||
_onConnectionCallback(webSocket);
|
||||
|
||||
webSocket->disableAutomaticReconnection();
|
||||
@ -99,6 +99,7 @@ namespace ix
|
||||
|
||||
size_t WebSocketServer::getConnectedClientsCount()
|
||||
{
|
||||
return getClients().size();
|
||||
std::lock_guard<std::mutex> lock(_clientsMutex);
|
||||
return _clients.size();
|
||||
}
|
||||
}
|
||||
|
@ -538,7 +538,7 @@ namespace ix
|
||||
|
||||
while (_txbuf.size())
|
||||
{
|
||||
int ret = _socket->send((char*)&_txbuf[0], _txbuf.size());
|
||||
ssize_t ret = _socket->send((char*)&_txbuf[0], _txbuf.size());
|
||||
|
||||
if (ret < 0 && (_socket->getErrno() == EWOULDBLOCK ||
|
||||
_socket->getErrno() == EAGAIN))
|
||||
|
@ -8,7 +8,7 @@ project (ixwebsocket_unittest)
|
||||
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/../third_party/sanitizers-cmake/cmake" ${CMAKE_MODULE_PATH})
|
||||
find_package(Sanitizers)
|
||||
|
||||
set (CMAKE_CXX_STANDARD 11)
|
||||
set (CMAKE_CXX_STANDARD 14)
|
||||
|
||||
if (NOT WIN32)
|
||||
option(USE_TLS "Add TLS support" ON)
|
||||
|
Loading…
Reference in New Issue
Block a user