From d380012fc92af5c536cfd148037a070b4c945861 Mon Sep 17 00:00:00 2001 From: lachan-roberts Date: Fri, 1 Mar 2019 18:22:18 +1100 Subject: [PATCH] Issue #3412 - WSChannel delay config of idletimeout on WSConnection Signed-off-by: lachan-roberts --- .../jetty/websocket/core/WebSocketConstants.java | 2 ++ .../websocket/core/internal/WebSocketChannel.java | 12 ++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/WebSocketConstants.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/WebSocketConstants.java index 543fc1d6d3c..a1dc0ab8910 100644 --- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/WebSocketConstants.java +++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/WebSocketConstants.java @@ -19,6 +19,7 @@ package org.eclipse.jetty.websocket.core; import java.nio.charset.StandardCharsets; +import java.time.Duration; public final class WebSocketConstants { @@ -32,6 +33,7 @@ public final class WebSocketConstants public static final int DEFAULT_INPUT_BUFFER_SIZE = 4 * 1024; public static final int DEFAULT_OUTPUT_BUFFER_SIZE = 4 * 1024; public static final boolean DEFAULT_AUTO_FRAGMENT = true; + public static final Duration DEFAULT_IDLE_TIMEOUT = Duration.ZERO; /** * Globally Unique Identifier for use in WebSocket handshake within {@code Sec-WebSocket-Accept} and Sec-WebSocket-Key http headers. diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/WebSocketChannel.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/WebSocketChannel.java index 2002d82dcae..617c8554868 100644 --- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/WebSocketChannel.java +++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/WebSocketChannel.java @@ -77,6 +77,7 @@ public class WebSocketChannel implements IncomingFrames, FrameHandler.CoreSessio private int outputBufferSize = WebSocketConstants.DEFAULT_OUTPUT_BUFFER_SIZE; private long maxBinaryMessageSize = WebSocketConstants.DEFAULT_MAX_BINARY_MESSAGE_SIZE; private long maxTextMessageSize = WebSocketConstants.DEFAULT_MAX_TEXT_MESSAGE_SIZE; + private Duration idleTimeout = WebSocketConstants.DEFAULT_IDLE_TIMEOUT; public WebSocketChannel(FrameHandler handler, Behavior behavior, @@ -222,13 +223,19 @@ public class WebSocketChannel implements IncomingFrames, FrameHandler.CoreSessio @Override public Duration getIdleTimeout() { - return Duration.ofMillis(getConnection().getEndPoint().getIdleTimeout()); + if (getConnection() == null) + return idleTimeout; + else + return Duration.ofMillis(getConnection().getEndPoint().getIdleTimeout()); } @Override public void setIdleTimeout(Duration timeout) { - getConnection().getEndPoint().setIdleTimeout(timeout == null?0:timeout.toMillis()); + if (getConnection() == null) + idleTimeout = timeout; + else + getConnection().getEndPoint().setIdleTimeout(timeout.toMillis()); } public SocketAddress getLocalAddress() @@ -255,6 +262,7 @@ public class WebSocketChannel implements IncomingFrames, FrameHandler.CoreSessio public void setWebSocketConnection(WebSocketConnection connection) { this.connection = connection; + getConnection().getEndPoint().setIdleTimeout(idleTimeout.toMillis()); } /**