Skip to content

Commit 7251505

Browse files
committed
fix: remove timeout argument from connect_with_config
Move timeout from connect_with_config to Config struct.
1 parent dd36155 commit 7251505

File tree

4 files changed

+16
-22
lines changed

4 files changed

+16
-22
lines changed

CHANGELOG.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@
99
- tlua::LuaTable::metatable which is a better alternative to the existing `tlua::LuaTable::get_or_create_metatable`
1010
- `ffi::tarantool::box_schema_version` and `ffi::tarantool::box_session_id` functions
1111
- `network::protocol::SyncIndex::get` method
12-
- `network::protocol::codec::{LegacyCall, Nop, Prepare, Begin, Commit, Rollback}` variants
12+
- `network::protocol::codec::{LegacyCall, Nop, Prepare, Begin, Commit, Rollback}` variants
1313
- `network::protocol::codec::Header::encode_from_parts` function
1414
- `network::protocol::codec::iproto_key::SQL_INFO` constant
15-
- Added optional argument timeout to `network::client::Client::connect_with_config`
15+
- Added optional field `timeout` to `network::protocol::Config`.
16+
Used in `network::client::Client::connect_with_config` for
17+
restricting time for resolving address.
1618
- Untagged enum represention as in serde with `#[encode(untagged)]` attribute
1719
- `tlua::Nil` now supports (de)serialization via serde
1820

@@ -111,7 +113,7 @@
111113
- `tarantool::set_error!` macro will now use the caller's location, so if it's
112114
called from a function marked `#[track_caller]`, the log message will contain
113115
that function's call site, instead of the location of the macro call itself.
114-
- `Decimal` type is now backed by builtin tarantool decimal implementation.
116+
- `Decimal` type is now backed by builtin tarantool decimal implementation.
115117
The only expected difference is slight change in formatting (lack of
116118
scientific notation).
117119
- datetime `from_ffi_dt` and `as_ffi_dt` functions now public

tarantool/src/network/client/mod.rs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ impl Client {
183183
/// # Errors
184184
/// Error is returned if an attempt to connect failed.
185185
pub async fn connect(url: &str, port: u16) -> Result<Self, ClientError> {
186-
Self::connect_with_config(url, port, Default::default(), None).await
186+
Self::connect_with_config(url, port, Default::default()).await
187187
}
188188

189189
/// Creates a new client and tries to establish connection
@@ -199,9 +199,8 @@ impl Client {
199199
url: &str,
200200
port: u16,
201201
config: protocol::Config,
202-
timeout: Option<Duration>,
203202
) -> Result<Self, ClientError> {
204-
let timeout = timeout.unwrap_or(Duration::MAX);
203+
let timeout = config.timeout.unwrap_or(Duration::MAX);
205204
let stream = TcpStream::connect_timeout(url, port, timeout)
206205
.map_err(|e| ClientError::ConnectionClosed(Arc::new(e.into())))?;
207206
let client = ClientInner::new(config, stream.clone());
@@ -481,7 +480,6 @@ mod tests {
481480
creds: Some(("test_user".into(), "password".into())),
482481
..Default::default()
483482
},
484-
None,
485483
)
486484
.timeout(Duration::from_secs(3))
487485
.await
@@ -494,8 +492,10 @@ mod tests {
494492
let client = Client::connect_with_config(
495493
"123123", // Invalid host
496494
listen_port(),
497-
protocol::Config::default(),
498-
Some(Duration::from_secs(1)),
495+
protocol::Config {
496+
timeout: Some(Duration::from_secs(1)),
497+
..Default::default()
498+
},
499499
);
500500
let res = client.await.unwrap_err();
501501
if cfg!(target_os = "macos") {
@@ -764,7 +764,6 @@ mod tests {
764764
auth_method: AuthMethod::Md5,
765765
..Default::default()
766766
},
767-
None,
768767
)
769768
.timeout(Duration::from_secs(3))
770769
.await
@@ -788,7 +787,6 @@ mod tests {
788787
auth_method: AuthMethod::Md5,
789788
..Default::default()
790789
},
791-
None,
792790
)
793791
.timeout(Duration::from_secs(3))
794792
.await
@@ -811,7 +809,6 @@ mod tests {
811809
auth_method: AuthMethod::ChapSha1,
812810
..Default::default()
813811
},
814-
None,
815812
)
816813
.timeout(Duration::from_secs(3))
817814
.await
@@ -862,7 +859,6 @@ mod tests {
862859
auth_method: AuthMethod::Ldap,
863860
..Default::default()
864861
},
865-
None,
866862
)
867863
.timeout(Duration::from_secs(3))
868864
.await
@@ -886,7 +882,6 @@ mod tests {
886882
auth_method: AuthMethod::Ldap,
887883
..Default::default()
888884
},
889-
None,
890885
)
891886
.timeout(Duration::from_secs(3))
892887
.await
@@ -909,7 +904,6 @@ mod tests {
909904
auth_method: AuthMethod::ChapSha1,
910905
..Default::default()
911906
},
912-
None,
913907
)
914908
.timeout(Duration::from_secs(3))
915909
.await

tarantool/src/network/client/reconnect.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,9 @@ impl Client {
5252
self.reconnect_count.fetch_add(1, Ordering::Relaxed);
5353
}
5454

55-
let res = super::Client::connect_with_config(
56-
&self.url,
57-
self.port,
58-
self.protocol_config.clone(),
59-
None,
60-
)
61-
.await;
55+
let res =
56+
super::Client::connect_with_config(&self.url, self.port, self.protocol_config.clone())
57+
.await;
6258
match res {
6359
Ok(new_client) => {
6460
*client = Some(Ok(new_client.clone()));

tarantool/src/network/protocol/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use crate::error;
1616
use crate::error::TarantoolError;
1717
use std::collections::HashMap;
1818
use std::io::{Cursor, Read, Seek};
19+
use std::time::Duration;
1920

2021
#[deprecated = "use `ProtocolError` instead"]
2122
pub type Error = ProtocolError;
@@ -78,6 +79,7 @@ pub struct Config {
7879
pub creds: Option<(String, String)>,
7980
/// Authentication method. Only useful in picodata.
8081
pub auth_method: AuthMethod,
82+
pub timeout: Option<Duration>,
8183
// TODO: add buffer limits here
8284
}
8385

0 commit comments

Comments
 (0)