about summary refs log tree commit diff
path: root/library/std/src/os
diff options
context:
space:
mode:
authorDan Gohman <dev@sunfishcode.online>2021-09-09 15:30:17 -0700
committerDan Gohman <dev@sunfishcode.online>2021-09-09 15:30:17 -0700
commitc986c6b4ffec634d3c0ecbc3867a818bc41a59be (patch)
tree619be4968ff0c47757fd72a4b333249254ccdb72 /library/std/src/os
parent622dfcceb9328b359e28adaec8192390e494ca1e (diff)
downloadrust-c986c6b4ffec634d3c0ecbc3867a818bc41a59be.tar.gz
rust-c986c6b4ffec634d3c0ecbc3867a818bc41a59be.zip
Fix more Windows compilation errors.
Diffstat (limited to 'library/std/src/os')
-rw-r--r--library/std/src/os/windows/io/handle.rs4
-rw-r--r--library/std/src/os/windows/io/socket.rs17
2 files changed, 16 insertions, 5 deletions
diff --git a/library/std/src/os/windows/io/handle.rs b/library/std/src/os/windows/io/handle.rs
index 92c5f49e58a..9522a05495c 100644
--- a/library/std/src/os/windows/io/handle.rs
+++ b/library/std/src/os/windows/io/handle.rs
@@ -116,9 +116,7 @@ impl OwnedHandle {
     /// Creates a new `OwnedHandle` instance that shares the same underlying file handle
     /// as the existing `OwnedHandle` instance.
     pub fn try_clone(&self) -> crate::io::Result<Self> {
-        let handle = self.duplicate(0, false, c::DUPLICATE_SAME_ACCESS)?;
-
-        Ok(unsafe { OwnedHandle::from_raw_handle(handle) })
+        self.duplicate(0, false, c::DUPLICATE_SAME_ACCESS)
     }
 
     pub(crate) fn duplicate(
diff --git a/library/std/src/os/windows/io/socket.rs b/library/std/src/os/windows/io/socket.rs
index 0d776434047..7acd0af88b3 100644
--- a/library/std/src/os/windows/io/socket.rs
+++ b/library/std/src/os/windows/io/socket.rs
@@ -93,7 +93,7 @@ impl OwnedSocket {
         };
 
         if socket != c::INVALID_SOCKET {
-            unsafe { Ok(Self(OwnedSocket::from_raw_socket(socket))) }
+            unsafe { Ok(OwnedSocket::from_raw_socket(socket)) }
         } else {
             let error = unsafe { c::WSAGetLastError() };
 
@@ -117,12 +117,25 @@ impl OwnedSocket {
             }
 
             unsafe {
-                let socket = Self(OwnedSocket::from_raw_socket(socket));
+                let socket = OwnedSocket::from_raw_socket(socket);
                 socket.set_no_inherit()?;
                 Ok(socket)
             }
         }
     }
+
+    #[cfg(not(target_vendor = "uwp"))]
+    pub(crate) fn set_no_inherit(&self) -> io::Result<()> {
+        sys::cvt(unsafe {
+            c::SetHandleInformation(self.as_raw_socket() as c::HANDLE, c::HANDLE_FLAG_INHERIT, 0)
+        })
+        .map(drop)
+    }
+
+    #[cfg(target_vendor = "uwp")]
+    pub(crate) fn set_no_inherit(&self) -> io::Result<()> {
+        Err(io::Error::new_const(io::ErrorKind::Unsupported, &"Unavailable on UWP"))
+    }
 }
 
 /// Returns the last error from the Windows socket interface.