From 23af9c9f600db1d3d4d7c6554d29408a954df576 Mon Sep 17 00:00:00 2001 From: Konstantin Baltruschat Date: Fri, 27 Dec 2024 15:29:21 +0100 Subject: [PATCH] add event_timeout method to SslRef --- openssl/src/ssl/mod.rs | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/openssl/src/ssl/mod.rs b/openssl/src/ssl/mod.rs index f5a696ab5..eeaf13553 100644 --- a/openssl/src/ssl/mod.rs +++ b/openssl/src/ssl/mod.rs @@ -104,6 +104,8 @@ use std::path::Path; use std::ptr; use std::str; use std::sync::{Arc, Mutex}; +#[cfg(ossl320)] +use std::time::Duration; pub use crate::ssl::connector::{ ConnectConfiguration, SslAcceptor, SslAcceptorBuilder, SslConnector, SslConnectorBuilder, @@ -3470,6 +3472,38 @@ impl SslRef { } } } + + /// Returns a duration after which openssl needs to be called again to handle + /// time sensitive events. The duration may be ZERO, indicating that there are + /// events that need to be handled immediatly. + #[corresponds(SSL_get_event_timeout)] + #[cfg(ossl320)] + pub fn event_timeout(&self) -> Result, ErrorStack> { + unsafe { + let mut tv = libc::timeval { + tv_sec: 0, + tv_usec: 0, + }; + let mut is_infinite = 0; + + cvt(ffi::SSL_get_event_timeout( + self.as_ptr(), + &mut tv, + &mut is_infinite, + ))?; + + if is_infinite == 1 { + return Ok(None); + } + + let timeout = Duration::new( + u64::try_from(tv.tv_sec).unwrap(), + u32::try_from(tv.tv_usec).unwrap() * 1000, + ); + + Ok(Some(timeout)) + } + } } /// An SSL stream midway through the handshake process.