Skip to content

Commit

Permalink
linger
Browse files Browse the repository at this point in the history
  • Loading branch information
mmastrac committed Nov 15, 2023
1 parent 69d9545 commit 0c08430
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,16 @@ impl TlsStream {
}
}

pub fn linger(&self) -> Result<Option<Duration>, io::Error> {
match &self.state {
TlsStreamState::Open(stm) => stm.tcp_stream().linger(),
TlsStreamState::Handshaking { tcp, .. } => tcp.linger(),
TlsStreamState::Closed | TlsStreamState::ClosedError(_) => {
Err(std::io::ErrorKind::NotConnected.into())
}
}
}

pub fn set_linger(&self, dur: Option<Duration>) -> Result<(), io::Error> {
match &self.state {
TlsStreamState::Open(stm) => stm.tcp_stream().set_linger(dur),
Expand Down Expand Up @@ -1838,7 +1848,9 @@ pub(super) mod tests {
};

let a = spawn(async move {
eprintln!("linger = {:?}", server.linger());
server.set_linger(Some(Duration::from_secs(60))).unwrap();
eprintln!("linger = {:?}", server.linger());
let (mut r, mut w) = server.into_split();
let barrier = Arc::new(Barrier::new(2));
let barrier2 = barrier.clone();
Expand All @@ -1858,7 +1870,7 @@ pub(super) mod tests {
w.handshake().await.unwrap();
while !buf.is_empty() {
let n = w.write(&buf).await.unwrap();
// w.flush().await.unwrap();
w.flush().await.unwrap();
buf = &mut buf[n..];
trace!("[TEST] wrote {n}");
}
Expand All @@ -1869,7 +1881,6 @@ pub(super) mod tests {

let r = a.await.unwrap();
let w = b.await.unwrap();
tokio::time::sleep(Duration::from_secs(60)).await;
drop(r.unsplit(w));
});
let b = spawn(async move {
Expand Down

0 comments on commit 0c08430

Please sign in to comment.