瀏覽代碼

Added maxMessageSize to C API

Paul-Louis Ageneau 1 年之前
父節點
當前提交
7dd5eda012
共有 4 個文件被更改,包括 12 次插入1 次删除
  1. 1 0
      include/rtc/configuration.hpp
  2. 3 1
      include/rtc/rtc.h
  3. 7 0
      src/capi.cpp
  4. 1 0
      src/impl/websocketserver.cpp

+ 1 - 0
include/rtc/configuration.hpp

@@ -112,6 +112,7 @@ struct WebSocketServerConfiguration {
 	optional<string> keyPemPass;
 	optional<string> keyPemPass;
 	optional<string> bindAddress;
 	optional<string> bindAddress;
 	optional<std::chrono::milliseconds> connectionTimeout;
 	optional<std::chrono::milliseconds> connectionTimeout;
+	optional<size_t> maxMessageSize;
 };
 };
 
 
 #endif
 #endif

+ 3 - 1
include/rtc/rtc.h

@@ -422,6 +422,7 @@ typedef struct {
 	int connectionTimeoutMs; // in milliseconds, 0 means default, < 0 means disabled
 	int connectionTimeoutMs; // in milliseconds, 0 means default, < 0 means disabled
 	int pingIntervalMs;      // in milliseconds, 0 means default, < 0 means disabled
 	int pingIntervalMs;      // in milliseconds, 0 means default, < 0 means disabled
 	int maxOutstandingPings; // 0 means default, < 0 means disabled
 	int maxOutstandingPings; // 0 means default, < 0 means disabled
+	int maxMessageSize;      // <= 0 means default
 } rtcWsConfiguration;
 } rtcWsConfiguration;
 
 
 RTC_C_EXPORT int rtcCreateWebSocket(const char *url); // returns ws id
 RTC_C_EXPORT int rtcCreateWebSocket(const char *url); // returns ws id
@@ -441,8 +442,9 @@ typedef struct {
 	const char *certificatePemFile; // NULL for autogenerated certificate
 	const char *certificatePemFile; // NULL for autogenerated certificate
 	const char *keyPemFile;         // NULL for autogenerated certificate
 	const char *keyPemFile;         // NULL for autogenerated certificate
 	const char *keyPemPass;         // NULL if no pass
 	const char *keyPemPass;         // NULL if no pass
-	const char *bindAddress;        // NULL for IP_ANY_ADDR
+	const char *bindAddress;        // NULL for any
 	int connectionTimeoutMs;        // in milliseconds, 0 means default, < 0 means disabled
 	int connectionTimeoutMs;        // in milliseconds, 0 means default, < 0 means disabled
+	int maxMessageSize;             // <= 0 means default
 } rtcWsServerConfiguration;
 } rtcWsServerConfiguration;
 
 
 RTC_C_EXPORT int rtcCreateWebSocketServer(const rtcWsServerConfiguration *config,
 RTC_C_EXPORT int rtcCreateWebSocketServer(const rtcWsServerConfiguration *config,

+ 7 - 0
src/capi.cpp

@@ -1479,6 +1479,9 @@ int rtcCreateWebSocketEx(const char *url, const rtcWsConfiguration *config) {
 		else if (config->maxOutstandingPings < 0)
 		else if (config->maxOutstandingPings < 0)
 			c.maxOutstandingPings = 0; // setting to 0 disables, not setting keeps default
 			c.maxOutstandingPings = 0; // setting to 0 disables, not setting keeps default
 
 
+		if(config->maxMessageSize > 0)
+			c.maxMessageSize = size_t(config->maxMessageSize);
+
 		auto webSocket = std::make_shared<WebSocket>(std::move(c));
 		auto webSocket = std::make_shared<WebSocket>(std::move(c));
 		webSocket->open(url);
 		webSocket->open(url);
 		return emplaceWebSocket(webSocket);
 		return emplaceWebSocket(webSocket);
@@ -1533,6 +1536,10 @@ RTC_C_EXPORT int rtcCreateWebSocketServer(const rtcWsServerConfiguration *config
 		c.keyPemFile = config->keyPemFile ? make_optional(string(config->keyPemFile)) : nullopt;
 		c.keyPemFile = config->keyPemFile ? make_optional(string(config->keyPemFile)) : nullopt;
 		c.keyPemPass = config->keyPemPass ? make_optional(string(config->keyPemPass)) : nullopt;
 		c.keyPemPass = config->keyPemPass ? make_optional(string(config->keyPemPass)) : nullopt;
 		c.bindAddress = config->bindAddress ? make_optional(string(config->bindAddress)) : nullopt;
 		c.bindAddress = config->bindAddress ? make_optional(string(config->bindAddress)) : nullopt;
+
+		if(config->maxMessageSize > 0)
+			c.maxMessageSize = size_t(config->maxMessageSize);
+
 		auto webSocketServer = std::make_shared<WebSocketServer>(std::move(c));
 		auto webSocketServer = std::make_shared<WebSocketServer>(std::move(c));
 		int wsserver = emplaceWebSocketServer(webSocketServer);
 		int wsserver = emplaceWebSocketServer(webSocketServer);
 
 

+ 1 - 0
src/impl/websocketserver.cpp

@@ -79,6 +79,7 @@ void WebSocketServer::runLoop() {
 
 
 				WebSocket::Configuration clientConfig;
 				WebSocket::Configuration clientConfig;
 				clientConfig.connectionTimeout = config.connectionTimeout;
 				clientConfig.connectionTimeout = config.connectionTimeout;
+				clientConfig.maxMessageSize = config.maxMessageSize;
 
 
 				auto impl = std::make_shared<WebSocket>(std::move(clientConfig), mCertificate);
 				auto impl = std::make_shared<WebSocket>(std::move(clientConfig), mCertificate);
 				impl->changeState(WebSocket::State::Connecting);
 				impl->changeState(WebSocket::State::Connecting);