Skip to content

Commit 9076f36

Browse files
committed
If connection_timeout is zero, don't set timeout on connection
1 parent ad03031 commit 9076f36

File tree

4 files changed

+26
-10
lines changed

4 files changed

+26
-10
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Changelog
22

33
- [Changelog](#changelog)
4+
- [0.2.1](#021)
45
- [0.2.0](#020)
56
- [0.1.6](#016)
67
- [0.1.5](#015)
@@ -11,6 +12,12 @@
1112

1213
---
1314

15+
## 0.2.1
16+
17+
Released on 06/07/2023
18+
19+
- If ssh configuration timeout is `0`, don't set connection timeout
20+
1421
## 0.2.0
1522

1623
Released on 09/05/2023

Cargo.toml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ license = "MIT"
1111
name = "remotefs-ssh"
1212
readme = "README.md"
1313
repository = "https://github.com/veeso/remotefs-rs-ssh"
14-
version = "0.2.0"
14+
version = "0.2.1"
1515

1616
[dependencies]
1717
chrono = "^0.4"
@@ -30,14 +30,14 @@ serial_test = "^2.0"
3030
tempfile = "^3.5"
3131

3232
[features]
33-
default = [ "find" ]
33+
default = ["find"]
3434
# misc
35-
find = [ "remotefs/find" ]
36-
no-log = [ "log/max_level_off" ]
37-
ssh2-vendored = [ "ssh2/vendored-openssl" ]
35+
find = ["remotefs/find"]
36+
no-log = ["log/max_level_off"]
37+
ssh2-vendored = ["ssh2/vendored-openssl"]
3838
# tests
3939
github-actions = []
40-
with-containers = [ ]
40+
with-containers = []
4141

4242
[target."cfg(target_os = \"windows\")"]
4343
[target."cfg(target_os = \"windows\")".dependencies]

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<p align="center">~ Remotefs SSH client ~</p>
1212

1313
<p align="center">Developed by <a href="https://veeso.github.io/" target="_blank">@veeso</a></p>
14-
<p align="center">Current version: 0.2.0 (09/05/2023)</p>
14+
<p align="center">Current version: 0.2.1 (06/07/2023)</p>
1515

1616
<p align="center">
1717
<a href="https://opensource.org/licenses/MIT"

src/ssh/commons.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use std::io::Read;
66
use std::net::{SocketAddr, TcpStream, ToSocketAddrs};
77
use std::path::{Path, PathBuf};
88
use std::str::FromStr;
9+
use std::time::Duration;
910

1011
use remotefs::{RemoteError, RemoteErrorType, RemoteResult};
1112
use ssh2::{MethodType as SshMethodType, Session};
@@ -61,9 +62,7 @@ pub fn connect(opts: &SshOpts) -> RemoteResult<Session> {
6162
socket_addr,
6263
ssh_config.connection_timeout.as_secs()
6364
);
64-
if let Ok(tcp_stream) =
65-
TcpStream::connect_timeout(socket_addr, ssh_config.connection_timeout)
66-
{
65+
if let Ok(tcp_stream) = tcp_connect(socket_addr, ssh_config.connection_timeout) {
6766
debug!("Connection established with address {}", socket_addr);
6867
stream = Some(tcp_stream);
6968
break;
@@ -129,6 +128,16 @@ pub fn connect(opts: &SshOpts) -> RemoteResult<Session> {
129128
Ok(session)
130129
}
131130

131+
/// connect to socket address with provided timeout.
132+
/// If timeout is zero, don't set timeout
133+
fn tcp_connect(address: &SocketAddr, timeout: Duration) -> std::io::Result<TcpStream> {
134+
if timeout.is_zero() {
135+
TcpStream::connect(address)
136+
} else {
137+
TcpStream::connect_timeout(address, timeout)
138+
}
139+
}
140+
132141
/// Configure algorithm preferences into session
133142
fn set_algo_prefs(session: &mut Session, opts: &SshOpts, config: &Config) -> RemoteResult<()> {
134143
// Configure preferences from config

0 commit comments

Comments
 (0)