Skip to content

Commit

Permalink
[fix] adjust write fix to revert regressions (hangs)
Browse files Browse the repository at this point in the history
follow-up on 75a66e1
which would not work with the higher level syswrite usage
  • Loading branch information
kares committed Jul 2, 2022
1 parent 68d4c2f commit 744b489
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/main/java/org/jruby/ext/openssl/SSLSocket.java
Original file line number Diff line number Diff line change
Expand Up @@ -674,28 +674,32 @@ public int write(ByteBuffer src, boolean blocking) throws SSLException, IOExcept
final boolean blockingMode = channel.isBlocking();
if ( ! blocking ) channel.configureBlocking(false);

int written = 0;
boolean loop = false; int written = 0;
try {
while (true) {
if (netWriteData.hasRemaining()) flushData(blocking);
else if (!src.hasRemaining()) break;

if (netWriteData.hasRemaining()) flushData(blocking);
do {
netWriteData.clear();
final SSLEngineResult result = engine.wrap(src, netWriteData);
netWriteData.flip();

switch (result.getStatus()) {
case OK:
loop = flushData(blocking) && src.hasRemaining();
written += result.bytesConsumed();
break;
case BUFFER_OVERFLOW:
netWriteData = Utils.ensureCapacity(netWriteData, engine.getSession().getPacketBufferSize());
netWriteData.position(netWriteData.limit());
loop = true; // src.hasRemaining();
if (netWriteData.hasRemaining()) flushData(blocking);
break;
case CLOSED:
throw getRuntime().newIOError("closed SSL engine"); // EOF?
case BUFFER_UNDERFLOW:
debug("SSLSocket.write unexpected BUFFER_UNDERFLOW");
return written;
}
}
} while (loop);
}
finally {
if ( ! blocking ) channel.configureBlocking(blockingMode);
Expand Down

0 comments on commit 744b489

Please sign in to comment.