summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2016-11-26 08:45:57 -0800
committerAlex Crichton <alex@alexcrichton.com>2016-11-26 08:45:57 -0800
commit891db584c1e7706e3075cea454f639ff3272c2a3 (patch)
treed575dc0e21c08455b5fdd535d3f45c0cd9636a28
parent221c0d844daad0180422aa23167b9e306897fe07 (diff)
downloadssh2-rs-891db584c1e7706e3075cea454f639ff3272c2a3.zip
Push init synchronization to sys layer
-rw-r--r--Cargo.toml3
-rw-r--r--libssh2-sys/lib.rs21
-rw-r--r--src/lib.rs18
3 files changed, 22 insertions, 20 deletions
diff --git a/Cargo.toml b/Cargo.toml
index 426aed9..4a526e4 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -21,8 +21,5 @@ bitflags = "0.7"
libc = "0.2"
libssh2-sys = { path = "libssh2-sys", version = "0.2" }
-[target."cfg(unix)".dependencies]
-openssl-sys = "0.9"
-
[dev-dependencies]
tempdir = "0.3"
diff --git a/libssh2-sys/lib.rs b/libssh2-sys/lib.rs
index 660587a..2432b55 100644
--- a/libssh2-sys/lib.rs
+++ b/libssh2-sys/lib.rs
@@ -533,4 +533,25 @@ fn smoke() {
unsafe { libssh2_init(0) };
}
+#[doc(hidden)]
pub fn issue_14344_workaround() {}
+
+pub fn init() {
+ use std::sync::{Once, ONCE_INIT};
+
+ static INIT: Once = ONCE_INIT;
+ INIT.call_once(|| unsafe {
+ platform_init();
+ assert_eq!(libssh2_init(LIBSSH2_INIT_NO_CRYPTO), 0);
+ assert_eq!(libc::atexit(shutdown), 0);
+ });
+ extern fn shutdown() { unsafe { libssh2_exit(); } }
+
+ #[cfg(unix)]
+ fn platform_init() {
+ openssl_sys::init();
+ }
+
+ #[cfg(windows)]
+ fn platform_init() {}
+}
diff --git a/src/lib.rs b/src/lib.rs
index cf05eb5..2c60572 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -133,7 +133,6 @@ extern crate libc;
#[macro_use] extern crate bitflags;
use std::ffi::CStr;
-use std::sync::{Once, ONCE_INIT};
pub use agent::{Agent, Identities, PublicKey};
pub use channel::{Channel, ExitSignal, ReadWindow, WriteWindow, Stream};
@@ -164,22 +163,7 @@ mod util;
///
/// This is optional, it is lazily invoked.
pub fn init() {
- static INIT: Once = ONCE_INIT;
- INIT.call_once(|| unsafe {
- platform_init();
- assert_eq!(raw::libssh2_init(raw::LIBSSH2_INIT_NO_CRYPTO), 0);
- assert_eq!(libc::atexit(shutdown), 0);
- });
- extern fn shutdown() { unsafe { raw::libssh2_exit(); } }
-
- #[cfg(unix)]
- fn platform_init() {
- extern crate openssl_sys;
- openssl_sys::init();
- }
-
- #[cfg(windows)]
- fn platform_init() {}
+ raw::init();
}
unsafe fn opt_bytes<'a, T>(_: &'a T,