aboutsummaryrefslogtreecommitdiff
path: root/openssl/src/ssl/bio.rs
diff options
context:
space:
mode:
Diffstat (limited to 'openssl/src/ssl/bio.rs')
-rw-r--r--openssl/src/ssl/bio.rs54
1 files changed, 6 insertions, 48 deletions
diff --git a/openssl/src/ssl/bio.rs b/openssl/src/ssl/bio.rs
index aa445562..8d295928 100644
--- a/openssl/src/ssl/bio.rs
+++ b/openssl/src/ssl/bio.rs
@@ -11,9 +11,6 @@ use std::sync::Arc;
use ssl::error::SslError;
-// "rust"
-const NAME: [c_char; 5] = [114, 117, 115, 116, 0];
-
pub struct StreamState<S> {
pub stream: S,
pub error: Option<io::Error>,
@@ -23,7 +20,7 @@ pub struct StreamState<S> {
pub fn new<S: Read + Write>(stream: S) -> Result<(*mut BIO, Arc<BIO_METHOD>), SslError> {
let method = Arc::new(BIO_METHOD {
type_: BIO_TYPE_NONE,
- name: &NAME[0],
+ name: b"rust\0".as_ptr() as *const _,
bwrite: Some(bwrite::<S>),
bread: Some(bread::<S>),
bputs: Some(bputs::<S>),
@@ -74,8 +71,8 @@ unsafe fn state<'a, S: 'a>(bio: *mut BIO) -> &'a mut StreamState<S> {
}
#[cfg(feature = "nightly")]
-fn recover<F, T>(f: F) -> Result<T, Box<Any + Send>> where F: FnOnce() -> T + ::std::panic::RecoverSafe {
- ::std::panic::recover(f)
+fn recover<F, T>(f: F) -> Result<T, Box<Any + Send>> where F: FnOnce() -> T {
+ ::std::panic::recover(::std::panic::AssertRecoverSafe::new(f))
}
#[cfg(not(feature = "nightly"))]
@@ -83,45 +80,13 @@ fn recover<F, T>(f: F) -> Result<T, Box<Any + Send>> where F: FnOnce() -> T {
Ok(f())
}
-#[cfg(feature = "nightly")]
-use std::panic::AssertRecoverSafe;
-
-#[cfg(not(feature = "nightly"))]
-struct AssertRecoverSafe<T>(T);
-
-#[cfg(not(feature = "nightly"))]
-impl<T> AssertRecoverSafe<T> {
- fn new(t: T) -> Self {
- AssertRecoverSafe(t)
- }
-}
-
-#[cfg(not(feature = "nightly"))]
-impl<T> ::std::ops::Deref for AssertRecoverSafe<T> {
- type Target = T;
-
- fn deref(&self) -> &T {
- &self.0
- }
-}
-
-#[cfg(not(feature = "nightly"))]
-impl<T> ::std::ops::DerefMut for AssertRecoverSafe<T> {
- fn deref_mut(&mut self) -> &mut T {
- &mut self.0
- }
-}
-
unsafe extern "C" fn bwrite<S: Write>(bio: *mut BIO, buf: *const c_char, len: c_int) -> c_int {
BIO_clear_retry_flags(bio);
let state = state::<S>(bio);
let buf = slice::from_raw_parts(buf as *const _, len as usize);
- let result = {
- let mut youre_not_my_supervisor = AssertRecoverSafe::new(&mut *state);
- recover(move || youre_not_my_supervisor.stream.write(buf))
- };
+ let result = recover(|| state.stream.write(buf));
match result {
Ok(Ok(len)) => len as c_int,
@@ -145,11 +110,7 @@ unsafe extern "C" fn bread<S: Read>(bio: *mut BIO, buf: *mut c_char, len: c_int)
let state = state::<S>(bio);
let buf = slice::from_raw_parts_mut(buf as *mut _, len as usize);
- let result = {
- let mut youre_not_my_supervisor = AssertRecoverSafe::new(&mut *state);
- let mut fuuuu = AssertRecoverSafe::new(buf);
- recover(move || youre_not_my_supervisor.stream.read(&mut *fuuuu))
- };
+ let result = recover(|| state.stream.read(buf));
match result {
Ok(Ok(len)) => len as c_int,
@@ -185,10 +146,7 @@ unsafe extern "C" fn ctrl<S: Write>(bio: *mut BIO,
-> c_long {
if cmd == BIO_CTRL_FLUSH {
let state = state::<S>(bio);
- let result = {
- let mut youre_not_my_supervisor = AssertRecoverSafe::new(&mut *state);
- recover(move || youre_not_my_supervisor.stream.flush())
- };
+ let result = recover(|| state.stream.flush());
match result {
Ok(Ok(())) => 1,