diff options
| author | Jeremy Soller <jackpot51@gmail.com> | 2016-11-23 14:22:39 -0700 |
|---|---|---|
| committer | Jeremy Soller <jackpot51@gmail.com> | 2016-11-23 14:22:39 -0700 |
| commit | 6733074c847767fd3e0425fcefb73226bde1f6a1 (patch) | |
| tree | 1d931b8c3ec476c4191402c9bce2eaee5470b0c4 /src/libstd/sys | |
| parent | 4a0bc71bb7e32d7f63d10be13055942fb5dc6aca (diff) | |
| download | rust-6733074c847767fd3e0425fcefb73226bde1f6a1.tar.gz rust-6733074c847767fd3e0425fcefb73226bde1f6a1.zip | |
Allow setting nonblock on sockets
Diffstat (limited to 'src/libstd/sys')
| -rw-r--r-- | src/libstd/sys/redox/fd.rs | 15 | ||||
| -rw-r--r-- | src/libstd/sys/redox/net/tcp.rs | 6 | ||||
| -rw-r--r-- | src/libstd/sys/redox/net/udp.rs | 6 |
3 files changed, 16 insertions, 11 deletions
diff --git a/src/libstd/sys/redox/fd.rs b/src/libstd/sys/redox/fd.rs index 47d2280fe05..b716965860e 100644 --- a/src/libstd/sys/redox/fd.rs +++ b/src/libstd/sys/redox/fd.rs @@ -48,6 +48,16 @@ impl FileDesc { cvt(libc::write(self.fd, buf)) } + pub fn duplicate(&self) -> io::Result<FileDesc> { + let new_fd = cvt(libc::dup(self.fd, &[]))?; + Ok(FileDesc::new(new_fd)) + } + + pub fn nonblocking(&self) -> io::Result<bool> { + let flags = cvt(libc::fcntl(self.fd, libc::F_GETFL, 0))?; + Ok(flags & libc::O_NONBLOCK == libc::O_NONBLOCK) + } + pub fn set_cloexec(&self) -> io::Result<()> { let mut flags = cvt(libc::fcntl(self.fd, libc::F_GETFL, 0))?; flags |= libc::O_CLOEXEC; @@ -63,11 +73,6 @@ impl FileDesc { } cvt(libc::fcntl(self.fd, libc::F_SETFL, flags)).and(Ok(())) } - - pub fn duplicate(&self) -> io::Result<FileDesc> { - let new_fd = cvt(libc::dup(self.fd, &[]))?; - Ok(FileDesc::new(new_fd)) - } } impl<'a> Read for &'a FileDesc { diff --git a/src/libstd/sys/redox/net/tcp.rs b/src/libstd/sys/redox/net/tcp.rs index 351c534c036..ceaa5df267f 100644 --- a/src/libstd/sys/redox/net/tcp.rs +++ b/src/libstd/sys/redox/net/tcp.rs @@ -58,7 +58,7 @@ impl TcpStream { } pub fn nonblocking(&self) -> Result<bool> { - Err(Error::new(ErrorKind::Other, "TcpStream::nonblocking not implemented")) + self.0.fd().nonblocking() } pub fn only_v6(&self) -> Result<bool> { @@ -81,8 +81,8 @@ impl TcpStream { Err(Error::new(ErrorKind::Other, "TcpStream::set_nodelay not implemented")) } - pub fn set_nonblocking(&self, _nonblocking: bool) -> Result<()> { - Err(Error::new(ErrorKind::Other, "TcpStream::set_nonblocking not implemented")) + pub fn set_nonblocking(&self, nonblocking: bool) -> Result<()> { + self.0.fd().set_nonblocking(nonblocking) } pub fn set_only_v6(&self, _only_v6: bool) -> Result<()> { diff --git a/src/libstd/sys/redox/net/udp.rs b/src/libstd/sys/redox/net/udp.rs index a259db6a4c0..7856de033eb 100644 --- a/src/libstd/sys/redox/net/udp.rs +++ b/src/libstd/sys/redox/net/udp.rs @@ -90,7 +90,7 @@ impl UdpSocket { } pub fn nonblocking(&self) -> Result<bool> { - Err(Error::new(ErrorKind::Other, "UdpSocket::nonblocking not implemented")) + self.0.fd().nonblocking() } pub fn only_v6(&self) -> Result<bool> { @@ -125,8 +125,8 @@ impl UdpSocket { Err(Error::new(ErrorKind::Other, "UdpSocket::set_multicast_ttl_v4 not implemented")) } - pub fn set_nonblocking(&self, _nonblocking: bool) -> Result<()> { - Err(Error::new(ErrorKind::Other, "UdpSocket::set_nonblocking not implemented")) + pub fn set_nonblocking(&self, nonblocking: bool) -> Result<()> { + self.0.fd().set_nonblocking(nonblocking) } pub fn set_only_v6(&self, _only_v6: bool) -> Result<()> { |
