Skip to content

Commit 8ce0e34

Browse files
committed
fixed issues regarding the closing handshake
1 parent df82bb7 commit 8ce0e34

3 files changed

Lines changed: 5 additions & 3 deletions

File tree

‎src/org/java_websocket/WebSocketImpl.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ public WebSocketImpl( WebSocketListener listener , Draft draft , Socket sock ) {
167167
* @throws InterruptedException
168168
*/
169169
public void decode( ByteBuffer socketBuffer ) throws IOException {
170-
if( !socketBuffer.hasRemaining() )
170+
if( !socketBuffer.hasRemaining() || connectionClosed )
171171
return;
172172

173173
if( DEBUG )

‎src/org/java_websocket/client/WebSocketClient.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,13 +209,13 @@ protected final void interruptableRun() {
209209
conn = (WebSocketImpl) wf.createWebSocket( this, draft, channel.socket() );
210210
ByteBuffer buff = ByteBuffer.allocate( WebSocket.RCVBUF );
211211
try/*IO*/{
212-
while ( !conn.isClosed() ) {
212+
while ( channel.isOpen() ) {
213213
if( Thread.interrupted() ) {
214214
conn.close( CloseFrame.NORMAL );
215215
}
216216
SelectionKey key = null;
217-
SocketChannelIOHelper.batch( conn, channel );
218217
selector.select();
218+
SocketChannelIOHelper.batch( conn, channel );
219219
Set<SelectionKey> keys = selector.selectedKeys();
220220
Iterator<SelectionKey> i = keys.iterator();
221221
while ( i.hasNext() ) {

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,8 @@ public final void onWebsocketOpen( WebSocket conn, Handshakedata handshake ) {
416416

417417
@Override
418418
public final void onWebsocketClose( WebSocket conn, int code, String reason, boolean remote ) {
419+
oqueue.add( (WebSocketImpl) conn );// because the ostream will close the channel
420+
selector.wakeup();
419421
try {
420422
synchronized ( connections ) {
421423
if( this.connections.remove( conn ) ) {

0 commit comments

Comments
 (0)