Skip to content

Commit 23af9c9

Browse files
committed
add event_timeout method to SslRef
1 parent 538a5cb commit 23af9c9

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

openssl/src/ssl/mod.rs

+34
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ use std::path::Path;
104104
use std::ptr;
105105
use std::str;
106106
use std::sync::{Arc, Mutex};
107+
#[cfg(ossl320)]
108+
use std::time::Duration;
107109

108110
pub use crate::ssl::connector::{
109111
ConnectConfiguration, SslAcceptor, SslAcceptorBuilder, SslConnector, SslConnectorBuilder,
@@ -3470,6 +3472,38 @@ impl SslRef {
34703472
}
34713473
}
34723474
}
3475+
3476+
/// Returns a duration after which openssl needs to be called again to handle
3477+
/// time sensitive events. The duration may be ZERO, indicating that there are
3478+
/// events that need to be handled immediatly.
3479+
#[corresponds(SSL_get_event_timeout)]
3480+
#[cfg(ossl320)]
3481+
pub fn event_timeout(&self) -> Result<Option<Duration>, ErrorStack> {
3482+
unsafe {
3483+
let mut tv = libc::timeval {
3484+
tv_sec: 0,
3485+
tv_usec: 0,
3486+
};
3487+
let mut is_infinite = 0;
3488+
3489+
cvt(ffi::SSL_get_event_timeout(
3490+
self.as_ptr(),
3491+
&mut tv,
3492+
&mut is_infinite,
3493+
))?;
3494+
3495+
if is_infinite == 1 {
3496+
return Ok(None);
3497+
}
3498+
3499+
let timeout = Duration::new(
3500+
u64::try_from(tv.tv_sec).unwrap(),
3501+
u32::try_from(tv.tv_usec).unwrap() * 1000,
3502+
);
3503+
3504+
Ok(Some(timeout))
3505+
}
3506+
}
34733507
}
34743508

34753509
/// An SSL stream midway through the handshake process.

0 commit comments

Comments
 (0)