Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
shutdown
  • Loading branch information
youknowone committed Oct 25, 2025
commit 5b2b64c40ef72a2d960d95b38cbb752ea032cb0f
34 changes: 33 additions & 1 deletion stdlib/src/ssl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1310,11 +1310,43 @@ mod _ssl {
#[cfg(not(ossl111))]
{
Err(vm.new_not_implemented_error(
"Post-handshake auth is not supported by your OpenSSL version.".to_owned()
"Post-handshake auth is not supported by your OpenSSL version.".to_owned(),
))
}
}

#[pymethod]
fn shutdown(&self, vm: &VirtualMachine) -> PyResult<PyRef<PySocket>> {
let stream = self.stream.read();
let ssl_ptr = stream.ssl().as_ptr();

// Perform SSL shutdown
let ret = unsafe { sys::SSL_shutdown(ssl_ptr) };

if ret < 0 {
// Error occurred
let err = unsafe {
let err_code = sys::SSL_get_error(ssl_ptr, ret);
err_code
};

if err == sys::SSL_ERROR_WANT_READ || err == sys::SSL_ERROR_WANT_WRITE {
// Non-blocking would block - this is okay for shutdown
// Return the underlying socket
} else {
return Err(vm.new_exception_msg(
ssl_error(vm),
format!("SSL shutdown failed: error code {}", err),
));
}
}

// Return the underlying socket
// Get the socket from the stream (SocketStream wraps PyRef<PySocket>)
let socket = stream.get_ref();
Ok(socket.0.clone())
}

#[cfg(osslconf = "OPENSSL_NO_COMP")]
#[pymethod]
fn compression(&self) -> Option<&'static str> {
Expand Down