Skip to content

Commit

Permalink
add event_timeout method to SslRef
Browse files Browse the repository at this point in the history
  • Loading branch information
kbalt committed Dec 29, 2024
1 parent 538a5cb commit 23af9c9
Showing 1 changed file with 34 additions and 0 deletions.
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

0 comments on commit 23af9c9

Please sign in to comment.