Skip to content

Commit fbf636d

Browse files
matt2xumattnenterprise
authored andcommitted
added get_ref() method to allow setting read/write timeout, see #52 (#58)
1 parent 606b883 commit fbf636d

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

src/data_stream.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,17 @@ impl DataStream {
3131
}
3232
}
3333

34+
impl DataStream {
35+
/// Returns a reference to the underlying TcpStream.
36+
pub fn get_ref(&self) -> &TcpStream {
37+
match self {
38+
&DataStream::Tcp(ref stream) => stream,
39+
#[cfg(feature = "secure")]
40+
&DataStream::Ssl(ref stream) => stream.get_ref(),
41+
}
42+
}
43+
}
44+
3445
impl Read for DataStream {
3546
fn read(&mut self, buf: &mut [u8]) -> Result<usize> {
3647
match self {

src/ftp.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,21 @@ impl FtpStream {
164164
})
165165
}
166166

167+
/// Returns a reference to the underlying TcpStream.
168+
///
169+
/// Example:
170+
/// ```no_run
171+
/// use std::net::TcpStream;
172+
///
173+
/// let stream = FtpStream::connect("127.0.0.1:21")
174+
/// .expect("Couldn't connect to the server...");
175+
/// stream.get_ref().set_read_timeout(Duration::from_secs(10))
176+
/// .expect("set_read_timeout call failed");
177+
/// ```
178+
pub fn get_ref(&self) -> &TcpStream {
179+
self.reader.get_ref().get_ref()
180+
}
181+
167182
/// Log in to the FTP server.
168183
pub fn login(&mut self, user: &str, password: &str) -> Result<()> {
169184
let user_command = format!("USER {}\r\n", user);

0 commit comments

Comments
 (0)