diff --git a/Makefile b/Makefile index 7f6edaa..d393dc0 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ EXAMPLE_FILES := HelloWorld ServerName EchoServer BroadcastingEchoServer UpgradeSync UpgradeAsync THREADED_EXAMPLE_FILES := HelloWorldThreaded EchoServerThreaded -override CXXFLAGS += -lpthread -Wpedantic -Wall -Wextra -std=c++2a -Isrc -IuSockets/src +override CXXFLAGS += -lpthread -Wpedantic -Wall -Wextra -Wsign-conversion -Wconversion -std=c++2a -Isrc -IuSockets/src override LDFLAGS += uSockets/*.o -lz DESTDIR ?= diff --git a/src/App.h b/src/App.h index 4493f58..f6aed6b 100644 --- a/src/App.h +++ b/src/App.h @@ -29,6 +29,23 @@ namespace uWS { + /* This one matches us_socket_context_options_t but has default values */ + struct SocketContextOptions { + const char *key_file_name = nullptr; + const char *cert_file_name = nullptr; + const char *passphrase = nullptr; + const char *dh_params_file_name = nullptr; + const char *ca_file_name = nullptr; + int ssl_prefer_low_memory_usage = 0; + + /* Conversion operator used internally */ + operator struct us_socket_context_options_t() const { + struct us_socket_context_options_t socket_context_options; + memcpy(&socket_context_options, this, sizeof(SocketContextOptions)); + return socket_context_options; + } + }; + template struct TemplatedApp { private: @@ -39,7 +56,7 @@ private: public: /* Server name */ - TemplatedApp &&addServerName(std::string hostname_pattern, us_socket_context_options_t options = {}) { + TemplatedApp &&addServerName(std::string hostname_pattern, SocketContextOptions options = {}) { us_socket_context_add_server_name(SSL, (struct us_socket_context_t *) httpContext, hostname_pattern.c_str(), options); return std::move(*this); @@ -107,7 +124,7 @@ public: webSocketContexts = std::move(other.webSocketContexts); } - TemplatedApp(us_socket_context_options_t options = {}) { + TemplatedApp(SocketContextOptions options = {}) { httpContext = uWS::HttpContext::create(uWS::Loop::get(), options); } diff --git a/src/BloomFilter.h b/src/BloomFilter.h index 2547fd6..95ced77 100644 --- a/src/BloomFilter.h +++ b/src/BloomFilter.h @@ -31,11 +31,11 @@ private: std::bitset<512> filter; unsigned int hash1(std::string_view key) { - return ((unsigned int)key[key.length() - 1] - (key.length() << 3)) & 511; + return ((size_t)key[key.length() - 1] - (key.length() << 3)) & 511; } unsigned int hash2(std::string_view key) { - return (((unsigned int)key[0] + (key.length() << 4)) & 511); + return (((size_t)key[0] + (key.length() << 4)) & 511); } unsigned int hash3(std::string_view key) { diff --git a/src/HttpParser.h b/src/HttpParser.h index 53dc07c..2917dcc 100644 --- a/src/HttpParser.h +++ b/src/HttpParser.h @@ -152,7 +152,7 @@ private: static unsigned int toUnsignedInteger(std::string_view str) { unsigned int unsignedIntegerValue = 0; for (char c : str) { - unsignedIntegerValue = unsignedIntegerValue * 10 + ((unsigned char) c - '0'); + unsignedIntegerValue = unsignedIntegerValue * 10u + ((unsigned int) c - (unsigned int) '0'); } return unsignedIntegerValue; } diff --git a/src/WebSocketProtocol.h b/src/WebSocketProtocol.h index f3a56c9..db282e4 100644 --- a/src/WebSocketProtocol.h +++ b/src/WebSocketProtocol.h @@ -362,9 +362,9 @@ protected: static inline bool consumeContinuation(char *&src, unsigned int &length, WebSocketState *wState, void *user) { if (wState->remainingBytes <= length) { if (isServer) { - int n = wState->remainingBytes >> 2; + unsigned int n = wState->remainingBytes >> 2; unmaskInplace(src, src + n * 4, wState->mask); - for (int i = 0, s = wState->remainingBytes % 4; i < s; i++) { + for (unsigned int i = 0, s = wState->remainingBytes % 4; i < s; i++) { src[n * 4 + i] ^= wState->mask[i]; } }