59
59
import com .oracle .graal .python .nodes .ErrorMessages ;
60
60
import com .oracle .graal .python .nodes .PNodeWithRaise ;
61
61
import com .oracle .graal .python .nodes .PRaiseNode ;
62
+ import com .oracle .graal .python .runtime .GilNode ;
62
63
import com .oracle .graal .python .runtime .exception .PException ;
63
64
import com .oracle .graal .python .util .OverflowException ;
64
65
import com .oracle .truffle .api .CompilerDirectives ;
@@ -392,6 +393,7 @@ private static PException handleSSLException(PNodeWithRaise node, SSLException e
392
393
throw PRaiseSSLErrorNode .raiseUncached (node , SSLErrorCode .ERROR_SSL , e .toString ());
393
394
}
394
395
396
+ @ SuppressWarnings ("try" )
395
397
private static int obtainMoreInput (PNodeWithRaise node , SSLEngine engine , PMemoryBIO networkInboundBIO , PSocket socket , TimeoutHelper timeoutHelper ) throws IOException , OverflowException {
396
398
if (socket != null ) {
397
399
if (socket .getSocket () == null ) {
@@ -426,7 +428,7 @@ private static int obtainMoreInput(PNodeWithRaise node, SSLEngine engine, PMemor
426
428
ByteBuffer writeBuffer = networkInboundBIO .getBufferForWriting ();
427
429
// Avoid reading more that we determined
428
430
writeBuffer .limit (writeBuffer .position () + toRead );
429
- try {
431
+ try ( GilNode . UncachedRelease gil = GilNode . uncachedRelease ()) {
430
432
return SocketUtils .recv (node , socket , writeBuffer , timeoutHelper == null ? 0 : timeoutHelper .checkAndGetRemainingTimeout (node ));
431
433
} finally {
432
434
networkInboundBIO .applyWrite (writeBuffer );
@@ -443,22 +445,25 @@ private static int obtainMoreInput(PNodeWithRaise node, SSLEngine engine, PMemor
443
445
}
444
446
}
445
447
448
+ @ SuppressWarnings ("try" )
446
449
private static void emitOutputOrRaiseWantWrite (PNodeWithRaise node , PMemoryBIO networkOutboundBIO , PSocket socket , TimeoutHelper timeoutHelper ) throws IOException {
447
450
if (socket != null && networkOutboundBIO .getPending () > 0 ) {
448
451
if (socket .getSocket () == null ) {
449
452
// TODO use raiseOsError with ENOTCONN
450
453
throw node .raise (OSError );
451
454
}
455
+ int pendingBytes = networkOutboundBIO .getPending ();
452
456
// Network output
453
457
ByteBuffer readBuffer = networkOutboundBIO .getBufferForReading ();
454
- try {
455
- int writtenBytes = SocketUtils .send (node , socket , readBuffer , timeoutHelper == null ? 0 : timeoutHelper .checkAndGetRemainingTimeout (node ));
456
- if (writtenBytes == 0 ) {
457
- throw PRaiseSSLErrorNode .raiseUncached (node , SSLErrorCode .ERROR_WANT_WRITE , ErrorMessages .SSL_WANT_WRITE );
458
- }
458
+ int writtenBytes ;
459
+ try (GilNode .UncachedRelease gil = GilNode .uncachedRelease ()) {
460
+ writtenBytes = SocketUtils .send (node , socket , readBuffer , timeoutHelper == null ? 0 : timeoutHelper .checkAndGetRemainingTimeout (node ));
459
461
} finally {
460
462
networkOutboundBIO .applyRead (readBuffer );
461
463
}
464
+ if (writtenBytes < pendingBytes ) {
465
+ throw PRaiseSSLErrorNode .raiseUncached (node , SSLErrorCode .ERROR_WANT_WRITE , ErrorMessages .SSL_WANT_WRITE );
466
+ }
462
467
}
463
468
}
464
469
}
0 commit comments