|
8 | 8 | import java.nio.ByteBuffer; |
9 | 9 | import java.nio.channels.ByteChannel; |
10 | 10 | import java.nio.channels.CancelledKeyException; |
| 11 | +import java.nio.channels.SelectableChannel; |
11 | 12 | import java.nio.channels.SelectionKey; |
12 | 13 | import java.nio.channels.Selector; |
13 | 14 | import java.nio.channels.ServerSocketChannel; |
@@ -370,7 +371,7 @@ public void run() { |
370 | 371 | } catch ( IOException ex ) { |
371 | 372 | if( key != null ) |
372 | 373 | key.cancel(); |
373 | | - handleIOException( conn, ex ); |
| 374 | + handleIOException( key, conn, ex ); |
374 | 375 | } catch ( InterruptedException e ) { |
375 | 376 | return;// FIXME controlled shutdown |
376 | 377 | } |
@@ -416,10 +417,21 @@ private void pushBuffer( ByteBuffer buf ) throws InterruptedException { |
416 | 417 | buffers.put( buf ); |
417 | 418 | } |
418 | 419 |
|
419 | | - private void handleIOException( WebSocket conn, IOException ex ) { |
| 420 | + private void handleIOException( SelectionKey key, WebSocket conn, IOException ex ) { |
420 | 421 | onWebsocketError( conn, ex );// conn may be null here |
421 | 422 | if( conn != null ) { |
422 | 423 | conn.closeConnection( CloseFrame.ABNORMAL_CLOSE, ex.getMessage() ); |
| 424 | + } else if( key != null ) { |
| 425 | + SelectableChannel channel = key.channel(); |
| 426 | + if( channel != null && channel.isOpen() ) { // this could be the case if the IOException ex is a SSLException |
| 427 | + try { |
| 428 | + channel.close(); |
| 429 | + } catch ( IOException e ) { |
| 430 | + // there is nothing that must be done here |
| 431 | + } |
| 432 | + if( WebSocketImpl.DEBUG ) |
| 433 | + System.out.println( "Connection closed because of" + ex ); |
| 434 | + } |
423 | 435 | } |
424 | 436 | } |
425 | 437 |
|
|
0 commit comments