Skip to content

Commit

Permalink
Set accepted TcpStreams in non-blocking mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomasdezeeuw committed Sep 12, 2019
1 parent 6b02a62 commit 4793629
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
8 changes: 5 additions & 3 deletions src/sys/unix/tcp_listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,11 @@ impl TcpListener {
}

pub fn accept(&self) -> io::Result<(TcpStream, SocketAddr)> {
self.inner
.accept()
.map(|(inner, addr)| (TcpStream::new(inner), addr))
self.inner.accept().and_then(|(inner, addr)| {
inner
.set_nonblocking(true)
.map(|()| (TcpStream::new(inner), addr))
})
}

pub fn set_ttl(&self, ttl: u32) -> io::Result<()> {
Expand Down
18 changes: 10 additions & 8 deletions src/sys/windows/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,14 +359,16 @@ impl TcpListener {
}

pub fn accept(&self) -> io::Result<(TcpStream, SocketAddr)> {
wouldblock!(self, accept).map(|(inner, addr)| {
(
TcpStream {
internal: Arc::new(Mutex::new(None)),
inner,
},
addr,
)
wouldblock!(self, accept).and_then(|(inner, addr)| {
inner.set_nonblocking(true).map(|()| {
(
TcpStream {
internal: Arc::new(Mutex::new(None)),
inner,
},
addr,
)
})
})
}

Expand Down

0 comments on commit 4793629

Please sign in to comment.