From dd46d1922e4706cf4c15c8cd915c1254363def8c Mon Sep 17 00:00:00 2001 From: Valerii Hiora Date: Mon, 13 Oct 2014 17:41:03 +0300 Subject: Correct init mutexes and locking function `libcrypto` uses locks quite intensively even without SSL. So they should be initialized before everything else to function properly in multi-threaded apps in which SSL operations are absent or delayed. Finishes #79 --- src/ssl/mod.rs | 23 +---------------------- 1 file changed, 1 insertion(+), 22 deletions(-) (limited to 'src/ssl') diff --git a/src/ssl/mod.rs b/src/ssl/mod.rs index 86b3ec83..0ed3c2e8 100644 --- a/src/ssl/mod.rs +++ b/src/ssl/mod.rs @@ -1,8 +1,7 @@ -use libc::{c_int, c_void, c_char, c_long}; +use libc::{c_int, c_void, c_long}; use std::io::{IoResult, IoError, EndOfFile, Stream, Reader, Writer}; use std::mem; use std::ptr; -use std::rt::mutex::NativeMutex; use std::string; use sync::one::{Once, ONCE_INIT}; @@ -16,7 +15,6 @@ pub mod error; mod tests; static mut VERIFY_IDX: c_int = -1; -static mut MUTEXES: *mut Vec = 0 as *mut Vec; fn init() { static mut INIT: Once = ONCE_INIT; @@ -29,12 +27,6 @@ fn init() { None, None); assert!(verify_idx >= 0); VERIFY_IDX = verify_idx; - - let num_locks = ffi::CRYPTO_num_locks(); - let mutexes = box Vec::from_fn(num_locks as uint, |_| NativeMutex::new()); - MUTEXES = mem::transmute(mutexes); - - ffi::CRYPTO_set_locking_callback(locking_function); }); } } @@ -109,19 +101,6 @@ fn get_verify_data_idx() -> c_int { } } -extern fn locking_function(mode: c_int, n: c_int, _file: *const c_char, - _line: c_int) { - unsafe { - let mutex = (*MUTEXES).get_mut(n as uint); - - if mode & ffi::CRYPTO_LOCK != 0 { - mutex.lock_noguard(); - } else { - mutex.unlock_noguard(); - } - } -} - extern fn raw_verify(preverify_ok: c_int, x509_ctx: *mut ffi::X509_STORE_CTX) -> c_int { unsafe { -- cgit v1.2.3