File tree Expand file tree Collapse file tree 1 file changed +33
-1
lines changed
Expand file tree Collapse file tree 1 file changed +33
-1
lines changed Original file line number Diff line number Diff line change @@ -1338,11 +1338,43 @@ mod _ssl {
13381338 #[ cfg( not( ossl111) ) ]
13391339 {
13401340 Err ( vm. new_not_implemented_error (
1341- "Post-handshake auth is not supported by your OpenSSL version." . to_owned ( )
1341+ "Post-handshake auth is not supported by your OpenSSL version." . to_owned ( ) ,
13421342 ) )
13431343 }
13441344 }
13451345
1346+ #[ pymethod]
1347+ fn shutdown ( & self , vm : & VirtualMachine ) -> PyResult < PyObjectRef > {
1348+ let stream = self . stream . read ( ) ;
1349+ let ssl_ptr = stream. ssl ( ) . as_ptr ( ) ;
1350+
1351+ // Perform SSL shutdown
1352+ let ret = unsafe { sys:: SSL_shutdown ( ssl_ptr) } ;
1353+
1354+ if ret < 0 {
1355+ // Error occurred
1356+ let err = unsafe {
1357+ let err_code = sys:: SSL_get_error ( ssl_ptr, ret) ;
1358+ err_code
1359+ } ;
1360+
1361+ if err == sys:: SSL_ERROR_WANT_READ || err == sys:: SSL_ERROR_WANT_WRITE {
1362+ // Non-blocking would block - this is okay for shutdown
1363+ // Return the underlying socket
1364+ } else {
1365+ return Err ( vm. new_exception_msg (
1366+ ssl_error ( vm) ,
1367+ format ! ( "SSL shutdown failed: error code {}" , err) ,
1368+ ) ) ;
1369+ }
1370+ }
1371+
1372+ // Return the underlying socket
1373+ // Get the socket from the stream (SocketStream wraps PyRef<PySocket>)
1374+ let socket = stream. get_ref ( ) ;
1375+ Ok ( socket. 0 . clone ( ) . into ( ) )
1376+ }
1377+
13461378 #[ cfg( osslconf = "OPENSSL_NO_COMP" ) ]
13471379 #[ pymethod]
13481380 fn compression ( & self ) -> Option < & ' static str > {
You can’t perform that action at this time.
0 commit comments