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 @@ -1310,11 +1310,43 @@ mod _ssl {
13101310 #[ cfg( not( ossl111) ) ]
13111311 {
13121312 Err ( vm. new_not_implemented_error (
1313- "Post-handshake auth is not supported by your OpenSSL version." . to_owned ( )
1313+ "Post-handshake auth is not supported by your OpenSSL version." . to_owned ( ) ,
13141314 ) )
13151315 }
13161316 }
13171317
1318+ #[ pymethod]
1319+ fn shutdown ( & self , vm : & VirtualMachine ) -> PyResult < PyRef < PySocket > > {
1320+ let stream = self . stream . read ( ) ;
1321+ let ssl_ptr = stream. ssl ( ) . as_ptr ( ) ;
1322+
1323+ // Perform SSL shutdown
1324+ let ret = unsafe { sys:: SSL_shutdown ( ssl_ptr) } ;
1325+
1326+ if ret < 0 {
1327+ // Error occurred
1328+ let err = unsafe {
1329+ let err_code = sys:: SSL_get_error ( ssl_ptr, ret) ;
1330+ err_code
1331+ } ;
1332+
1333+ if err == sys:: SSL_ERROR_WANT_READ || err == sys:: SSL_ERROR_WANT_WRITE {
1334+ // Non-blocking would block - this is okay for shutdown
1335+ // Return the underlying socket
1336+ } else {
1337+ return Err ( vm. new_exception_msg (
1338+ ssl_error ( vm) ,
1339+ format ! ( "SSL shutdown failed: error code {}" , err) ,
1340+ ) ) ;
1341+ }
1342+ }
1343+
1344+ // Return the underlying socket
1345+ // Get the socket from the stream (SocketStream wraps PyRef<PySocket>)
1346+ let socket = stream. get_ref ( ) ;
1347+ Ok ( socket. 0 . clone ( ) )
1348+ }
1349+
13181350 #[ cfg( osslconf = "OPENSSL_NO_COMP" ) ]
13191351 #[ pymethod]
13201352 fn compression ( & self ) -> Option < & ' static str > {
You can’t perform that action at this time.
0 commit comments