Loading src/ssl/mod.rs +5 −4 Original line number Diff line number Diff line Loading @@ -2,7 +2,7 @@ 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::sync::{Once, ONCE_INIT}; use std::sync::{Once, ONCE_INIT, Arc}; use bio::{MemBio}; use ffi; Loading Loading @@ -397,9 +397,10 @@ enum LibSslError { } /// A stream wrapper which handles SSL encryption for an underlying stream. #[deriving(Clone)] pub struct SslStream<S> { stream: S, ssl: Ssl, ssl: Arc<Ssl>, buf: Vec<u8> } Loading @@ -407,7 +408,7 @@ impl<S: Stream> SslStream<S> { fn new_base(ssl:Ssl, stream: S) -> SslStream<S> { SslStream { stream: stream, ssl: ssl, ssl: Arc::new(ssl), // Maximum TLS record size is 16k buf: Vec::from_elem(16 * 1024, 0u8) } Loading Loading @@ -465,7 +466,7 @@ impl<S: Stream> SslStream<S> { fn in_retry_wrapper(&mut self, blk: |&Ssl| -> c_int) -> Result<c_int, SslError> { loop { let ret = blk(&self.ssl); let ret = blk(&*self.ssl); if ret > 0 { return Ok(ret); } Loading src/ssl/tests.rs +13 −3 Original line number Diff line number Diff line use serialize::hex::FromHex; use std::io::{Writer}; use std::io::net::tcp::TcpStream; use std::str; use crypto::hash::HashType::{SHA256}; use ssl::SslMethod::Sslv23; Loading Loading @@ -191,6 +190,17 @@ fn test_read() { let mut stream = SslStream::new(&SslContext::new(Sslv23).unwrap(), stream).unwrap(); stream.write("GET /\r\n\r\n".as_bytes()).unwrap(); stream.flush().unwrap(); let buf = stream.read_to_end().ok().expect("read error"); print!("{}", str::from_utf8(buf.as_slice())); stream.read_to_end().ok().expect("read error"); } #[test] fn test_clone() { let stream = TcpStream::connect("127.0.0.1:15418").unwrap(); let mut stream = SslStream::new(&SslContext::new(Sslv23).unwrap(), stream).unwrap(); let mut stream2 = stream.clone(); spawn(proc() { stream2.write("GET /\r\n\r\n".as_bytes()).unwrap(); stream2.flush().unwrap(); }); stream.read_to_end().ok().expect("read error"); } Loading
src/ssl/mod.rs +5 −4 Original line number Diff line number Diff line Loading @@ -2,7 +2,7 @@ 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::sync::{Once, ONCE_INIT}; use std::sync::{Once, ONCE_INIT, Arc}; use bio::{MemBio}; use ffi; Loading Loading @@ -397,9 +397,10 @@ enum LibSslError { } /// A stream wrapper which handles SSL encryption for an underlying stream. #[deriving(Clone)] pub struct SslStream<S> { stream: S, ssl: Ssl, ssl: Arc<Ssl>, buf: Vec<u8> } Loading @@ -407,7 +408,7 @@ impl<S: Stream> SslStream<S> { fn new_base(ssl:Ssl, stream: S) -> SslStream<S> { SslStream { stream: stream, ssl: ssl, ssl: Arc::new(ssl), // Maximum TLS record size is 16k buf: Vec::from_elem(16 * 1024, 0u8) } Loading Loading @@ -465,7 +466,7 @@ impl<S: Stream> SslStream<S> { fn in_retry_wrapper(&mut self, blk: |&Ssl| -> c_int) -> Result<c_int, SslError> { loop { let ret = blk(&self.ssl); let ret = blk(&*self.ssl); if ret > 0 { return Ok(ret); } Loading
src/ssl/tests.rs +13 −3 Original line number Diff line number Diff line use serialize::hex::FromHex; use std::io::{Writer}; use std::io::net::tcp::TcpStream; use std::str; use crypto::hash::HashType::{SHA256}; use ssl::SslMethod::Sslv23; Loading Loading @@ -191,6 +190,17 @@ fn test_read() { let mut stream = SslStream::new(&SslContext::new(Sslv23).unwrap(), stream).unwrap(); stream.write("GET /\r\n\r\n".as_bytes()).unwrap(); stream.flush().unwrap(); let buf = stream.read_to_end().ok().expect("read error"); print!("{}", str::from_utf8(buf.as_slice())); stream.read_to_end().ok().expect("read error"); } #[test] fn test_clone() { let stream = TcpStream::connect("127.0.0.1:15418").unwrap(); let mut stream = SslStream::new(&SslContext::new(Sslv23).unwrap(), stream).unwrap(); let mut stream2 = stream.clone(); spawn(proc() { stream2.write("GET /\r\n\r\n".as_bytes()).unwrap(); stream2.flush().unwrap(); }); stream.read_to_end().ok().expect("read error"); }