Reset timeout on websocket send and publishes

This commit is contained in:
Alex Hultman
2019-10-08 22:59:22 +02:00
parent f58a9e1e0d
commit cbb46b494f
2 changed files with 8 additions and 1 deletions
+6
View File
@@ -55,6 +55,12 @@ public:
/* Send or buffer a WebSocket frame, compressed or not. Returns false on increased user space backpressure. */
bool send(std::string_view message, uWS::OpCode opCode = uWS::OpCode::BINARY, bool compress = false) {
/* Every send resets the timeout */
WebSocketContextData<SSL> *webSocketContextData = (WebSocketContextData<SSL> *) us_socket_context_ext(SSL,
(us_socket_context_t *) us_socket_context(SSL, (us_socket_t *) this)
);
AsyncSocket<SSL>::timeout(webSocketContextData->idleTimeout);
/* Transform the message to compressed domain if requested */
if (compress) {
WebSocketData *webSocketData = (WebSocketData *) Super::getAsyncSocketData();
+2 -1
View File
@@ -47,10 +47,11 @@ struct WebSocketContextData {
/* Each websocket context has a topic tree for pub/sub */
TopicTree topicTree;
WebSocketContextData() : topicTree([](Subscriber *s, std::string_view data) -> int {
WebSocketContextData() : topicTree([this](Subscriber *s, std::string_view data) -> int {
/* We rely on writing to regular asyncSockets */
auto *asyncSocket = (AsyncSocket<SSL> *) s->user;
asyncSocket->timeout(this->idleTimeout);
asyncSocket->write(data.data(), data.length());
/* Reserved, unused */