Skip to content

Commit 0298ade

Browse files
committed
-fixed infinite recurring on lost connections
1 parent d74f699 commit 0298ade

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

src/net/tootallnate/websocket/WebSocketServer.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,13 @@
66
import java.nio.channels.Selector;
77
import java.nio.channels.ServerSocketChannel;
88
import java.nio.channels.SocketChannel;
9-
import java.security.MessageDigest;
109
import java.security.NoSuchAlgorithmException;
1110
import java.util.Collections;
12-
import java.util.HashMap;
1311
import java.util.Iterator;
14-
import java.util.Properties;
1512
import java.util.Set;
1613
import java.util.concurrent.CopyOnWriteArraySet;
1714
import java.util.concurrent.LinkedBlockingQueue;
1815

19-
import sun.misc.BASE64Encoder;
20-
2116
/**
2217
* <tt>WebSocketServer</tt> is an abstract class that only takes care of the
2318
* HTTP handshake portion of WebSockets. It's up to a subclass to add
@@ -205,13 +200,14 @@ public void run() {
205200
}
206201

207202
while(true) {
203+
SelectionKey key = null;
208204
try {
209205
selector.select();
210206
Set<SelectionKey> keys = selector.selectedKeys();
211207
Iterator<SelectionKey> i = keys.iterator();
212208

213209
while(i.hasNext()) {
214-
SelectionKey key = i.next();
210+
key = i.next();
215211

216212
// Remove the current key
217213
i.remove();
@@ -254,6 +250,8 @@ public void run() {
254250
}
255251
}
256252
} catch (IOException ex) {
253+
if( key != null )
254+
key.cancel();
257255
onError(ex);
258256
} catch (RuntimeException ex) {
259257
ex.printStackTrace();

0 commit comments

Comments
 (0)