Issue #3412 - WSChannel delay config of idletimeout on WSConnection

Signed-off-by: lachan-roberts <lachlan@webtide.com>
This commit is contained in:
lachan-roberts 2019-03-01 18:22:18 +11:00
parent 5ecd512a90
commit d380012fc9
2 changed files with 12 additions and 2 deletions

View File

@ -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 <code>Sec-WebSocket-Key</code> http headers.

View File

@ -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());
}
/**