Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -303,12 +303,21 @@ endif()

if (USE_WS OR USE_TEST)
include(FetchContent)

set(MSGPACK11_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(CMAKE_POLICY_VERSION_MINIMUM 3.5 CACHE STRING "" FORCE)

FetchContent_Declare(msgpack11
GIT_REPOSITORY "https://github.com/ar90n/msgpack11"
GIT_TAG "5d051ec8409c96280dcb09f2d2d2f3102b3cc674"
GIT_SHALLOW 1)

FetchContent_Declare(spdlog
GIT_REPOSITORY "https://github.com/gabime/spdlog"
GIT_TAG "v1.8.0"
GIT_TAG "v1.17.0"
GIT_SHALLOW 1)

FetchContent_MakeAvailable(spdlog)
FetchContent_MakeAvailable(spdlog msgpack11)

if (USE_WS)
add_subdirectory(ws)
Expand Down
3 changes: 3 additions & 0 deletions ixwebsocket/IXGzipCodec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ namespace ix
std::string gzipCompress(const std::string& str)
{
#ifndef IXWEBSOCKET_USE_ZLIB
(void) str;
return std::string();
#else
z_stream zs; // z_stream is zlib's control structure
Expand Down Expand Up @@ -74,6 +75,8 @@ namespace ix
bool gzipDecompress(const std::string& in, std::string& out)
{
#ifndef IXWEBSOCKET_USE_ZLIB
(void) in;
(void) out;
return false;
#else
z_stream inflateState;
Expand Down
4 changes: 2 additions & 2 deletions ixwebsocket/IXNetSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ namespace ix
}
}

DWORD n = WSAWaitForMultipleEvents(handles.size(), handles.data(), FALSE, timeout != -1 ? static_cast<DWORD>(timeout) : WSA_INFINITE, FALSE);
DWORD n = WSAWaitForMultipleEvents(static_cast<DWORD>(handles.size()), handles.data(), FALSE, timeout != -1 ? static_cast<DWORD>(timeout) : WSA_INFINITE, FALSE);

if (n == WSA_WAIT_FAILED) return SOCKET_ERROR;
if (n == WSA_WAIT_TIMEOUT) return 0;
Expand Down Expand Up @@ -243,7 +243,7 @@ namespace ix
tv.tv_sec = timeout / 1000;
tv.tv_usec = (timeout % 1000) * 1000;

int ret = select(maxfd + 1, &readfds, &writefds, &errorfds, timeout != -1 ? &tv : NULL);
int ret = select(static_cast<int>(maxfd + 1), &readfds, &writefds, &errorfds, timeout != -1 ? &tv : NULL);

if (ret < 0)
{
Expand Down
4 changes: 4 additions & 0 deletions ixwebsocket/IXNetSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
#define WIN32_LEAN_AND_MEAN
#endif

#ifndef NOMINMAX
#define NOMINMAX
#endif

#include <ws2tcpip.h>
#include <winsock2.h>
#include <basetsd.h>
Expand Down
12 changes: 10 additions & 2 deletions ixwebsocket/IXSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ namespace ix

PollResultType Socket::poll(bool readyToRead,
int timeoutMs,
int sockfd,
socket_t sockfd,
const SelectInterruptPtr& selectInterrupt)
{
PollResultType pollResult = PollResultType::ReadyForRead;
Expand Down Expand Up @@ -247,7 +247,11 @@ namespace ix
flags = MSG_NOSIGNAL;
#endif

#ifdef _WIN32
return ::send(_sockfd, buffer, static_cast<int>(length), flags);
#else
return ::send(_sockfd, buffer, length, flags);
#endif
}

ssize_t Socket::send(const std::string& buffer)
Expand All @@ -262,7 +266,11 @@ namespace ix
flags = MSG_NOSIGNAL;
#endif

#ifdef _WIN32
return ::recv(_sockfd, (char*) buffer, static_cast<int>(length), flags);
#else
return ::recv(_sockfd, (char*) buffer, length, flags);
#endif
}

int Socket::getErrno()
Expand Down Expand Up @@ -290,7 +298,7 @@ namespace ix
return false;
}

void Socket::closeSocket(int fd)
void Socket::closeSocket(socket_t fd)
{
#ifdef _WIN32
closesocket(fd);
Expand Down
5 changes: 3 additions & 2 deletions ixwebsocket/IXSocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ typedef SSIZE_T ssize_t;
#endif

#include "IXCancellationRequest.h"
#include "IXNetSystem.h"
#include "IXProgressCallback.h"
#include "IXSelectInterrupt.h"

Expand Down Expand Up @@ -81,11 +82,11 @@ namespace ix

static int getErrno();
static bool isWaitNeeded();
static void closeSocket(int fd);
static void closeSocket(socket_t fd);

static PollResultType poll(bool readyToRead,
int timeoutMs,
int sockfd,
socket_t sockfd,
const SelectInterruptPtr& selectInterrupt);

protected:
Expand Down
6 changes: 3 additions & 3 deletions ixwebsocket/IXSocketConnect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ namespace ix
// block us for too long
SocketConnect::configure(fd);

int res = ::connect(fd, address->ai_addr, address->ai_addrlen);
int res = ::connect(fd, address->ai_addr, static_cast<int>(address->ai_addrlen));

if (res == -1 && !Socket::isWaitNeeded())
{
Expand Down Expand Up @@ -82,7 +82,7 @@ namespace ix
}
else if (pollResult == PollResultType::ReadyForWrite)
{
return fd;
return static_cast<int>(fd);
}
else
{
Expand Down Expand Up @@ -128,7 +128,7 @@ namespace ix
}

// FIXME: configure is a terrible name
void SocketConnect::configure(int sockfd)
void SocketConnect::configure(socket_t sockfd)
{
// 1. disable Nagle's algorithm
int flag = 1;
Expand Down
3 changes: 2 additions & 1 deletion ixwebsocket/IXSocketConnect.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#pragma once

#include "IXCancellationRequest.h"
#include "IXNetSystem.h"
#include <string>

struct addrinfo;
Expand All @@ -21,7 +22,7 @@ namespace ix
std::string& errMsg,
const CancellationRequest& isCancellationRequested);

static void configure(int sockfd);
static void configure(socket_t sockfd);

private:
static int connectToAddress(const struct addrinfo* address,
Expand Down
2 changes: 1 addition & 1 deletion ixwebsocket/IXSocketServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ namespace ix
socklen_t addressLen = sizeof(client);
memset(&client, 0, sizeof(client));

if ((clientFd = accept(_serverFd, (struct sockaddr*) &client, &addressLen)) < 0)
if ((clientFd = static_cast<int>(accept(_serverFd, (struct sockaddr*) &client, &addressLen))) < 0)
{
if (!Socket::isWaitNeeded())
{
Expand Down
8 changes: 4 additions & 4 deletions ixwebsocket/IXUdpSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ namespace ix
return false;
}

void UdpSocket::closeSocket(int fd)
void UdpSocket::closeSocket(socket_t fd)
{
#ifdef _WIN32
closesocket(fd);
Expand All @@ -67,7 +67,7 @@ namespace ix

bool UdpSocket::init(const std::string& host, int port, std::string& errMsg)
{
_sockfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
_sockfd = static_cast<int>(socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP));
if (_sockfd < 0)
{
errMsg = "Could not create socket";
Expand Down Expand Up @@ -110,7 +110,7 @@ namespace ix
ssize_t UdpSocket::sendto(const std::string& buffer)
{
return (ssize_t)::sendto(
_sockfd, buffer.data(), buffer.size(), 0, (struct sockaddr*) &_server, sizeof(_server));
_sockfd, buffer.data(), static_cast<int>(buffer.size()), 0, (struct sockaddr*) &_server, sizeof(_server));
}

ssize_t UdpSocket::recvfrom(char* buffer, size_t length)
Expand All @@ -121,6 +121,6 @@ namespace ix
socklen_t addressLen = (socklen_t) sizeof(_server);
#endif
return (ssize_t)::recvfrom(
_sockfd, buffer, length, 0, (struct sockaddr*) &_server, &addressLen);
_sockfd, buffer, static_cast<int>(length), 0, (struct sockaddr*) &_server, &addressLen);
}
} // namespace ix
2 changes: 1 addition & 1 deletion ixwebsocket/IXUdpSocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace ix

static int getErrno();
static bool isWaitNeeded();
static void closeSocket(int fd);
static void closeSocket(socket_t fd);

private:
std::atomic<int> _sockfd;
Expand Down
8 changes: 8 additions & 0 deletions ixwebsocket/IXWebSocketPerMessageDeflateCodec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ namespace ix

return true;
#else
(void) deflateBits;
(void) clientNoContextTakeOver;
return false;
#endif
}
Expand Down Expand Up @@ -163,6 +165,8 @@ namespace ix

return true;
#else
(void) in;
(void) out;
return false;
#endif
}
Expand Down Expand Up @@ -202,6 +206,8 @@ namespace ix

return true;
#else
(void) inflateBits;
(void) clientNoContextTakeOver;
return false;
#endif
}
Expand Down Expand Up @@ -246,6 +252,8 @@ namespace ix

return true;
#else
(void) in;
(void) out;
return false;
#endif
}
Expand Down
4 changes: 2 additions & 2 deletions ixwebsocket/IXWebSocketPerMessageDeflateCodec.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ namespace ix
template<typename T>
bool endsWithEmptyUnCompressedBlock(const T& value);

#ifdef IXWEBSOCKET_USE_ZLIB
int _flush;
std::array<unsigned char, 1 << 14> _compressBuffer;

#ifdef IXWEBSOCKET_USE_ZLIB
z_stream _deflateState;
#endif
};
Expand All @@ -54,10 +54,10 @@ namespace ix
bool decompress(const std::string& in, std::string& out);

private:
#ifdef IXWEBSOCKET_USE_ZLIB
int _flush;
std::array<unsigned char, 1 << 14> _compressBuffer;

#ifdef IXWEBSOCKET_USE_ZLIB
z_stream _inflateState;
#endif
};
Expand Down
5 changes: 3 additions & 2 deletions ixwebsocket/IXWebSocketPerMessageDeflateOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ namespace ix
{
/// Default values as defined in the RFC
const uint8_t WebSocketPerMessageDeflateOptions::kDefaultServerMaxWindowBits = 15;
const uint8_t WebSocketPerMessageDeflateOptions::kDefaultClientMaxWindowBits = 15;
#ifdef IXWEBSOCKET_USE_ZLIB
static const uint8_t minServerMaxWindowBits = 8;
static const uint8_t maxServerMaxWindowBits = 15;

const uint8_t WebSocketPerMessageDeflateOptions::kDefaultClientMaxWindowBits = 15;
static const uint8_t minClientMaxWindowBits = 8;
static const uint8_t maxClientMaxWindowBits = 15;
#endif

WebSocketPerMessageDeflateOptions::WebSocketPerMessageDeflateOptions(
bool enabled,
Expand Down
6 changes: 2 additions & 4 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,14 @@ target_sources(ixwebsocket_test PRIVATE
${JSONCPP_SOURCES}
test_runner.cpp
IXTest.cpp
../third_party/msgpack11/msgpack11.cpp
)
target_compile_definitions(ixwebsocket_test PRIVATE ${TEST_PROGRAMS_DEFINITIONS})
target_include_directories(ixwebsocket_test PRIVATE
${PROJECT_SOURCE_DIR}/Catch2/single_include
../third_party
)
target_link_libraries(ixwebsocket_test ixwebsocket)
target_link_libraries(ixwebsocket_test spdlog)
target_link_libraries(ixwebsocket_test msgpack11)

foreach(TEST_TARGET_NAME ${TEST_TARGET_NAMES})
add_executable(${TEST_TARGET_NAME}
Expand All @@ -77,8 +76,6 @@ foreach(TEST_TARGET_NAME ${TEST_TARGET_NAMES})

target_include_directories(${TEST_TARGET_NAME} PRIVATE
${PROJECT_SOURCE_DIR}/Catch2/single_include
../third_party
../third_party/msgpack11
)

target_compile_definitions(${TEST_TARGET_NAME} PRIVATE SPDLOG_COMPILED_LIB=1)
Expand All @@ -92,6 +89,7 @@ foreach(TEST_TARGET_NAME ${TEST_TARGET_NAMES})
target_link_libraries(${TEST_TARGET_NAME} ixwebsocket)

target_link_libraries(${TEST_TARGET_NAME} spdlog)
target_link_libraries(${TEST_TARGET_NAME} msgpack11)

add_test(NAME ${TEST_TARGET_NAME}
COMMAND ${TEST_TARGET_NAME}
Expand Down
2 changes: 2 additions & 0 deletions test/IXTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ namespace ix
#if defined(IXWEBSOCKET_USE_MBED_TLS) || defined(IXWEBSOCKET_USE_OPEN_SSL)
tlsOptionsServer.tls = preferTLS;
#else
(void) preferTLS;
tlsOptionsServer.tls = false;
#endif
return tlsOptionsServer;
Expand Down Expand Up @@ -201,6 +202,7 @@ namespace ix
scheme = "ws://";
}
#else
(void) preferTLS;
scheme = "ws://";
#endif
return scheme;
Expand Down
2 changes: 0 additions & 2 deletions third_party/.clang-format

This file was deleted.

7 changes: 0 additions & 7 deletions third_party/README.md

This file was deleted.

Loading
Loading