Skip to content

Commit

Permalink
If connection_timeout is zero, don't set timeout on connection
Browse files Browse the repository at this point in the history
  • Loading branch information
veeso committed Jul 6, 2023
1 parent ad03031 commit 9076f36
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 10 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Changelog

- [Changelog](#changelog)
- [0.2.1](#021)
- [0.2.0](#020)
- [0.1.6](#016)
- [0.1.5](#015)
Expand All @@ -11,6 +12,12 @@

---

## 0.2.1

Released on 06/07/2023

- If ssh configuration timeout is `0`, don't set connection timeout

## 0.2.0

Released on 09/05/2023
Expand Down
12 changes: 6 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ license = "MIT"
name = "remotefs-ssh"
readme = "README.md"
repository = "https://github.com/veeso/remotefs-rs-ssh"
version = "0.2.0"
version = "0.2.1"

[dependencies]
chrono = "^0.4"
Expand All @@ -30,14 +30,14 @@ serial_test = "^2.0"
tempfile = "^3.5"

[features]
default = [ "find" ]
default = ["find"]
# misc
find = [ "remotefs/find" ]
no-log = [ "log/max_level_off" ]
ssh2-vendored = [ "ssh2/vendored-openssl" ]
find = ["remotefs/find"]
no-log = ["log/max_level_off"]
ssh2-vendored = ["ssh2/vendored-openssl"]
# tests
github-actions = []
with-containers = [ ]
with-containers = []

[target."cfg(target_os = \"windows\")"]
[target."cfg(target_os = \"windows\")".dependencies]
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<p align="center">~ Remotefs SSH client ~</p>

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

<p align="center">
<a href="https://opensource.org/licenses/MIT"
Expand Down
15 changes: 12 additions & 3 deletions src/ssh/commons.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use std::io::Read;
use std::net::{SocketAddr, TcpStream, ToSocketAddrs};
use std::path::{Path, PathBuf};
use std::str::FromStr;
use std::time::Duration;

use remotefs::{RemoteError, RemoteErrorType, RemoteResult};
use ssh2::{MethodType as SshMethodType, Session};
Expand Down Expand Up @@ -61,9 +62,7 @@ pub fn connect(opts: &SshOpts) -> RemoteResult<Session> {
socket_addr,
ssh_config.connection_timeout.as_secs()
);
if let Ok(tcp_stream) =
TcpStream::connect_timeout(socket_addr, ssh_config.connection_timeout)
{
if let Ok(tcp_stream) = tcp_connect(socket_addr, ssh_config.connection_timeout) {
debug!("Connection established with address {}", socket_addr);
stream = Some(tcp_stream);
break;
Expand Down Expand Up @@ -129,6 +128,16 @@ pub fn connect(opts: &SshOpts) -> RemoteResult<Session> {
Ok(session)
}

/// connect to socket address with provided timeout.
/// If timeout is zero, don't set timeout
fn tcp_connect(address: &SocketAddr, timeout: Duration) -> std::io::Result<TcpStream> {
if timeout.is_zero() {
TcpStream::connect(address)
} else {
TcpStream::connect_timeout(address, timeout)
}
}

/// Configure algorithm preferences into session
fn set_algo_prefs(session: &mut Session, opts: &SshOpts, config: &Config) -> RemoteResult<()> {
// Configure preferences from config
Expand Down

0 comments on commit 9076f36

Please sign in to comment.