31
31
import java .nio .ByteBuffer ;
32
32
import java .nio .channels .Channel ;
33
33
import java .nio .channels .ClosedChannelException ;
34
+ import java .nio .channels .ClosedSelectorException ;
34
35
import java .nio .channels .NotYetConnectedException ;
35
36
import java .nio .channels .SelectionKey ;
36
37
import java .nio .channels .Selector ;
@@ -452,9 +453,9 @@ private Object waitSelect(final int operations, final boolean blocking, final bo
452
453
try {
453
454
result [0 ] = selector .selectNow ();
454
455
455
- if ( result [0 ] == 0 ) {
456
+ if (result [0 ] == 0 ) {
456
457
if ((operations & SelectionKey .OP_READ ) != 0 && (operations & SelectionKey .OP_WRITE ) != 0 ) {
457
- if ( key .isReadable () ) {
458
+ if (key .isReadable ()) {
458
459
writeWouldBlock (runtime , exception , result );
459
460
}
460
461
//else if ( key.isWritable() ) {
@@ -463,28 +464,27 @@ private Object waitSelect(final int operations, final boolean blocking, final bo
463
464
else { //neither, pick one
464
465
readWouldBlock (runtime , exception , result );
465
466
}
466
- }
467
- else if ((operations & SelectionKey .OP_READ ) != 0 ) {
467
+ } else if ((operations & SelectionKey .OP_READ ) != 0 ) {
468
468
readWouldBlock (runtime , exception , result );
469
- }
470
- else if ((operations & SelectionKey .OP_WRITE ) != 0 ) {
469
+ } else if ((operations & SelectionKey .OP_WRITE ) != 0 ) {
471
470
writeWouldBlock (runtime , exception , result );
472
471
}
473
472
}
474
- } catch (IOException ioe ) {
475
- debugStackTrace (runtime , "SSLSocket.waitSelect" , ioe );
476
- throw runtime .newRuntimeError ("Error with selector: " + ioe .getMessage ());
473
+ } catch (ClosedSelectorException ex ) {
474
+ throw Utils .newRuntimeError (runtime , "selector closed" , ex );
475
+ } catch (IOException ex ) {
476
+ throw Utils .newIOError (runtime , ex );
477
477
}
478
478
} else {
479
479
io .addBlockingThread (thread );
480
480
thread .executeBlockingTask (new RubyThread .BlockingTask () {
481
- public void run () throws InterruptedException {
481
+ public void run () {
482
482
try {
483
483
result [0 ] = selector .select ();
484
- }
485
- catch ( IOException ioe ) {
486
- debugStackTrace ( runtime , "SSLSocket.waitSelect" , ioe );
487
- throw runtime . newRuntimeError ( "Error with selector: " + ioe . getMessage () );
484
+ } catch ( ClosedSelectorException ex ) {
485
+ throw Utils . newRuntimeError ( runtime , "selector closed" , ex );
486
+ } catch ( IOException ex ) {
487
+ throw Utils . newIOError ( runtime , ex );
488
488
}
489
489
}
490
490
0 commit comments