Skip to content

Commit 6733074

Browse files
committed
Allow setting nonblock on sockets
1 parent 4a0bc71 commit 6733074

File tree

3 files changed

+16
-11
lines changed

3 files changed

+16
-11
lines changed

src/libstd/sys/redox/fd.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,16 @@ impl FileDesc {
4848
cvt(libc::write(self.fd, buf))
4949
}
5050

51+
pub fn duplicate(&self) -> io::Result<FileDesc> {
52+
let new_fd = cvt(libc::dup(self.fd, &[]))?;
53+
Ok(FileDesc::new(new_fd))
54+
}
55+
56+
pub fn nonblocking(&self) -> io::Result<bool> {
57+
let flags = cvt(libc::fcntl(self.fd, libc::F_GETFL, 0))?;
58+
Ok(flags & libc::O_NONBLOCK == libc::O_NONBLOCK)
59+
}
60+
5161
pub fn set_cloexec(&self) -> io::Result<()> {
5262
let mut flags = cvt(libc::fcntl(self.fd, libc::F_GETFL, 0))?;
5363
flags |= libc::O_CLOEXEC;
@@ -63,11 +73,6 @@ impl FileDesc {
6373
}
6474
cvt(libc::fcntl(self.fd, libc::F_SETFL, flags)).and(Ok(()))
6575
}
66-
67-
pub fn duplicate(&self) -> io::Result<FileDesc> {
68-
let new_fd = cvt(libc::dup(self.fd, &[]))?;
69-
Ok(FileDesc::new(new_fd))
70-
}
7176
}
7277

7378
impl<'a> Read for &'a FileDesc {

src/libstd/sys/redox/net/tcp.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ impl TcpStream {
5858
}
5959

6060
pub fn nonblocking(&self) -> Result<bool> {
61-
Err(Error::new(ErrorKind::Other, "TcpStream::nonblocking not implemented"))
61+
self.0.fd().nonblocking()
6262
}
6363

6464
pub fn only_v6(&self) -> Result<bool> {
@@ -81,8 +81,8 @@ impl TcpStream {
8181
Err(Error::new(ErrorKind::Other, "TcpStream::set_nodelay not implemented"))
8282
}
8383

84-
pub fn set_nonblocking(&self, _nonblocking: bool) -> Result<()> {
85-
Err(Error::new(ErrorKind::Other, "TcpStream::set_nonblocking not implemented"))
84+
pub fn set_nonblocking(&self, nonblocking: bool) -> Result<()> {
85+
self.0.fd().set_nonblocking(nonblocking)
8686
}
8787

8888
pub fn set_only_v6(&self, _only_v6: bool) -> Result<()> {

src/libstd/sys/redox/net/udp.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ impl UdpSocket {
9090
}
9191

9292
pub fn nonblocking(&self) -> Result<bool> {
93-
Err(Error::new(ErrorKind::Other, "UdpSocket::nonblocking not implemented"))
93+
self.0.fd().nonblocking()
9494
}
9595

9696
pub fn only_v6(&self) -> Result<bool> {
@@ -125,8 +125,8 @@ impl UdpSocket {
125125
Err(Error::new(ErrorKind::Other, "UdpSocket::set_multicast_ttl_v4 not implemented"))
126126
}
127127

128-
pub fn set_nonblocking(&self, _nonblocking: bool) -> Result<()> {
129-
Err(Error::new(ErrorKind::Other, "UdpSocket::set_nonblocking not implemented"))
128+
pub fn set_nonblocking(&self, nonblocking: bool) -> Result<()> {
129+
self.0.fd().set_nonblocking(nonblocking)
130130
}
131131

132132
pub fn set_only_v6(&self, _only_v6: bool) -> Result<()> {

0 commit comments

Comments
 (0)