aboutsummaryrefslogtreecommitdiff
path: root/openssl/src/ssl/bio.rs
diff options
context:
space:
mode:
authorSteven Fackler <[email protected]>2016-11-19 10:19:52 -0800
committerSteven Fackler <[email protected]>2016-11-27 21:00:59 -0800
commit234f126d7d9718bd95655aca5fa6f57dc2c4270a (patch)
tree2b389e1abb4419c03c70eaa7daa68d72539a02d0 /openssl/src/ssl/bio.rs
parentReturn Option from group (diff)
downloadrust-openssl-234f126d7d9718bd95655aca5fa6f57dc2c4270a.tar.xz
rust-openssl-234f126d7d9718bd95655aca5fa6f57dc2c4270a.zip
Cleanup
Diffstat (limited to 'openssl/src/ssl/bio.rs')
-rw-r--r--openssl/src/ssl/bio.rs13
1 files changed, 4 insertions, 9 deletions
diff --git a/openssl/src/ssl/bio.rs b/openssl/src/ssl/bio.rs
index 486b4dba..c5152a41 100644
--- a/openssl/src/ssl/bio.rs
+++ b/openssl/src/ssl/bio.rs
@@ -5,6 +5,7 @@ use std::any::Any;
use std::io;
use std::io::prelude::*;
use std::mem;
+use std::panic::{AssertUnwindSafe, catch_unwind};
use std::ptr;
use std::slice;
@@ -70,19 +71,13 @@ unsafe fn state<'a, S: 'a>(bio: *mut BIO) -> &'a mut StreamState<S> {
mem::transmute(compat::BIO_get_data(bio))
}
-fn catch_unwind<F, T>(f: F) -> Result<T, Box<Any + Send>>
- where F: FnOnce() -> T
-{
- ::std::panic::catch_unwind(::std::panic::AssertUnwindSafe(f))
-}
-
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);
- match catch_unwind(|| state.stream.write(buf)) {
+ match catch_unwind(AssertUnwindSafe(|| state.stream.write(buf))) {
Ok(Ok(len)) => len as c_int,
Ok(Err(err)) => {
if retriable_error(&err) {
@@ -104,7 +99,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);
- match catch_unwind(|| state.stream.read(buf)) {
+ match catch_unwind(AssertUnwindSafe(|| state.stream.read(buf))) {
Ok(Ok(len)) => len as c_int,
Ok(Err(err)) => {
if retriable_error(&err) {
@@ -140,7 +135,7 @@ unsafe extern "C" fn ctrl<S: Write>(bio: *mut BIO,
if cmd == BIO_CTRL_FLUSH {
let state = state::<S>(bio);
- match catch_unwind(|| state.stream.flush()) {
+ match catch_unwind(AssertUnwindSafe(|| state.stream.flush())) {
Ok(Ok(())) => 1,
Ok(Err(err)) => {
state.error = Some(err);