Skip to content

Commit 306e4ad

Browse files
committed
add event_timeout method to SslRef
1 parent 538a5cb commit 306e4ad

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

openssl/src/ssl/mod.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ use std::path::Path;
104104
use std::ptr;
105105
use std::str;
106106
use std::sync::{Arc, Mutex};
107+
use std::time::Duration;
107108

108109
pub use crate::ssl::connector::{
109110
ConnectConfiguration, SslAcceptor, SslAcceptorBuilder, SslConnector, SslConnectorBuilder,
@@ -3470,6 +3471,36 @@ impl SslRef {
34703471
}
34713472
}
34723473
}
3474+
3475+
/// Returns a duration after which openssl needs to be called again to handle
3476+
/// time sensitive events. The duration may be ZERO, indicating that there are
3477+
/// events that need to be handled immediatly.
3478+
#[corresponds(SSL_get_event_timeout)]
3479+
#[cfg(ossl320)]
3480+
pub fn event_timeout(&self) -> Result<Option<Duration>, ErrorStack> {
3481+
unsafe {
3482+
let mut tv = libc::timeval {
3483+
tv_sec: 0,
3484+
tv_usec: 0,
3485+
};
3486+
let mut is_infinite = 0;
3487+
3488+
cvt(ffi::SSL_get_event_timeout(
3489+
self.as_ptr(),
3490+
&mut tv,
3491+
&mut is_infinite,
3492+
))?;
3493+
3494+
if is_infinite == 1 {
3495+
return Ok(None);
3496+
}
3497+
3498+
let timeout = Duration::from_secs(tv.tv_sec.try_into().unwrap())
3499+
+ Duration::from_micros(tv.tv_usec.try_into().unwrap());
3500+
3501+
Ok(Some(timeout))
3502+
}
3503+
}
34733504
}
34743505

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

0 commit comments

Comments
 (0)