Skip to content

Commit 7d4d69a

Browse files
committed
removed unnecessary code witch caused a racing condition (TooTallNate#145)
1 parent 774bc89 commit 7d4d69a

File tree

1 file changed

+1
-14
lines changed

1 file changed

+1
-14
lines changed

src/main/java/org/java_websocket/server/WebSocketServer.java

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ public abstract class WebSocketServer extends WebSocketAdapter implements Runnab
7676

7777
private List<WebSocketWorker> decoders;
7878

79-
private BlockingQueue<WebSocketImpl> oqueue;
8079
private List<WebSocketImpl> iqueue;
8180
private BlockingQueue<ByteBuffer> buffers;
8281
private int queueinvokes = 0;
@@ -157,7 +156,6 @@ public WebSocketServer( InetSocketAddress address , int decodercount , List<Draf
157156
this.address = address;
158157
this.connections = connectionscontainer;
159158

160-
oqueue = new LinkedBlockingQueue<WebSocketImpl>();
161159
iqueue = new LinkedList<WebSocketImpl>();
162160

163161
decoders = new ArrayList<WebSocketWorker>( decodercount );
@@ -294,8 +292,6 @@ public void run() {
294292
WebSocketImpl conn = null;
295293
try {
296294
selector.select();
297-
registerWrite();
298-
299295
Set<SelectionKey> keys = selector.selectedKeys();
300296
Iterator<SelectionKey> i = keys.iterator();
301297

@@ -420,14 +416,6 @@ private void pushBuffer( ByteBuffer buf ) throws InterruptedException {
420416
buffers.put( buf );
421417
}
422418

423-
private void registerWrite() throws CancelledKeyException {
424-
int size = oqueue.size();
425-
for( int i = 0 ; i < size ; i++ ) {
426-
WebSocketImpl conn = oqueue.remove();
427-
conn.key.interestOps( SelectionKey.OP_READ | SelectionKey.OP_WRITE );
428-
}
429-
}
430-
431419
private void handleIOException( WebSocket conn, IOException ex ) {
432420
onWebsocketError( conn, ex );// conn may be null here
433421
if( conn != null ) {
@@ -483,7 +471,6 @@ public final void onWebsocketOpen( WebSocket conn, Handshakedata handshake ) {
483471

484472
@Override
485473
public final void onWebsocketClose( WebSocket conn, int code, String reason, boolean remote ) {
486-
oqueue.add( (WebSocketImpl) conn );// because the ostream will close the channel
487474
selector.wakeup();
488475
try {
489476
if( removeConnection( conn ) ) {
@@ -530,7 +517,7 @@ public final void onWebsocketError( WebSocket conn, Exception ex ) {
530517
@Override
531518
public final void onWriteDemand( WebSocket w ) {
532519
WebSocketImpl conn = (WebSocketImpl) w;
533-
oqueue.add( conn );
520+
conn.key.interestOps( SelectionKey.OP_READ | SelectionKey.OP_WRITE );
534521
selector.wakeup();
535522
}
536523

0 commit comments

Comments
 (0)