/// so it can be used in FFI in places where a socket is passed as an argument,
/// it is not captured or consumed, and it never has the value
/// `INVALID_SOCKET`.
+///
+/// This type's `.to_owned()` implementation returns another `BorrowedSocket`
+/// rather than an `OwnedSocket`. It just makes a trivial copy of the raw
+/// socket, which is then borrowed under the same lifetime.
#[derive(Copy, Clone)]
#[repr(transparent)]
#[rustc_layout_scalar_valid_range_start(0)]
/// `INVALID_SOCKET`.
#[inline]
#[unstable(feature = "io_safety", issue = "87074")]
- pub unsafe fn borrow_raw_socket(socket: RawSocket) -> Self {
+ pub unsafe fn borrow_raw(socket: RawSocket) -> Self {
debug_assert_ne!(socket, c::INVALID_SOCKET as RawSocket);
Self { socket, _phantom: PhantomData }
}
}
}
+ // FIXME(strict_provenance_magic): we defined RawSocket to be a u64 ;-;
#[cfg(not(target_vendor = "uwp"))]
pub(crate) fn set_no_inherit(&self) -> io::Result<()> {
cvt(unsafe {
}
impl FromRawSocket for OwnedSocket {
- /// Constructs a new instance of `Self` from the given raw socket.
- ///
- /// # Safety
- ///
- /// The resource pointed to by `socket` must be open and suitable for
- /// assuming ownership. The resource must not require cleanup other than
- /// `closesocket`.
#[inline]
unsafe fn from_raw_socket(socket: RawSocket) -> Self {
debug_assert_ne!(socket, c::INVALID_SOCKET as RawSocket);
// Safety: `OwnedSocket` and `BorrowedSocket` have the same validity
// invariants, and the `BorrowdSocket` is bounded by the lifetime
// of `&self`.
- unsafe { BorrowedSocket::borrow_raw_socket(self.as_raw_socket()) }
+ unsafe { BorrowedSocket::borrow_raw(self.as_raw_socket()) }
}
}
impl AsSocket for crate::net::TcpStream {
#[inline]
fn as_socket(&self) -> BorrowedSocket<'_> {
- unsafe { BorrowedSocket::borrow_raw_socket(self.as_raw_socket()) }
+ unsafe { BorrowedSocket::borrow_raw(self.as_raw_socket()) }
}
}
impl AsSocket for crate::net::TcpListener {
#[inline]
fn as_socket(&self) -> BorrowedSocket<'_> {
- unsafe { BorrowedSocket::borrow_raw_socket(self.as_raw_socket()) }
+ unsafe { BorrowedSocket::borrow_raw(self.as_raw_socket()) }
}
}
impl AsSocket for crate::net::UdpSocket {
#[inline]
fn as_socket(&self) -> BorrowedSocket<'_> {
- unsafe { BorrowedSocket::borrow_raw_socket(self.as_raw_socket()) }
+ unsafe { BorrowedSocket::borrow_raw(self.as_raw_socket()) }
}
}