Merge pull request #175 from aatxe/master

Added try_clone to SslStream for SslStream<TcpStream>.
This commit is contained in:
Steven Fackler 2015-03-04 22:42:32 -05:00
commit 515872fb66
2 changed files with 13 additions and 1 deletions

View File

@ -1,4 +1,4 @@
#![feature(unsafe_destructor, core, io, std_misc, path, os, unique)] #![feature(unsafe_destructor, core, io, std_misc, net, path, os, unique)]
#![cfg_attr(test, feature(net, fs))] #![cfg_attr(test, feature(net, fs))]
#![doc(html_root_url="https://sfackler.github.io/rust-openssl/doc/openssl")] #![doc(html_root_url="https://sfackler.github.io/rust-openssl/doc/openssl")]

View File

@ -5,6 +5,7 @@ use std::io;
use std::io::prelude::*; use std::io::prelude::*;
use std::ffi::AsOsStr; use std::ffi::AsOsStr;
use std::mem; use std::mem;
use std::net;
use std::num::FromPrimitive; use std::num::FromPrimitive;
use std::num::Int; use std::num::Int;
use std::path::Path; use std::path::Path;
@ -437,6 +438,17 @@ pub struct SslStream<S> {
buf: Vec<u8> buf: Vec<u8>
} }
impl SslStream<net::TcpStream> {
/// Create a new independently owned handle to the underlying socket.
pub fn try_clone(&self) -> io::Result<SslStream<net::TcpStream>> {
Ok(SslStream {
stream: try!(self.stream.try_clone()),
ssl: self.ssl.clone(),
buf: self.buf.clone(),
})
}
}
impl<S> fmt::Debug for SslStream<S> where S: fmt::Debug { impl<S> fmt::Debug for SslStream<S> where S: fmt::Debug {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
write!(fmt, "SslStream {{ stream: {:?}, ssl: {:?} }}", self.stream, self.ssl) write!(fmt, "SslStream {{ stream: {:?}, ssl: {:?} }}", self.stream, self.ssl)