Skip to content

Commit

Permalink
clippy & removed some assumptions
Browse files Browse the repository at this point in the history
  • Loading branch information
pompon0 committed Sep 23, 2024
1 parent a219e82 commit 88015be
Showing 1 changed file with 12 additions and 17 deletions.
29 changes: 12 additions & 17 deletions node/libs/concurrency/src/net/tcp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,23 @@ pub type Listener = tokio::net::TcpListener;

/// Accepts an INBOUND listener connection.
pub async fn accept(ctx: &ctx::Ctx, this: &mut Listener) -> ctx::OrCanceled<io::Result<Stream>> {
Ok(ctx.wait(this.accept()).await?.map(|(stream, _)| {
// We are the only owner of the correctly opened
// socket at this point so `set_nodelay` should
// always succeed.
stream.set_nodelay(true).unwrap();
stream
}))
ctx.wait(async {
let stream = this.accept().await?.0;
stream.set_nodelay(true)?;
Ok(stream)
})
.await
}

/// Opens a TCP connection to a remote host.
pub async fn connect(
ctx: &ctx::Ctx,
addr: std::net::SocketAddr,
) -> ctx::OrCanceled<io::Result<Stream>> {
Ok(ctx
.wait(tokio::net::TcpStream::connect(addr))
.await?
.map(|stream| {
// We are the only owner of the correctly opened
// socket at this point so `set_nodelay` should
// always succeed.
stream.set_nodelay(true).unwrap();
stream
}))
ctx.wait(async {
let stream = tokio::net::TcpStream::connect(addr).await?;
stream.set_nodelay(true)?;
Ok(stream)
})
.await
}

0 comments on commit 88015be

Please sign in to comment.