Skip to content

Commit

Permalink
adapt L4Re network interface mock to rust-lang#87329
Browse files Browse the repository at this point in the history
Copy the relevant trait implementations from the Unix default.
  • Loading branch information
atopia committed Mar 9, 2022
1 parent c0dc41f commit 997dc58
Showing 1 changed file with 34 additions and 9 deletions.
43 changes: 34 additions & 9 deletions library/std/src/sys/unix/l4re.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub mod net {
use crate::fmt;
use crate::io::{self, IoSlice, IoSliceMut};
use crate::net::{Ipv4Addr, Ipv6Addr, Shutdown, SocketAddr};
use crate::os::unix::io::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, RawFd};
use crate::sys::fd::FileDesc;
use crate::sys_common::{AsInner, FromInner, IntoInner};
use crate::time::Duration;
Expand Down Expand Up @@ -123,21 +124,45 @@ pub mod net {
}
}

impl AsInner<libc::c_int> for Socket {
fn as_inner(&self) -> &libc::c_int {
self.0.as_inner()
impl AsInner<FileDesc> for Socket {
fn as_inner(&self) -> &FileDesc {
&self.0
}
}

impl FromInner<libc::c_int> for Socket {
fn from_inner(fd: libc::c_int) -> Socket {
Socket(FileDesc::new(fd))
impl FromInner<FileDesc> for Socket {
fn from_inner(file_desc: FileDesc) -> Socket {
Socket(file_desc)
}
}

impl IntoInner<libc::c_int> for Socket {
fn into_inner(self) -> libc::c_int {
self.0.into_raw()
impl IntoInner<FileDesc> for Socket {
fn into_inner(self) -> FileDesc {
self.0
}
}

impl AsFd for Socket {
fn as_fd(&self) -> BorrowedFd<'_> {
self.0.as_fd()
}
}

impl AsRawFd for Socket {
fn as_raw_fd(&self) -> RawFd {
self.0.as_raw_fd()
}
}

impl IntoRawFd for Socket {
fn into_raw_fd(self) -> RawFd {
self.0.into_raw_fd()
}
}

impl FromRawFd for Socket {
unsafe fn from_raw_fd(raw_fd: RawFd) -> Self {
Self(FromRawFd::from_raw_fd(raw_fd))
}
}

Expand Down

0 comments on commit 997dc58

Please sign in to comment.