mention disablePerMessageDeflate in the doc

This commit is contained in:
Benjamin Sergeant 2021-03-16 09:56:08 -07:00
parent cadb8336f2
commit 0813eb1788
12 changed files with 47 additions and 24 deletions

View File

@ -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.1.0] - 2021-03-16
(ixwebsocket) Use LEAN_AND_MEAN Windows define to help with undefined link error when building a DLL. Support websocket server disablePerMessageDeflate option correctly.
## [11.0.9] - 2021-03-07 ## [11.0.9] - 2021-03-07
(ixwebsocket) Expose setHandshakeTimeout method (ixwebsocket) Expose setHandshakeTimeout method

View File

@ -343,6 +343,10 @@ if (!res.first)
return 1; return 1;
} }
// Per message deflate connection is enabled by default. It can be disabled
// which might be helpful when running on low power devices such as a Rasbery Pi
server.disablePerMessageDeflate();
// Run the server in the background. Server can be stoped by calling server.stop() // Run the server in the background. Server can be stoped by calling server.stop()
server.start(); server.start();
@ -410,6 +414,10 @@ if (!res.first)
return 1; return 1;
} }
// Per message deflate connection is enabled by default. It can be disabled
// which might be helpful when running on low power devices such as a Rasbery Pi
server.disablePerMessageDeflate();
// Run the server in the background. Server can be stoped by calling server.stop() // Run the server in the background. Server can be stoped by calling server.stop()
server.start(); server.start();

View File

@ -8,12 +8,12 @@
// mingw does not have those // mingw does not have those
#if defined(_WIN32) && defined(__GNUC__) #if defined(_WIN32) && defined(__GNUC__)
const char * inet_ntop(int af, const void * restrict src, char * restrict dst, socklen_t size) const char* inet_ntop(int af, const void* restrict src, char* restrict dst, socklen_t size)
{ {
return nullptr; return nullptr;
} }
int inet_pton(int af, const char * restrict src, void * restrict dst) int inet_pton(int af, const char* restrict src, void* restrict dst)
{ {
return -1; return -1;
} }

View File

@ -23,17 +23,18 @@ typedef unsigned long int nfds_t;
// mingw does not know about poll so mock it // mingw does not know about poll so mock it
#if defined(__GNUC__) #if defined(__GNUC__)
struct pollfd { struct pollfd
int fd; /* file descriptor */ {
short events; /* requested events */ int fd; /* file descriptor */
short revents; /* returned events */ short events; /* requested events */
short revents; /* returned events */
}; };
#define POLLIN 0x001 /* There is data to read. */ #define POLLIN 0x001 /* There is data to read. */
#define POLLOUT 0x004 /* Writing now will not block. */ #define POLLOUT 0x004 /* Writing now will not block. */
#define POLLERR 0x008 /* Error condition. */ #define POLLERR 0x008 /* Error condition. */
#define POLLHUP 0x010 /* Hung up. */ #define POLLHUP 0x010 /* Hung up. */
#define POLLNVAL 0x020 /* Invalid polling request. */ #define POLLNVAL 0x020 /* Invalid polling request. */
#endif #endif
#else #else
@ -54,8 +55,8 @@ struct pollfd {
// mingw does not have those // mingw does not have those
#if defined(_WIN32) && defined(__GNUC__) #if defined(_WIN32) && defined(__GNUC__)
const char * inet_ntop(int af, const void * restrict src, char * restrict dst, socklen_t size); const char* inet_ntop(int af, const void* restrict src, char* restrict dst, socklen_t size);
int inet_pton(int af, const char * restrict src, void * restrict dst); int inet_pton(int af, const char* restrict src, void* restrict dst);
#endif #endif
namespace ix namespace ix

View File

@ -218,7 +218,9 @@ namespace ix
return status; return status;
} }
WebSocketInitResult WebSocket::connectToSocket(std::unique_ptr<Socket> socket, int timeoutSecs) WebSocketInitResult WebSocket::connectToSocket(std::unique_ptr<Socket> socket,
int timeoutSecs,
bool enablePerMessageDeflate)
{ {
{ {
std::lock_guard<std::mutex> lock(_configMutex); std::lock_guard<std::mutex> lock(_configMutex);
@ -226,7 +228,8 @@ namespace ix
_perMessageDeflateOptions, _socketTLSOptions, _enablePong, _pingIntervalSecs); _perMessageDeflateOptions, _socketTLSOptions, _enablePong, _pingIntervalSecs);
} }
WebSocketInitResult status = _ws.connectToSocket(std::move(socket), timeoutSecs); WebSocketInitResult status =
_ws.connectToSocket(std::move(socket), timeoutSecs, enablePerMessageDeflate);
if (!status.success) if (!status.success)
{ {
return status; return status;

View File

@ -115,7 +115,9 @@ namespace ix
static void invokeTrafficTrackerCallback(size_t size, bool incoming); static void invokeTrafficTrackerCallback(size_t size, bool incoming);
// Server // Server
WebSocketInitResult connectToSocket(std::unique_ptr<Socket>, int timeoutSecs); WebSocketInitResult connectToSocket(std::unique_ptr<Socket>,
int timeoutSecs,
bool enablePerMessageDeflate);
WebSocketTransport _ws; WebSocketTransport _ws;

View File

@ -241,7 +241,8 @@ namespace ix
return WebSocketInitResult(true, status, "", headers, path); return WebSocketInitResult(true, status, "", headers, path);
} }
WebSocketInitResult WebSocketHandshake::serverHandshake(int timeoutSecs) WebSocketInitResult WebSocketHandshake::serverHandshake(int timeoutSecs,
bool enablePerMessageDeflate)
{ {
_requestInitCancellation = false; _requestInitCancellation = false;
@ -338,7 +339,7 @@ namespace ix
WebSocketPerMessageDeflateOptions webSocketPerMessageDeflateOptions(header); WebSocketPerMessageDeflateOptions webSocketPerMessageDeflateOptions(header);
// If the client has requested that extension, // If the client has requested that extension,
if (webSocketPerMessageDeflateOptions.enabled()) if (webSocketPerMessageDeflateOptions.enabled() && enablePerMessageDeflate)
{ {
_enablePerMessageDeflate = true; _enablePerMessageDeflate = true;

View File

@ -35,7 +35,7 @@ namespace ix
int port, int port,
int timeoutSecs); int timeoutSecs);
WebSocketInitResult serverHandshake(int timeoutSecs); WebSocketInitResult serverHandshake(int timeoutSecs, bool enablePerMessageDeflate);
private: private:
std::string genRandomString(const int len); std::string genRandomString(const int len);

View File

@ -129,7 +129,8 @@ namespace ix
_clients.insert(webSocket); _clients.insert(webSocket);
} }
auto status = webSocket->connectToSocket(std::move(socket), _handshakeTimeoutSecs); auto status = webSocket->connectToSocket(
std::move(socket), _handshakeTimeoutSecs, _enablePerMessageDeflate);
if (status.success) if (status.success)
{ {
// Process incoming messages and execute callbacks // Process incoming messages and execute callbacks

View File

@ -169,7 +169,8 @@ namespace ix
// Server // Server
WebSocketInitResult WebSocketTransport::connectToSocket(std::unique_ptr<Socket> socket, WebSocketInitResult WebSocketTransport::connectToSocket(std::unique_ptr<Socket> socket,
int timeoutSecs) int timeoutSecs,
bool enablePerMessageDeflate)
{ {
std::lock_guard<std::mutex> lock(_socketMutex); std::lock_guard<std::mutex> lock(_socketMutex);
@ -186,7 +187,7 @@ namespace ix
_perMessageDeflateOptions, _perMessageDeflateOptions,
_enablePerMessageDeflate); _enablePerMessageDeflate);
auto result = webSocketHandshake.serverHandshake(timeoutSecs); auto result = webSocketHandshake.serverHandshake(timeoutSecs, enablePerMessageDeflate);
if (result.success) if (result.success)
{ {
setReadyState(ReadyState::OPEN); setReadyState(ReadyState::OPEN);

View File

@ -83,7 +83,9 @@ namespace ix
int timeoutSecs); int timeoutSecs);
// Server // Server
WebSocketInitResult connectToSocket(std::unique_ptr<Socket> socket, int timeoutSecs); WebSocketInitResult connectToSocket(std::unique_ptr<Socket> socket,
int timeoutSecs,
bool enablePerMessageDeflate);
PollResult poll(); PollResult poll();
WebSocketSendInfo sendBinary(const std::string& message, WebSocketSendInfo sendBinary(const std::string& message,

View File

@ -6,4 +6,4 @@
#pragma once #pragma once
#define IX_WEBSOCKET_VERSION "11.0.9" #define IX_WEBSOCKET_VERSION "11.1.0"