Skip to content

Commit 8d43030

Browse files
committed
[refactor] propagate IOError from selector exception
1 parent f841697 commit 8d43030

File tree

2 files changed

+26
-18
lines changed

2 files changed

+26
-18
lines changed

src/main/java/org/jruby/ext/openssl/SSLSocket.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import java.nio.ByteBuffer;
3232
import java.nio.channels.Channel;
3333
import java.nio.channels.ClosedChannelException;
34+
import java.nio.channels.ClosedSelectorException;
3435
import java.nio.channels.NotYetConnectedException;
3536
import java.nio.channels.SelectionKey;
3637
import java.nio.channels.Selector;
@@ -452,9 +453,9 @@ private Object waitSelect(final int operations, final boolean blocking, final bo
452453
try {
453454
result[0] = selector.selectNow();
454455

455-
if ( result[0] == 0 ) {
456+
if (result[0] == 0) {
456457
if ((operations & SelectionKey.OP_READ) != 0 && (operations & SelectionKey.OP_WRITE) != 0) {
457-
if ( key.isReadable() ) {
458+
if (key.isReadable()) {
458459
writeWouldBlock(runtime, exception, result);
459460
}
460461
//else if ( key.isWritable() ) {
@@ -463,28 +464,27 @@ private Object waitSelect(final int operations, final boolean blocking, final bo
463464
else { //neither, pick one
464465
readWouldBlock(runtime, exception, result);
465466
}
466-
}
467-
else if ((operations & SelectionKey.OP_READ) != 0) {
467+
} else if ((operations & SelectionKey.OP_READ) != 0) {
468468
readWouldBlock(runtime, exception, result);
469-
}
470-
else if ((operations & SelectionKey.OP_WRITE) != 0) {
469+
} else if ((operations & SelectionKey.OP_WRITE) != 0) {
471470
writeWouldBlock(runtime, exception, result);
472471
}
473472
}
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);
477477
}
478478
} else {
479479
io.addBlockingThread(thread);
480480
thread.executeBlockingTask(new RubyThread.BlockingTask() {
481-
public void run() throws InterruptedException {
481+
public void run() {
482482
try {
483483
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);
488488
}
489489
}
490490

src/main/java/org/jruby/ext/openssl/Utils.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,25 @@ final class Utils {
4949
private Utils() {}
5050

5151
static RaiseException newIOError(Ruby runtime, IOException e) {
52-
RaiseException ex = newIOError(runtime, e.getMessage());
53-
ex.initCause(e);
54-
return ex;
52+
return newIOError(runtime, e.getMessage(), e);
5553
}
5654

5755
static RaiseException newIOError(Ruby runtime, String msg) {
5856
return new RaiseException(runtime, runtime.getIOError(), msg, true);
5957
}
6058

59+
static RaiseException newIOError(Ruby runtime, String msg, Exception e) {
60+
RaiseException ex = newIOError(runtime, msg);
61+
ex.initCause(e);
62+
return ex;
63+
}
64+
6165
static RaiseException newRuntimeError(Ruby runtime, Exception e) {
62-
RaiseException ex = newRuntimeError(runtime, e.getMessage());
66+
return newRuntimeError(runtime, e.getMessage(), e);
67+
}
68+
69+
static RaiseException newRuntimeError(Ruby runtime, String msg, Exception e) {
70+
RaiseException ex = newRuntimeError(runtime, msg);
6371
ex.initCause(e);
6472
return ex;
6573
}

0 commit comments

Comments
 (0)