summaryrefslogtreecommitdiff
path: root/tests/all.rs
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2014-11-11 10:12:54 -0800
committerAlex Crichton <alex@alexcrichton.com>2014-11-11 10:12:54 -0800
commit27d760680cf7b756298c8cb61fabe3aaefe0e84a (patch)
tree0a104bbaea442d2113bc5e5ca48b0500ad0544bc /tests/all.rs
parentcb6a56021282af938f6d82ab0901428eef0b3e96 (diff)
downloadssh2-rs-27d760680cf7b756298c8cb61fabe3aaefe0e84a.zip
Fix tests and build on windows
Diffstat (limited to 'tests/all.rs')
-rw-r--r--tests/all.rs42
1 files changed, 31 insertions, 11 deletions
diff --git a/tests/all.rs b/tests/all.rs
index cec7985..349ce50 100644
--- a/tests/all.rs
+++ b/tests/all.rs
@@ -1,10 +1,8 @@
extern crate ssh2;
-extern crate native;
-extern crate rustrt;
+extern crate libc;
use std::os;
-use rustrt::rtio::{SocketAddr, Ipv4Addr};
-use native::io::net::TcpStream;
+use std::mem;
mod agent;
mod session;
@@ -12,14 +10,26 @@ mod channel;
mod knownhosts;
mod sftp;
+pub struct TcpStream(libc::c_int);
+
pub fn socket() -> TcpStream {
- let stream = TcpStream::connect(SocketAddr {
- ip: Ipv4Addr(127, 0, 0, 1),
- port: 22,
- }, None);
- match stream {
- Ok(s) => s,
- Err(e) => panic!("no socket: [{}]: {}", e.code, e.detail),
+ 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)
}
}
@@ -40,3 +50,13 @@ 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()); }
+ }
+}