Fix more Windows compilation errors.

This commit is contained in:
Dan Gohman 2021-09-09 15:30:17 -07:00
parent 622dfcceb9
commit c986c6b4ff
4 changed files with 22 additions and 20 deletions

View file

@ -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(

View file

@ -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.

View file

@ -229,12 +229,16 @@ impl Handle {
Ok(written as usize)
}
pub fn try_clone(&self) -> io::Result<Self> {
Ok(Self(self.0.try_clone()?))
}
pub fn duplicate(
&self,
access: c::DWORD,
inherit: bool,
options: c::DWORD,
) -> io::Result<Handle> {
) -> io::Result<Self> {
Ok(Self(self.0.duplicate(access, inherit, options)?))
}
}

View file

@ -129,7 +129,7 @@ impl Socket {
unsafe {
let socket = Self::from_raw_socket(socket);
socket.set_no_inherit()?;
socket.0.set_no_inherit()?;
Ok(socket)
}
}
@ -371,19 +371,6 @@ impl Socket {
}
}
#[cfg(not(target_vendor = "uwp"))]
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")]
fn set_no_inherit(&self) -> io::Result<()> {
Err(io::Error::new_const(io::ErrorKind::Unsupported, &"Unavailable on UWP"))
}
pub fn shutdown(&self, how: Shutdown) -> io::Result<()> {
let how = match how {
Shutdown::Write => c::SD_SEND,