Skip to content

Commit c986c6b

Browse files
committed
Fix more Windows compilation errors.
1 parent 622dfcc commit c986c6b

File tree

4 files changed

+22
-20
lines changed

4 files changed

+22
-20
lines changed

library/std/src/os/windows/io/handle.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,7 @@ impl OwnedHandle {
116116
/// Creates a new `OwnedHandle` instance that shares the same underlying file handle
117117
/// as the existing `OwnedHandle` instance.
118118
pub fn try_clone(&self) -> crate::io::Result<Self> {
119-
let handle = self.duplicate(0, false, c::DUPLICATE_SAME_ACCESS)?;
120-
121-
Ok(unsafe { OwnedHandle::from_raw_handle(handle) })
119+
self.duplicate(0, false, c::DUPLICATE_SAME_ACCESS)
122120
}
123121

124122
pub(crate) fn duplicate(

library/std/src/os/windows/io/socket.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ impl OwnedSocket {
9393
};
9494

9595
if socket != c::INVALID_SOCKET {
96-
unsafe { Ok(Self(OwnedSocket::from_raw_socket(socket))) }
96+
unsafe { Ok(OwnedSocket::from_raw_socket(socket)) }
9797
} else {
9898
let error = unsafe { c::WSAGetLastError() };
9999

@@ -117,12 +117,25 @@ impl OwnedSocket {
117117
}
118118

119119
unsafe {
120-
let socket = Self(OwnedSocket::from_raw_socket(socket));
120+
let socket = OwnedSocket::from_raw_socket(socket);
121121
socket.set_no_inherit()?;
122122
Ok(socket)
123123
}
124124
}
125125
}
126+
127+
#[cfg(not(target_vendor = "uwp"))]
128+
pub(crate) fn set_no_inherit(&self) -> io::Result<()> {
129+
sys::cvt(unsafe {
130+
c::SetHandleInformation(self.as_raw_socket() as c::HANDLE, c::HANDLE_FLAG_INHERIT, 0)
131+
})
132+
.map(drop)
133+
}
134+
135+
#[cfg(target_vendor = "uwp")]
136+
pub(crate) fn set_no_inherit(&self) -> io::Result<()> {
137+
Err(io::Error::new_const(io::ErrorKind::Unsupported, &"Unavailable on UWP"))
138+
}
126139
}
127140

128141
/// Returns the last error from the Windows socket interface.

library/std/src/sys/windows/handle.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,12 +229,16 @@ impl Handle {
229229
Ok(written as usize)
230230
}
231231

232+
pub fn try_clone(&self) -> io::Result<Self> {
233+
Ok(Self(self.0.try_clone()?))
234+
}
235+
232236
pub fn duplicate(
233237
&self,
234238
access: c::DWORD,
235239
inherit: bool,
236240
options: c::DWORD,
237-
) -> io::Result<Handle> {
241+
) -> io::Result<Self> {
238242
Ok(Self(self.0.duplicate(access, inherit, options)?))
239243
}
240244
}

library/std/src/sys/windows/net.rs

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ impl Socket {
129129

130130
unsafe {
131131
let socket = Self::from_raw_socket(socket);
132-
socket.set_no_inherit()?;
132+
socket.0.set_no_inherit()?;
133133
Ok(socket)
134134
}
135135
}
@@ -371,19 +371,6 @@ impl Socket {
371371
}
372372
}
373373

374-
#[cfg(not(target_vendor = "uwp"))]
375-
fn set_no_inherit(&self) -> io::Result<()> {
376-
sys::cvt(unsafe {
377-
c::SetHandleInformation(self.as_raw_socket() as c::HANDLE, c::HANDLE_FLAG_INHERIT, 0)
378-
})
379-
.map(drop)
380-
}
381-
382-
#[cfg(target_vendor = "uwp")]
383-
fn set_no_inherit(&self) -> io::Result<()> {
384-
Err(io::Error::new_const(io::ErrorKind::Unsupported, &"Unavailable on UWP"))
385-
}
386-
387374
pub fn shutdown(&self, how: Shutdown) -> io::Result<()> {
388375
let how = match how {
389376
Shutdown::Write => c::SD_SEND,

0 commit comments

Comments
 (0)