force websocket idle timeout default to be set on endpoint

Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
This commit is contained in:
Lachlan Roberts 2019-05-10 14:22:24 +10:00 committed by Greg Wilkins
parent 2782344d4c
commit 7e5dcda708
2 changed files with 12 additions and 30 deletions

View File

@ -33,7 +33,7 @@ public final class WebSocketConstants
public static final int DEFAULT_INPUT_BUFFER_SIZE = 4 * 1024; public static final int DEFAULT_INPUT_BUFFER_SIZE = 4 * 1024;
public static final int DEFAULT_OUTPUT_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 boolean DEFAULT_AUTO_FRAGMENT = true;
public static final Duration DEFAULT_IDLE_TIMEOUT = Duration.ZERO; public static final Duration DEFAULT_IDLE_TIMEOUT = Duration.ofSeconds(30);
public static final Duration DEFAULT_WRITE_TIMEOUT = Duration.ZERO; public static final Duration DEFAULT_WRITE_TIMEOUT = Duration.ZERO;
/** /**

View File

@ -78,8 +78,8 @@ public class WebSocketChannel implements IncomingFrames, FrameHandler.CoreSessio
private int outputBufferSize = WebSocketConstants.DEFAULT_OUTPUT_BUFFER_SIZE; private int outputBufferSize = WebSocketConstants.DEFAULT_OUTPUT_BUFFER_SIZE;
private long maxBinaryMessageSize = WebSocketConstants.DEFAULT_MAX_BINARY_MESSAGE_SIZE; private long maxBinaryMessageSize = WebSocketConstants.DEFAULT_MAX_BINARY_MESSAGE_SIZE;
private long maxTextMessageSize = WebSocketConstants.DEFAULT_MAX_TEXT_MESSAGE_SIZE; private long maxTextMessageSize = WebSocketConstants.DEFAULT_MAX_TEXT_MESSAGE_SIZE;
private Duration idleTimeout; private Duration idleTimeout = WebSocketConstants.DEFAULT_IDLE_TIMEOUT;
private Duration idleWriteTimeout; private Duration writeTimeout = WebSocketConstants.DEFAULT_WRITE_TIMEOUT;
public WebSocketChannel(FrameHandler handler, public WebSocketChannel(FrameHandler handler,
Behavior behavior, Behavior behavior,
@ -225,36 +225,28 @@ public class WebSocketChannel implements IncomingFrames, FrameHandler.CoreSessio
@Override @Override
public Duration getIdleTimeout() public Duration getIdleTimeout()
{ {
if (getConnection() == null) return idleTimeout;
return idleTimeout;
else
return Duration.ofMillis(getConnection().getEndPoint().getIdleTimeout());
} }
@Override @Override
public void setIdleTimeout(Duration timeout) public void setIdleTimeout(Duration timeout)
{ {
if (getConnection() == null) idleTimeout = timeout;
idleTimeout = timeout; if (connection != null)
else connection.getEndPoint().setIdleTimeout(timeout.toMillis());
getConnection().getEndPoint().setIdleTimeout(timeout.toMillis());
} }
@Override @Override
public Duration getWriteTimeout() public Duration getWriteTimeout()
{ {
if (getConnection() == null) return writeTimeout;
return idleWriteTimeout;
else
return Duration.ofMillis(getConnection().getFrameFlusher().getIdleTimeout());
} }
@Override @Override
public void setWriteTimeout(Duration timeout) public void setWriteTimeout(Duration timeout)
{ {
if (getConnection() == null) writeTimeout = timeout;
idleWriteTimeout = timeout; if (getConnection() != null)
else
getConnection().getFrameFlusher().setIdleTimeout(timeout.toMillis()); getConnection().getFrameFlusher().setIdleTimeout(timeout.toMillis());
} }
@ -281,19 +273,9 @@ public class WebSocketChannel implements IncomingFrames, FrameHandler.CoreSessio
public void setWebSocketConnection(WebSocketConnection connection) public void setWebSocketConnection(WebSocketConnection connection)
{ {
connection.getEndPoint().setIdleTimeout(idleTimeout.toMillis());
connection.getFrameFlusher().setIdleTimeout(writeTimeout.toMillis());
this.connection = connection; this.connection = connection;
if (idleTimeout != null)
{
getConnection().getEndPoint().setIdleTimeout(idleTimeout.toMillis());
idleTimeout = null;
}
if (idleWriteTimeout != null)
{
getConnection().getFrameFlusher().setIdleTimeout(idleWriteTimeout.toMillis());
idleWriteTimeout = null;
}
} }
/** /**