Skip to content

Commit 6f155e7

Browse files
committed
[refactor] ssl handshake wrap-ing - do tasks eagerly
1 parent 444dd6b commit 6f155e7

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

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

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -586,10 +586,8 @@ private IRubyObject doHandshake(final boolean blocking, final boolean exception)
586586
if ( netData.hasRemaining() ) {
587587
while ( flushData(blocking) ) { /* loop */ }
588588
}
589-
netData.clear();
590-
SSLEngineResult result = engine.wrap(dummy, netData);
591-
handshakeStatus = result.getHandshakeStatus();
592-
netData.flip();
589+
assert !netData.hasRemaining();
590+
doWrap(blocking);
593591
flushData(blocking);
594592
break;
595593
default:
@@ -598,6 +596,18 @@ private IRubyObject doHandshake(final boolean blocking, final boolean exception)
598596
}
599597
}
600598

599+
private void doWrap(boolean blocking) throws IOException {
600+
netData.clear();
601+
SSLEngineResult result = engine.wrap(dummy, netData);
602+
netData.flip();
603+
handshakeStatus = result.getHandshakeStatus();
604+
status = result.getStatus();
605+
if (handshakeStatus == SSLEngineResult.HandshakeStatus.NEED_TASK
606+
&& status == SSLEngineResult.Status.OK) {
607+
doTasks();
608+
}
609+
}
610+
601611
private void doTasks() {
602612
Runnable task;
603613
while ((task = engine.getDelegatedTask()) != null) {

0 commit comments

Comments
 (0)