Skip to content

Commit 22ee83f

Browse files
authored
fix(net): set reuseaddr in TcpListener::bind (#379)
1 parent 0704ae0 commit 22ee83f

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

compio-net/src/socket.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use crate::PollFd;
2323

2424
#[derive(Debug, Clone)]
2525
pub struct Socket {
26-
socket: Attacher<Socket2>,
26+
pub(crate) socket: Attacher<Socket2>,
2727
}
2828

2929
impl Socket {

compio-net/src/tcp.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,10 @@ impl TcpListener {
5656
/// to this listener.
5757
pub async fn bind(addr: impl ToSocketAddrsAsync) -> io::Result<Self> {
5858
super::each_addr(addr, |addr| async move {
59-
let socket =
60-
Socket::bind(&SockAddr::from(addr), Type::STREAM, Some(Protocol::TCP)).await?;
59+
let sa = SockAddr::from(addr);
60+
let socket = Socket::new(sa.domain(), Type::STREAM, Some(Protocol::TCP)).await?;
61+
socket.socket.set_reuse_address(true)?;
62+
socket.socket.bind(&sa)?;
6163
socket.listen(128)?;
6264
Ok(Self { inner: socket })
6365
})

0 commit comments

Comments
 (0)