|
17 | 17 | */
|
18 | 18 | package io.undertow.websockets.core;
|
19 | 19 |
|
| 20 | +import io.undertow.UndertowLogger; |
20 | 21 | import io.undertow.conduits.IdleTimeoutConduit;
|
21 | 22 | import io.undertow.server.protocol.framed.AbstractFramedChannel;
|
22 | 23 | import io.undertow.server.protocol.framed.AbstractFramedStreamSourceChannel;
|
|
28 | 29 | import org.xnio.ChannelListeners;
|
29 | 30 | import org.xnio.IoUtils;
|
30 | 31 | import org.xnio.OptionMap;
|
| 32 | +import org.xnio.Options; |
| 33 | + |
31 | 34 | import io.undertow.connector.ByteBufferPool;
|
32 | 35 | import io.undertow.connector.PooledByteBuffer;
|
33 | 36 | import org.xnio.StreamConnection;
|
|
50 | 53 | * @author Stuart Douglas
|
51 | 54 | */
|
52 | 55 | public abstract class WebSocketChannel extends AbstractFramedChannel<WebSocketChannel, StreamSourceFrameChannel, StreamSinkFrameChannel> {
|
53 |
| - |
| 56 | + /** |
| 57 | + * Configure a read timeout for a web socket, in milliseconds. If its present it will override {@link org.xnio.Options.READ_TIMEOUT}. If the given amount of time elapses without |
| 58 | + * a successful read taking place, the socket's next read will throw a {@link ReadTimeoutException}. |
| 59 | + */ |
| 60 | + public static final String WEB_SOCKETS_READ_TIMEOUT = "io.undertow.websockets.core.read-timeout"; |
| 61 | + /** |
| 62 | + * Configure a write timeout for a web socket, in milliseconds. If its present it will override {@link org.xnio.Options.WRITE_TIMEOUT}. If the given amount of time elapses without |
| 63 | + * a successful write taking place, the socket's next write will throw a {@link WriteTimeoutException}. |
| 64 | + */ |
| 65 | + public static final String WEB_SOCKETS_WRITE_TIMEOUT = "io.undertow.websockets.core.write-timeout"; |
54 | 66 | private final boolean client;
|
55 | 67 |
|
56 | 68 | private final WebSocketVersion version;
|
@@ -106,6 +118,22 @@ protected WebSocketChannel(final StreamConnection connectedStreamChannel, ByteBu
|
106 | 118 | this.hasReservedOpCode = extensionFunction.hasExtensionOpCode();
|
107 | 119 | this.subProtocol = subProtocol;
|
108 | 120 | this.peerConnections = peerConnections;
|
| 121 | + final String webSocketReadTimeout = System.getProperty(WEB_SOCKETS_READ_TIMEOUT); |
| 122 | + if(webSocketReadTimeout != null) { |
| 123 | + try { |
| 124 | + this.setOption(Options.READ_TIMEOUT, Integer.parseInt(webSocketReadTimeout)); |
| 125 | + } catch (Exception e) { |
| 126 | + UndertowLogger.ROOT_LOGGER.failedToSetWSTimeout(e); |
| 127 | + } |
| 128 | + } |
| 129 | + final String webSocketWriteTimeout = System.getProperty(WEB_SOCKETS_WRITE_TIMEOUT); |
| 130 | + if(webSocketWriteTimeout != null) { |
| 131 | + try { |
| 132 | + this.setOption(Options.WRITE_TIMEOUT, Integer.parseInt(webSocketWriteTimeout)); |
| 133 | + } catch (Exception e) { |
| 134 | + UndertowLogger.ROOT_LOGGER.failedToSetWSTimeout(e); |
| 135 | + } |
| 136 | + } |
109 | 137 | addCloseTask(new ChannelListener<WebSocketChannel>() {
|
110 | 138 | @Override
|
111 | 139 | public void handleEvent(WebSocketChannel channel) {
|
|
0 commit comments