Skip to content
Open
Changes from all commits
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
34 changes: 34 additions & 0 deletions openssl/src/ssl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<Option<Duration>, 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.
Expand Down
Loading