Add closeOnBackpressureLimit option

This commit is contained in:
Alex Hultman
2021-01-26 12:18:31 +01:00
parent 359c26b0bf
commit 12d8b192a1
4 changed files with 13 additions and 1 deletions
+2
View File
@@ -139,6 +139,7 @@ public:
unsigned int maxPayloadLength = 16 * 1024; unsigned int maxPayloadLength = 16 * 1024;
unsigned int idleTimeout = 120; unsigned int idleTimeout = 120;
unsigned int maxBackpressure = 1 * 1024 * 1024; 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(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> *)> open = nullptr;
fu2::unique_function<void(uWS::WebSocket<SSL, true> *, std::string_view, uWS::OpCode)> message = 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()->maxPayloadLength = behavior.maxPayloadLength;
webSocketContext->getExt()->idleTimeout = behavior.idleTimeout; webSocketContext->getExt()->idleTimeout = behavior.idleTimeout;
webSocketContext->getExt()->maxBackpressure = behavior.maxBackpressure; webSocketContext->getExt()->maxBackpressure = behavior.maxBackpressure;
webSocketContext->getExt()->closeOnBackpressureLimit = behavior.closeOnBackpressureLimit;
webSocketContext->getExt()->compression = behavior.compression; webSocketContext->getExt()->compression = behavior.compression;
httpContext->onHttp("get", pattern, [webSocketContext, behavior = std::move(behavior)](auto *res, auto *req) mutable { httpContext->onHttp("get", pattern, [webSocketContext, behavior = std::move(behavior)](auto *res, auto *req) mutable {
+4
View File
@@ -64,6 +64,10 @@ public:
/* Skip sending and report success if we are over the limit of maxBackpressure */ /* Skip sending and report success if we are over the limit of maxBackpressure */
if (webSocketContextData->maxBackpressure && webSocketContextData->maxBackpressure < getBufferedAmount()) { 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; return true;
} }
+6
View File
@@ -64,6 +64,7 @@ public:
/* There needs to be a maxBackpressure which will force close everything over that limit */ /* There needs to be a maxBackpressure which will force close everything over that limit */
size_t maxBackpressure = 0; size_t maxBackpressure = 0;
bool closeOnBackpressureLimit;
/* Each websocket context has a topic tree for pub/sub */ /* Each websocket context has a topic tree for pub/sub */
TopicTree topicTree; TopicTree topicTree;
@@ -143,6 +144,11 @@ public:
/* If we have too much backpressure, simply skip sending from here */ /* 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 */ /* Reserved, unused */
return 0; return 0;
}) { }) {