From 90e61e88fd71a23149b5c360f6b0f452ed95a2e1 Mon Sep 17 00:00:00 2001 From: Alex Hultman Date: Wed, 27 Jan 2021 18:56:24 +0100 Subject: [PATCH] Add resetIdleTimeoutOnSend --- src/App.h | 2 ++ src/WebSocket.h | 4 +++- src/WebSocketContextData.h | 5 ++++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/App.h b/src/App.h index 309865a..9b7cf26 100644 --- a/src/App.h +++ b/src/App.h @@ -140,6 +140,7 @@ public: unsigned int idleTimeout = 120; unsigned int maxBackpressure = 1 * 1024 * 1024; bool closeOnBackpressureLimit = false; + bool resetIdleTimeoutOnSend = true; fu2::unique_function *, HttpRequest *, struct us_socket_context_t *)> upgrade = nullptr; fu2::unique_function *)> open = nullptr; fu2::unique_function *, std::string_view, uWS::OpCode)> message = nullptr; @@ -202,6 +203,7 @@ public: webSocketContext->getExt()->idleTimeout = behavior.idleTimeout; webSocketContext->getExt()->maxBackpressure = behavior.maxBackpressure; webSocketContext->getExt()->closeOnBackpressureLimit = behavior.closeOnBackpressureLimit; + webSocketContext->getExt()->resetIdleTimeoutOnSend = behavior.resetIdleTimeoutOnSend; webSocketContext->getExt()->compression = behavior.compression; httpContext->onHttp("get", pattern, [webSocketContext, behavior = std::move(behavior)](auto *res, auto *req) mutable { diff --git a/src/WebSocket.h b/src/WebSocket.h index f36e03d..fcf40d1 100644 --- a/src/WebSocket.h +++ b/src/WebSocket.h @@ -122,7 +122,9 @@ public: } /* Every successful send resets the timeout */ - Super::timeout(webSocketContextData->idleTimeout); + if (webSocketContextData->resetIdleTimeoutOnSend) { + Super::timeout(webSocketContextData->idleTimeout); + } /* Return success */ return true; diff --git a/src/WebSocketContextData.h b/src/WebSocketContextData.h index e2278dd..db2a04f 100644 --- a/src/WebSocketContextData.h +++ b/src/WebSocketContextData.h @@ -65,6 +65,7 @@ public: /* There needs to be a maxBackpressure which will force close everything over that limit */ size_t maxBackpressure = 0; bool closeOnBackpressureLimit; + bool resetIdleTimeoutOnSend; /* Each websocket context has a topic tree for pub/sub */ TopicTree topicTree; @@ -134,7 +135,9 @@ public: /* Note: this assumes we are not corked, as corking will swallow things and fail later on */ auto [written, failed] = asyncSocket->write(selectedData.data(), (int) selectedData.length()); if (!failed) { - asyncSocket->timeout(this->idleTimeout); + if (this->resetIdleTimeoutOnSend) { + asyncSocket->timeout(this->idleTimeout); + } } /* Failing here must not immediately close the socket, as that could result in stack overflow,