mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-09-09 00:00:08 +02:00
net: allow to set linger on TcpSocket (#4324)
For now, this is only allowed on TcpStream. This is a problem when one want to disable lingering (i.e. set it to Duration(0, 0)). Without being able to set it prior to the connect call, if the connect future is dropped it would leave sockets in a TIME_WAIT state. Co-authored-by: Fabien Gaud <[email protected]>
This commit is contained in:
co-authored by
Fabien Gaud
parent
f64673580d
commit
22e6aef6e7
@@ -1,6 +1,7 @@
|
||||
#![warn(rust_2018_idioms)]
|
||||
#![cfg(feature = "full")]
|
||||
|
||||
use std::time::Duration;
|
||||
use tokio::net::TcpSocket;
|
||||
use tokio_test::assert_ok;
|
||||
|
||||
@@ -58,3 +59,16 @@ async fn bind_before_connect() {
|
||||
// Accept
|
||||
let _ = assert_ok!(srv.accept().await);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn basic_linger() {
|
||||
// Create server
|
||||
let addr = assert_ok!("127.0.0.1:0".parse());
|
||||
let srv = assert_ok!(TcpSocket::new_v4());
|
||||
assert_ok!(srv.bind(addr));
|
||||
|
||||
assert!(srv.linger().unwrap().is_none());
|
||||
|
||||
srv.set_linger(Some(Duration::new(0, 0))).unwrap();
|
||||
assert_eq!(srv.linger().unwrap(), Some(Duration::new(0, 0)));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user