5959import com .oracle .graal .python .nodes .ErrorMessages ;
6060import com .oracle .graal .python .nodes .PNodeWithRaise ;
6161import com .oracle .graal .python .nodes .PRaiseNode ;
62+ import com .oracle .graal .python .runtime .GilNode ;
6263import com .oracle .graal .python .runtime .exception .PException ;
6364import com .oracle .graal .python .util .OverflowException ;
6465import com .oracle .truffle .api .CompilerDirectives ;
@@ -392,6 +393,7 @@ private static PException handleSSLException(PNodeWithRaise node, SSLException e
392393 throw PRaiseSSLErrorNode .raiseUncached (node , SSLErrorCode .ERROR_SSL , e .toString ());
393394 }
394395
396+ @ SuppressWarnings ("try" )
395397 private static int obtainMoreInput (PNodeWithRaise node , SSLEngine engine , PMemoryBIO networkInboundBIO , PSocket socket , TimeoutHelper timeoutHelper ) throws IOException , OverflowException {
396398 if (socket != null ) {
397399 if (socket .getSocket () == null ) {
@@ -426,7 +428,7 @@ private static int obtainMoreInput(PNodeWithRaise node, SSLEngine engine, PMemor
426428 ByteBuffer writeBuffer = networkInboundBIO .getBufferForWriting ();
427429 // Avoid reading more that we determined
428430 writeBuffer .limit (writeBuffer .position () + toRead );
429- try {
431+ try ( GilNode . UncachedRelease gil = GilNode . uncachedRelease ()) {
430432 return SocketUtils .recv (node , socket , writeBuffer , timeoutHelper == null ? 0 : timeoutHelper .checkAndGetRemainingTimeout (node ));
431433 } finally {
432434 networkInboundBIO .applyWrite (writeBuffer );
@@ -443,22 +445,25 @@ private static int obtainMoreInput(PNodeWithRaise node, SSLEngine engine, PMemor
443445 }
444446 }
445447
448+ @ SuppressWarnings ("try" )
446449 private static void emitOutputOrRaiseWantWrite (PNodeWithRaise node , PMemoryBIO networkOutboundBIO , PSocket socket , TimeoutHelper timeoutHelper ) throws IOException {
447450 if (socket != null && networkOutboundBIO .getPending () > 0 ) {
448451 if (socket .getSocket () == null ) {
449452 // TODO use raiseOsError with ENOTCONN
450453 throw node .raise (OSError );
451454 }
455+ int pendingBytes = networkOutboundBIO .getPending ();
452456 // Network output
453457 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 ));
459461 } finally {
460462 networkOutboundBIO .applyRead (readBuffer );
461463 }
464+ if (writtenBytes < pendingBytes ) {
465+ throw PRaiseSSLErrorNode .raiseUncached (node , SSLErrorCode .ERROR_WANT_WRITE , ErrorMessages .SSL_WANT_WRITE );
466+ }
462467 }
463468 }
464469}
0 commit comments