Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit ff339fb

Browse files
authored
Rollup merge of rust-lang#136449 - joboet:move_pal_net, r=ChrisDenton
std: move network code into `sys` As per rust-lang#117276, this PR moves `sys_common::net` and the `sys::pal::net` into the newly created `sys::net` module. In order to support rust-lang#135141, I've moved all the current network code into a separate `connection` module, future functions like `hostname` can live in separate modules. I'll probably do a follow-up PR and clean up some of the actual code, this is mostly just a reorganization.
2 parents cc58e8b + 8a3cb13 commit ff339fb

File tree

42 files changed

+114
-1037
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+114
-1037
lines changed

library/std/src/net/socket_addr.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ mod tests;
66
pub use core::net::{SocketAddr, SocketAddrV4, SocketAddrV6};
77

88
use crate::net::{IpAddr, Ipv4Addr, Ipv6Addr};
9-
use crate::sys::net::netc as c;
10-
use crate::sys_common::net::LookupHost;
9+
use crate::sys::net::{LookupHost, netc as c};
1110
use crate::sys_common::{FromInner, IntoInner};
1211
use crate::{io, iter, mem, option, slice, vec};
1312

library/std/src/net/tcp.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ use crate::io::prelude::*;
1515
use crate::io::{self, BorrowedCursor, IoSlice, IoSliceMut};
1616
use crate::iter::FusedIterator;
1717
use crate::net::{Shutdown, SocketAddr, ToSocketAddrs};
18-
use crate::sys_common::{AsInner, FromInner, IntoInner, net as net_imp};
18+
use crate::sys::net as net_imp;
19+
use crate::sys_common::{AsInner, FromInner, IntoInner};
1920
use crate::time::Duration;
2021

2122
/// A TCP stream between a local and a remote socket.

library/std/src/net/udp.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ mod tests;
1212
use crate::fmt;
1313
use crate::io::{self, ErrorKind};
1414
use crate::net::{Ipv4Addr, Ipv6Addr, SocketAddr, ToSocketAddrs};
15-
use crate::sys_common::{AsInner, FromInner, IntoInner, net as net_imp};
15+
use crate::sys::net as net_imp;
16+
use crate::sys_common::{AsInner, FromInner, IntoInner};
1617
use crate::time::Duration;
1718

1819
/// A UDP socket.

library/std/src/os/fd/net.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::os::fd::owned::OwnedFd;
22
use crate::os::fd::raw::{AsRawFd, FromRawFd, IntoRawFd, RawFd};
3-
use crate::sys_common::{self, AsInner, FromInner, IntoInner};
3+
use crate::sys_common::{AsInner, FromInner, IntoInner};
44
use crate::{net, sys};
55

66
macro_rules! impl_as_raw_fd {
@@ -24,7 +24,7 @@ macro_rules! impl_from_raw_fd {
2424
unsafe fn from_raw_fd(fd: RawFd) -> net::$t {
2525
unsafe {
2626
let socket = sys::net::Socket::from_inner(FromInner::from_inner(OwnedFd::from_raw_fd(fd)));
27-
net::$t::from_inner(sys_common::net::$t::from_inner(socket))
27+
net::$t::from_inner(sys::net::$t::from_inner(socket))
2828
}
2929
}
3030
}

library/std/src/os/hermit/io/net.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ macro_rules! impl_from_raw_fd {
2323
unsafe fn from_raw_fd(fd: RawFd) -> net::$t {
2424
unsafe {
2525
let socket = sys::net::Socket::from_inner(FromInner::from_inner(OwnedFd::from_raw_fd(fd)));
26-
net::$t::from_inner(sys_common::net::$t::from_inner(socket))
26+
net::$t::from_inner(sys::net::$t::from_inner(socket))
2727
}
2828
}
2929
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848

4949
use crate::marker::PhantomData;
5050
use crate::mem::ManuallyDrop;
51-
use crate::sys_common::{self, AsInner, FromInner, IntoInner};
51+
use crate::sys_common::{AsInner, FromInner, IntoInner};
5252
use crate::{fmt, net, sys};
5353

5454
/// Raw file descriptors.
@@ -387,7 +387,7 @@ macro_rules! impl_from_raw_fd {
387387
#[inline]
388388
unsafe fn from_raw_fd(fd: RawFd) -> net::$t {
389389
let socket = unsafe { sys::net::Socket::from_raw_fd(fd) };
390-
net::$t::from_inner(sys_common::net::$t::from_inner(socket))
390+
net::$t::from_inner(sys::net::$t::from_inner(socket))
391391
}
392392
}
393393
)*};

library/std/src/os/windows/io/raw.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use crate::os::windows::io::{AsHandle, AsSocket};
77
use crate::os::windows::io::{OwnedHandle, OwnedSocket};
88
use crate::os::windows::raw;
9-
use crate::sys_common::{self, AsInner, FromInner, IntoInner};
9+
use crate::sys_common::{AsInner, FromInner, IntoInner};
1010
use crate::{fs, io, net, ptr, sys};
1111

1212
/// Raw HANDLEs.
@@ -262,7 +262,7 @@ impl FromRawSocket for net::TcpStream {
262262
unsafe fn from_raw_socket(sock: RawSocket) -> net::TcpStream {
263263
unsafe {
264264
let sock = sys::net::Socket::from_inner(OwnedSocket::from_raw_socket(sock));
265-
net::TcpStream::from_inner(sys_common::net::TcpStream::from_inner(sock))
265+
net::TcpStream::from_inner(sys::net::TcpStream::from_inner(sock))
266266
}
267267
}
268268
}
@@ -272,7 +272,7 @@ impl FromRawSocket for net::TcpListener {
272272
unsafe fn from_raw_socket(sock: RawSocket) -> net::TcpListener {
273273
unsafe {
274274
let sock = sys::net::Socket::from_inner(OwnedSocket::from_raw_socket(sock));
275-
net::TcpListener::from_inner(sys_common::net::TcpListener::from_inner(sock))
275+
net::TcpListener::from_inner(sys::net::TcpListener::from_inner(sock))
276276
}
277277
}
278278
}
@@ -282,7 +282,7 @@ impl FromRawSocket for net::UdpSocket {
282282
unsafe fn from_raw_socket(sock: RawSocket) -> net::UdpSocket {
283283
unsafe {
284284
let sock = sys::net::Socket::from_inner(OwnedSocket::from_raw_socket(sock));
285-
net::UdpSocket::from_inner(sys_common::net::UdpSocket::from_inner(sock))
285+
net::UdpSocket::from_inner(sys::net::UdpSocket::from_inner(sock))
286286
}
287287
}
288288
}

library/std/src/sys/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ pub mod anonymous_pipe;
1212
pub mod backtrace;
1313
pub mod cmath;
1414
pub mod exit_guard;
15+
pub mod net;
1516
pub mod os_str;
1617
pub mod path;
1718
pub mod random;

library/std/src/sys/pal/sgx/net.rs renamed to library/std/src/sys/net/connection/sgx.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
use super::abi::usercalls;
21
use crate::io::{self, BorrowedCursor, IoSlice, IoSliceMut};
32
use crate::net::{Ipv4Addr, Ipv6Addr, Shutdown, SocketAddr, ToSocketAddrs};
43
use crate::sync::Arc;
4+
use crate::sys::abi::usercalls;
55
use crate::sys::fd::FileDesc;
66
use crate::sys::{AsInner, FromInner, IntoInner, TryIntoInner, sgx_ineffective, unsupported};
77
use crate::time::Duration;

library/std/src/sys_common/net.rs renamed to library/std/src/sys/net/connection/socket.rs

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,31 @@ use crate::ffi::{c_int, c_void};
55
use crate::io::{self, BorrowedCursor, ErrorKind, IoSlice, IoSliceMut};
66
use crate::net::{Ipv4Addr, Ipv6Addr, Shutdown, SocketAddr};
77
use crate::sys::common::small_c_string::run_with_cstr;
8-
use crate::sys::net::{Socket, cvt, cvt_gai, cvt_r, init, netc as c, wrlen_t};
98
use crate::sys_common::{AsInner, FromInner, IntoInner};
109
use crate::time::Duration;
1110
use crate::{cmp, fmt, mem, ptr};
1211

12+
cfg_if::cfg_if! {
13+
if #[cfg(target_os = "hermit")] {
14+
mod hermit;
15+
pub use hermit::*;
16+
} else if #[cfg(target_os = "solid_asp3")] {
17+
mod solid;
18+
pub use solid::*;
19+
} else if #[cfg(target_family = "unix")] {
20+
mod unix;
21+
pub use unix::*;
22+
} else if #[cfg(all(target_os = "wasi", target_env = "p2"))] {
23+
mod wasip2;
24+
pub use wasip2::*;
25+
} else if #[cfg(target_os = "windows")] {
26+
mod windows;
27+
pub use windows::*;
28+
}
29+
}
30+
31+
use netc as c;
32+
1333
cfg_if::cfg_if! {
1434
if #[cfg(any(
1535
target_os = "dragonfly",
@@ -24,11 +44,11 @@ cfg_if::cfg_if! {
2444
target_os = "nuttx",
2545
target_vendor = "apple",
2646
))] {
27-
use crate::sys::net::netc::IPV6_JOIN_GROUP as IPV6_ADD_MEMBERSHIP;
28-
use crate::sys::net::netc::IPV6_LEAVE_GROUP as IPV6_DROP_MEMBERSHIP;
47+
use c::IPV6_JOIN_GROUP as IPV6_ADD_MEMBERSHIP;
48+
use c::IPV6_LEAVE_GROUP as IPV6_DROP_MEMBERSHIP;
2949
} else {
30-
use crate::sys::net::netc::IPV6_ADD_MEMBERSHIP;
31-
use crate::sys::net::netc::IPV6_DROP_MEMBERSHIP;
50+
use c::IPV6_ADD_MEMBERSHIP;
51+
use c::IPV6_DROP_MEMBERSHIP;
3252
}
3353
}
3454

0 commit comments

Comments
 (0)