Skip to content

Commit 5e3519f

Browse files
authored
feat(tcp): expose socket2 set_linger
to allow for faster connection close time, see more on https://docs.rs/socket2/latest/socket2/struct.Socket.html#method.set_linger Pull-Request: libp2p#6225.
1 parent e10ce4c commit 5e3519f

File tree

5 files changed

+22
-3
lines changed

5 files changed

+22
-3
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ libp2p-stream = { version = "0.4.0-alpha", path = "protocols/stream" }
105105
libp2p-swarm = { version = "0.47.0", path = "swarm" }
106106
libp2p-swarm-derive = { version = "=0.35.1", path = "swarm-derive" } # `libp2p-swarm-derive` may not be compatible with different `libp2p-swarm` non-breaking releases. E.g. `libp2p-swarm` might introduce a new enum variant `FromSwarm` (which is `#[non-exhaustive]`) in a non-breaking release. Older versions of `libp2p-swarm-derive` would not forward this enum variant within the `NetworkBehaviour` hierarchy. Thus the version pinning is required.
107107
libp2p-swarm-test = { version = "0.6.0", path = "swarm-test" }
108-
libp2p-tcp = { version = "0.44.0", path = "transports/tcp" }
108+
libp2p-tcp = { version = "0.44.1", path = "transports/tcp" }
109109
libp2p-tls = { version = "0.6.2", path = "transports/tls" }
110110
libp2p-uds = { version = "0.43.1", path = "transports/uds" }
111111
libp2p-upnp = { version = "0.6.0", path = "protocols/upnp" }

transports/tcp/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.44.1
2+
- Expose `socket2`'s `set_linger` config option.
3+
See [PR 6225](https://github.com/libp2p/rust-libp2p/pull/5955)
4+
15
## 0.44.0
26

37
- Remove `async-std` support.

transports/tcp/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name = "libp2p-tcp"
33
edition.workspace = true
44
rust-version = { workspace = true }
55
description = "TCP/IP transport protocol for libp2p"
6-
version = "0.44.0"
6+
version = "0.44.1"
77
authors = ["Parity Technologies <admin@parity.io>"]
88
license = "MIT"
99
repository = "https://github.com/libp2p/rust-libp2p"

transports/tcp/src/lib.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ pub struct Config {
5959
ttl: Option<u32>,
6060
/// `TCP_NODELAY` to set for opened sockets.
6161
nodelay: bool,
62+
/// `SO_LINGER` to set for opened sockets,
63+
/// by default is `None`.
64+
linger: Option<Duration>,
6265
/// Size of the listen backlog for listen sockets.
6366
backlog: u32,
6467
}
@@ -137,6 +140,7 @@ impl Config {
137140
Self {
138141
ttl: None,
139142
nodelay: true, // Disable Nagle's algorithm by default.
143+
linger: None,
140144
backlog: 1024,
141145
}
142146
}
@@ -159,6 +163,12 @@ impl Config {
159163
self
160164
}
161165

166+
/// Configures the `SO_LINGER` option for new sockets.
167+
pub fn linger(mut self, duration: Option<Duration>) -> Self {
168+
self.linger = duration;
169+
self
170+
}
171+
162172
/// Configures port reuse for local sockets, which implies
163173
/// reuse of listening ports for outgoing connections to
164174
/// enhance NAT traversal capabilities.
@@ -196,6 +206,11 @@ impl Config {
196206
if let Some(ttl) = self.ttl {
197207
socket.set_ttl_v4(ttl)?;
198208
}
209+
210+
if self.linger.is_some() {
211+
socket.set_linger(self.linger)?;
212+
}
213+
199214
socket.set_tcp_nodelay(self.nodelay)?;
200215
socket.set_reuse_address(true)?;
201216
#[cfg(all(unix, not(any(target_os = "solaris", target_os = "illumos"))))]

0 commit comments

Comments
 (0)