adapt L4Re network interface mock to #87329

Copy the relevant trait implementations from the Unix default.
This commit is contained in:
Benjamin Lamowski 2021-10-18 13:59:36 +02:00
parent c0dc41f5ff
commit 997dc5899a

View File

@ -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;
@ -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))
}
}