Add closeOnBackpressureLimit option
This commit is contained in:
@@ -139,6 +139,7 @@ public:
|
||||
unsigned int maxPayloadLength = 16 * 1024;
|
||||
unsigned int idleTimeout = 120;
|
||||
unsigned int maxBackpressure = 1 * 1024 * 1024;
|
||||
bool closeOnBackpressureLimit = false;
|
||||
fu2::unique_function<void(HttpResponse<SSL> *, HttpRequest *, struct us_socket_context_t *)> upgrade = nullptr;
|
||||
fu2::unique_function<void(uWS::WebSocket<SSL, true> *)> open = nullptr;
|
||||
fu2::unique_function<void(uWS::WebSocket<SSL, true> *, std::string_view, uWS::OpCode)> message = nullptr;
|
||||
@@ -200,6 +201,7 @@ public:
|
||||
webSocketContext->getExt()->maxPayloadLength = behavior.maxPayloadLength;
|
||||
webSocketContext->getExt()->idleTimeout = behavior.idleTimeout;
|
||||
webSocketContext->getExt()->maxBackpressure = behavior.maxBackpressure;
|
||||
webSocketContext->getExt()->closeOnBackpressureLimit = behavior.closeOnBackpressureLimit;
|
||||
webSocketContext->getExt()->compression = behavior.compression;
|
||||
|
||||
httpContext->onHttp("get", pattern, [webSocketContext, behavior = std::move(behavior)](auto *res, auto *req) mutable {
|
||||
|
||||
@@ -64,6 +64,10 @@ public:
|
||||
|
||||
/* Skip sending and report success if we are over the limit of maxBackpressure */
|
||||
if (webSocketContextData->maxBackpressure && webSocketContextData->maxBackpressure < getBufferedAmount()) {
|
||||
/* Also defer a close if we should */
|
||||
if (webSocketContextData->closeOnBackpressureLimit) {
|
||||
us_socket_shutdown_read(SSL, (us_socket_t *) this);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -64,6 +64,7 @@ public:
|
||||
|
||||
/* There needs to be a maxBackpressure which will force close everything over that limit */
|
||||
size_t maxBackpressure = 0;
|
||||
bool closeOnBackpressureLimit;
|
||||
|
||||
/* Each websocket context has a topic tree for pub/sub */
|
||||
TopicTree topicTree;
|
||||
@@ -143,6 +144,11 @@ public:
|
||||
|
||||
/* If we have too much backpressure, simply skip sending from here */
|
||||
|
||||
/* Also (defer) a close if we have too much backpressure if that is what we want */
|
||||
if (maxBackpressure && closeOnBackpressureLimit && asyncSocket->getBufferedAmount() > maxBackpressure) {
|
||||
us_socket_shutdown_read(SSL, (us_socket_t *) asyncSocket);
|
||||
}
|
||||
|
||||
/* Reserved, unused */
|
||||
return 0;
|
||||
}) {
|
||||
|
||||
+1
-1
Submodule uSockets updated: 7683672d87...45a70140b1
Reference in New Issue
Block a user