diff options
author | Alex Crichton <alex@alexcrichton.com> | 2015-01-18 16:14:08 -0800 |
---|---|---|
committer | Alex Crichton <alex@alexcrichton.com> | 2015-01-18 16:14:08 -0800 |
commit | e2f2c5046f6079d80ed21ae21afc55249dff478a (patch) | |
tree | 79b61a47b057d3c8c555417d46402f752e1c26c0 /tests/all.rs | |
parent | fd5b63c00e83d498a4badcc8cf2a7559ba0f4aa6 (diff) | |
download | ssh2-rs-e2f2c5046f6079d80ed21ae21afc55249dff478a.zip |
Tweak impls/apis
Lots of changes, but largely cosmetic, reorganization, or internal refactorings.
Diffstat (limited to 'tests/all.rs')
-rw-r--r-- | tests/all.rs | 36 |
1 files changed, 4 insertions, 32 deletions
diff --git a/tests/all.rs b/tests/all.rs index 2b194f7..590d7d9 100644 --- a/tests/all.rs +++ b/tests/all.rs @@ -4,6 +4,7 @@ extern crate libc; use std::mem; use std::num::Int; use std::os; +use std::io::TcpStream; mod agent; mod session; @@ -11,34 +12,15 @@ mod channel; mod knownhosts; mod sftp; -pub struct TcpStream(libc::c_int); - pub fn socket() -> TcpStream { - unsafe { - let socket = libc::socket(libc::AF_INET, libc::SOCK_STREAM, 0); - assert!(socket != -1, "{} {}", os::errno(), os::last_os_error()); - - let addr = libc::sockaddr_in { - sin_family: libc::AF_INET as libc::sa_family_t, - sin_port: 22.to_be(), - sin_addr: libc::in_addr { - s_addr: 0x7f000001.to_be(), - }, - ..mem::zeroed() - }; - - let r = libc::connect(socket, &addr as *const _ as *const _, - mem::size_of_val(&addr) as libc::c_uint); - assert!(r != -1, "{} {}", os::errno(), os::last_os_error()); - TcpStream(socket) - } + TcpStream::connect("127.0.0.1:22").unwrap() } pub fn authed_session() -> (TcpStream, ssh2::Session) { let user = os::getenv("USER").unwrap(); - let mut sess = ssh2::Session::new().unwrap(); let socket = socket(); - sess.handshake(socket.fd()).unwrap(); + let mut sess = ssh2::Session::new().unwrap(); + sess.handshake(&socket).unwrap(); assert!(!sess.authenticated()); { @@ -51,13 +33,3 @@ pub fn authed_session() -> (TcpStream, ssh2::Session) { assert!(sess.authenticated()); (socket, sess) } - -impl TcpStream { - fn fd(&self) -> libc::c_int { let TcpStream(fd) = *self; fd } -} - -impl Drop for TcpStream { - fn drop(&mut self) { - unsafe { libc::close(self.fd()); } - } -} |