|
5 | 5 | import java.net.Socket; |
6 | 6 | import java.net.URI; |
7 | 7 | import java.nio.ByteBuffer; |
| 8 | +import java.nio.channels.ByteChannel; |
8 | 9 | import java.nio.channels.ClosedByInterruptException; |
9 | 10 | import java.nio.channels.NotYetConnectedException; |
10 | 11 | import java.nio.channels.SelectionKey; |
@@ -55,6 +56,8 @@ public abstract class WebSocketClient extends WebSocketAdapter implements Runnab |
55 | 56 | * The SocketChannel instance this channel uses. |
56 | 57 | */ |
57 | 58 | private SocketChannel channel = null; |
| 59 | + |
| 60 | + private ByteChannel wrappedchannel = null; |
58 | 61 | /** |
59 | 62 | * The 'Selector' used to get event keys from the underlying socket. |
60 | 63 | */ |
@@ -230,13 +233,13 @@ private final void interruptableRun() { |
230 | 233 | } |
231 | 234 | SelectionKey key = null; |
232 | 235 | selector.select(); |
233 | | - SocketChannelIOHelper.batch( conn, channel ); |
| 236 | + SocketChannelIOHelper.batch( conn, wrappedchannel ); |
234 | 237 | Set<SelectionKey> keys = selector.selectedKeys(); |
235 | 238 | Iterator<SelectionKey> i = keys.iterator(); |
236 | 239 | while ( i.hasNext() ) { |
237 | 240 | key = i.next(); |
238 | 241 | i.remove(); |
239 | | - if( key.isReadable() && SocketChannelIOHelper.read( buff, this.conn, channel ) ) { |
| 242 | + if( key.isReadable() && SocketChannelIOHelper.read( buff, this.conn, wrappedchannel ) ) { |
240 | 243 | conn.decode( buff ); |
241 | 244 | } |
242 | 245 | if( !key.isValid() ) { |
@@ -273,7 +276,7 @@ private void finishConnect() throws IOException , InvalidHandshakeException , In |
273 | 276 | if( channel.isConnectionPending() ) { |
274 | 277 | channel.finishConnect(); |
275 | 278 | } |
276 | | - |
| 279 | + wrappedchannel = wf.wrapChannel( channel ); |
277 | 280 | // Now that we're connected, re-register for only 'READ' keys. |
278 | 281 | channel.register( selector, SelectionKey.OP_READ ); |
279 | 282 |
|
|
0 commit comments