Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add event_timeout method to SslRef #2341

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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