Skip to content

Commit b04a5c5

Browse files
committed
kmc-solid: Replace {From,Into}Inner<c_int> impls with *RawFd for Socket
Follows how other targets are implemented.
1 parent 94237c4 commit b04a5c5

File tree

2 files changed

+16
-20
lines changed

2 files changed

+16
-20
lines changed

library/std/src/os/solid/io.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ macro_rules! impl_as_raw_fd {
372372
impl AsRawFd for net::$t {
373373
#[inline]
374374
fn as_raw_fd(&self) -> RawFd {
375-
*self.as_inner().socket().as_inner()
375+
self.as_inner().socket().as_raw_fd()
376376
}
377377
}
378378
)*};
@@ -385,7 +385,7 @@ macro_rules! impl_from_raw_fd {
385385
impl FromRawFd for net::$t {
386386
#[inline]
387387
unsafe fn from_raw_fd(fd: RawFd) -> net::$t {
388-
let socket = sys::net::Socket::from_inner(fd);
388+
let socket = unsafe { sys::net::Socket::from_raw_fd(fd) };
389389
net::$t::from_inner(sys_common::net::$t::from_inner(socket))
390390
}
391391
}
@@ -399,7 +399,7 @@ macro_rules! impl_into_raw_fd {
399399
impl IntoRawFd for net::$t {
400400
#[inline]
401401
fn into_raw_fd(self) -> RawFd {
402-
self.into_inner().into_socket().into_inner()
402+
self.into_inner().into_socket().into_raw_fd()
403403
}
404404
}
405405
)*};

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

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ use crate::{
55
io::{self, BorrowedBuf, BorrowedCursor, ErrorKind, IoSlice, IoSliceMut},
66
mem,
77
net::{Shutdown, SocketAddr},
8+
os::solid::io::{AsRawFd, FromRawFd, IntoRawFd},
89
ptr, str,
910
sys_common::net::{getsockopt, setsockopt, sockaddr_to_addr},
10-
sys_common::{AsInner, FromInner, IntoInner},
11+
sys_common::IntoInner,
1112
time::Duration,
1213
};
1314

@@ -111,13 +112,6 @@ impl FileDesc {
111112
}
112113
}
113114

114-
impl AsInner<c_int> for FileDesc {
115-
#[inline]
116-
fn as_inner(&self) -> &c_int {
117-
&self.fd
118-
}
119-
}
120-
121115
impl Drop for FileDesc {
122116
fn drop(&mut self) {
123117
unsafe { netc::close(self.fd) };
@@ -446,7 +440,7 @@ impl Socket {
446440
pub fn set_nonblocking(&self, nonblocking: bool) -> io::Result<()> {
447441
let mut nonblocking = nonblocking as c_int;
448442
cvt(unsafe {
449-
netc::ioctl(*self.as_inner(), netc::FIONBIO, (&mut nonblocking) as *mut c_int as _)
443+
netc::ioctl(self.0.raw(), netc::FIONBIO, (&mut nonblocking) as *mut c_int as _)
450444
})
451445
.map(drop)
452446
}
@@ -458,25 +452,27 @@ impl Socket {
458452

459453
// This method is used by sys_common code to abstract over targets.
460454
pub fn as_raw(&self) -> c_int {
461-
*self.as_inner()
455+
self.0.raw()
462456
}
463457
}
464458

465-
impl AsInner<c_int> for Socket {
459+
impl AsRawFd for Socket {
466460
#[inline]
467-
fn as_inner(&self) -> &c_int {
468-
self.0.as_inner()
461+
fn as_raw_fd(&self) -> c_int {
462+
self.0.fd
469463
}
470464
}
471465

472-
impl FromInner<c_int> for Socket {
473-
fn from_inner(fd: c_int) -> Socket {
466+
impl FromRawFd for Socket {
467+
#[inline]
468+
unsafe fn from_raw_fd(fd: c_int) -> Socket {
474469
Socket(FileDesc::new(fd))
475470
}
476471
}
477472

478-
impl IntoInner<c_int> for Socket {
479-
fn into_inner(self) -> c_int {
473+
impl IntoRawFd for Socket {
474+
#[inline]
475+
fn into_raw_fd(self) -> c_int {
480476
self.0.into_raw()
481477
}
482478
}

0 commit comments

Comments
 (0)