Skip to content

Commit a301ba5

Browse files
committed
Deprecate the tcp, udp and uds features
In favour of a new `net` feature that enables all networking primitives.
1 parent 25731e8 commit a301ba5

File tree

10 files changed

+39
-164
lines changed

10 files changed

+39
-164
lines changed

Cargo.toml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,22 @@ include = [
2525
"examples/**/*.rs",
2626
]
2727

28+
# For documentation of features see the `mio::features` module.
2829
[features]
30+
# By default Mio only provides a shell implementation.
2931
default = []
32+
3033
os-poll = []
3134
os-util = []
3235
pipe = ["os-poll"]
33-
tcp = []
34-
udp = []
35-
uds = []
36+
# Enables `mio::net` module containing networking primitives.
37+
net = []
3638

3739
# Deprecated features, will be removed in a future version.
3840
extra-docs = [] # Docs are now always present.
41+
tcp = ["net"] # Replaced with "net" feature.
42+
udp = ["net"] # Replaced with "net" feature.
43+
uds = ["net"] # Replaced with "net" feature.
3944

4045
[dependencies]
4146
log = "0.4.8"

src/lib.rs

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -127,21 +127,10 @@ pub mod features {
127127
//! The `pipe` feature adds `unix::pipe`, and related types, a non-blocking
128128
//! wrapper around the `pipe(2)` system call.
129129
//!
130-
//! ## Network types
130+
#![cfg_attr(feature = "net", doc = "## Network types (enabled)")]
131+
#![cfg_attr(not(feature = "net"), doc = "## Network types (disabled)")]
131132
//!
132-
//! Mio provide three features to enable network types:
133-
//!
134-
#![cfg_attr(feature = "tcp", doc = "* `tcp` (enabled)")]
135-
#![cfg_attr(not(feature = "tcp"), doc = "* `tcp` (disabled)")]
136-
//! : includes `TcpStream` and `TcpListener`,
137-
#![cfg_attr(feature = "udp", doc = "* `udp` (enabled)")]
138-
#![cfg_attr(not(feature = "udp"), doc = "* `udp` (disabled)")]
139-
//! : includes `UdpSocket`, and
140-
#![cfg_attr(feature = "uds", doc = "* `uds` (enabled)")]
141-
#![cfg_attr(not(feature = "uds"), doc = "* `uds` (disabled)")]
142-
//! : includes `UnixDatagram`, `UnixListener`, `UnixStream` and `SocketAddr`.
143-
//!
144-
//! All types can be found in the `net` module.
133+
//! The `net` feature enables networking primitives in the `net` module.
145134
}
146135

147136
pub mod guide {

src/macros/mod.rs

Lines changed: 9 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -24,71 +24,24 @@ macro_rules! cfg_not_os_poll {
2424
}
2525
}
2626

27-
/// One of the `tcp`, `udp`, `uds` features enabled.
28-
#[cfg(unix)]
27+
/// The `net` feature is enabled.
2928
macro_rules! cfg_net {
3029
($($item:item)*) => {
3130
$(
32-
#[cfg(any(feature = "tcp", feature = "udp", feature = "uds"))]
33-
#[cfg_attr(docsrs, doc(cfg(any(feature = "tcp", feature = "udp", feature = "uds"))))]
31+
#[cfg(feature = "net")]
32+
#[cfg_attr(docsrs, doc(cfg(feature = "net")))]
3433
$item
3534
)*
3635
}
3736
}
3837

39-
/// One of the features enabled that needs `IoSource`. That is `tcp`, or `udp`,
40-
/// or on Unix `uds` or `pipe`.
38+
/// One of the features enabled that needs `IoSource`. That is `net` or `pipe`
39+
/// (on Unix).
4140
macro_rules! cfg_io_source {
4241
($($item:item)*) => {
4342
$(
44-
#[cfg(any(feature = "tcp", feature = "udp", all(unix, any(feature = "uds", feature = "pipe"))))]
45-
#[cfg_attr(docsrs, doc(any(feature = "tcp", feature = "udp", all(unix, any(feature = "uds", feature = "pipe")))))]
46-
$item
47-
)*
48-
}
49-
}
50-
51-
/// One of the `tcp`, `udp` features enabled.
52-
#[cfg(windows)]
53-
macro_rules! cfg_net {
54-
($($item:item)*) => {
55-
$(
56-
#[cfg(any(feature = "tcp", feature = "udp"))]
57-
#[cfg_attr(docsrs, doc(cfg(any(feature = "tcp", feature = "udp"))))]
58-
$item
59-
)*
60-
}
61-
}
62-
63-
/// Feature `tcp` enabled.
64-
macro_rules! cfg_tcp {
65-
($($item:item)*) => {
66-
$(
67-
#[cfg(feature = "tcp")]
68-
#[cfg_attr(docsrs, doc(cfg(feature = "tcp")))]
69-
$item
70-
)*
71-
}
72-
}
73-
74-
/// Feature `udp` enabled.
75-
macro_rules! cfg_udp {
76-
($($item:item)*) => {
77-
$(
78-
#[cfg(feature = "udp")]
79-
#[cfg_attr(docsrs, doc(cfg(feature = "udp")))]
80-
$item
81-
)*
82-
}
83-
}
84-
85-
/// Feature `uds` enabled.
86-
#[cfg(unix)]
87-
macro_rules! cfg_uds {
88-
($($item:item)*) => {
89-
$(
90-
#[cfg(feature = "uds")]
91-
#[cfg_attr(docsrs, doc(cfg(feature = "uds")))]
43+
#[cfg(any(feature = "net", all(unix, feature = "pipe")))]
44+
#[cfg_attr(docsrs, doc(any(feature = "net", all(unix, feature = "pipe"))))]
9245
$item
9346
)*
9447
}
@@ -107,24 +60,11 @@ macro_rules! cfg_pipe {
10760
}
10861

10962
/// Feature `os-util` enabled, or one of the features that need `os-util`.
110-
#[cfg(unix)]
111-
macro_rules! cfg_any_os_util {
112-
($($item:item)*) => {
113-
$(
114-
#[cfg(any(feature = "os-util", feature = "tcp", feature = "udp", feature = "uds", feature = "pipe"))]
115-
#[cfg_attr(docsrs, doc(cfg(any(feature = "os-util", feature = "tcp", feature = "udp", feature = "uds", feature = "pipe"))))]
116-
$item
117-
)*
118-
}
119-
}
120-
121-
/// Feature `os-util` enabled, or one of the features that need `os-util`.
122-
#[cfg(windows)]
12363
macro_rules! cfg_any_os_util {
12464
($($item:item)*) => {
12565
$(
126-
#[cfg(any(feature = "os-util", feature = "tcp", feature = "udp", feature = "pipe"))]
127-
#[cfg_attr(docsrs, doc(cfg(any(feature = "os-util", feature = "tcp", feature = "udp", feature = "pipe"))))]
66+
#[cfg(any(feature = "os-util", feature = "net", all(unix, feature = "pipe")))]
67+
#[cfg_attr(docsrs, doc(cfg(any(feature = "os-util", feature = "net", all(unix, feature = "pipe")))))]
12868
$item
12969
)*
13070
}

src/net/mod.rs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! Networking primitives
1+
//! Networking primitives.
22
//!
33
//! The types provided in this module are non-blocking by default and are
44
//! designed to be portable across all supported Mio platforms. As long as the
@@ -7,18 +7,13 @@
77
//!
88
//! [portability guidelines]: ../struct.Poll.html#portability
99
10-
cfg_tcp! {
11-
mod tcp;
12-
pub use self::tcp::{TcpListener, TcpSocket, TcpStream};
13-
}
10+
mod tcp;
11+
pub use self::tcp::{TcpListener, TcpSocket, TcpStream};
1412

15-
cfg_udp! {
16-
mod udp;
17-
pub use self::udp::UdpSocket;
18-
}
13+
mod udp;
14+
pub use self::udp::UdpSocket;
1915

2016
#[cfg(unix)]
21-
cfg_uds! {
22-
mod uds;
23-
pub use self::uds::{SocketAddr, UnixDatagram, UnixListener, UnixStream};
24-
}
17+
mod uds;
18+
#[cfg(unix)]
19+
pub use self::uds::{SocketAddr, UnixDatagram, UnixListener, UnixStream};

src/sys/mod.rs

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -54,31 +54,7 @@ cfg_os_poll! {
5454
#[cfg(unix)]
5555
cfg_os_poll! {
5656
mod unix;
57-
pub use self::unix::SourceFd;
58-
59-
pub(crate) use self::unix::{event, Event, Events, Selector, Waker};
60-
61-
cfg_tcp! {
62-
pub(crate) use self::unix::tcp;
63-
}
64-
65-
cfg_udp! {
66-
pub(crate) use self::unix::udp;
67-
}
68-
69-
cfg_uds! {
70-
pub use self::unix::SocketAddr;
71-
72-
pub(crate) use self::unix::uds;
73-
}
74-
75-
cfg_pipe! {
76-
pub(crate) use self::unix::pipe;
77-
}
78-
79-
cfg_io_source! {
80-
pub(crate) use self::unix::IoSourceState;
81-
}
57+
pub use self::unix::*;
8258
}
8359

8460
#[cfg(windows)]
@@ -98,7 +74,7 @@ cfg_not_os_poll! {
9874
}
9975

10076
#[cfg(unix)]
101-
cfg_uds! {
77+
cfg_net! {
10278
pub use self::unix::SocketAddr;
10379
}
10480
}

src/sys/shell/mod.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,10 @@ pub(crate) use self::selector::{event, Event, Events, Selector};
1010
mod waker;
1111
pub(crate) use self::waker::Waker;
1212

13-
cfg_tcp! {
13+
cfg_net! {
1414
pub(crate) mod tcp;
15-
}
16-
17-
cfg_udp! {
1815
pub(crate) mod udp;
19-
}
20-
21-
#[cfg(unix)]
22-
cfg_uds! {
16+
#[cfg(unix)]
2317
pub(crate) mod uds;
2418
}
2519

src/sys/unix/mod.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ macro_rules! syscall {
1414
}
1515

1616
cfg_os_poll! {
17-
mod net;
18-
1917
mod selector;
2018
pub(crate) use self::selector::{event, Event, Events, Selector};
2119

@@ -25,15 +23,11 @@ cfg_os_poll! {
2523
mod waker;
2624
pub(crate) use self::waker::Waker;
2725

28-
cfg_tcp! {
29-
pub(crate) mod tcp;
30-
}
26+
cfg_net! {
27+
mod net;
3128

32-
cfg_udp! {
29+
pub(crate) mod tcp;
3330
pub(crate) mod udp;
34-
}
35-
36-
cfg_uds! {
3731
pub(crate) mod uds;
3832
pub use self::uds::SocketAddr;
3933
}
@@ -66,7 +60,7 @@ cfg_os_poll! {
6660
}
6761

6862
cfg_not_os_poll! {
69-
cfg_uds! {
63+
cfg_net! {
7064
mod uds;
7165
pub use self::uds::SocketAddr;
7266
}

src/sys/unix/net.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
#[cfg(all(feature = "os-poll", any(feature = "tcp", feature = "udp")))]
21
use std::net::SocketAddr;
32

4-
#[cfg(all(feature = "os-poll", any(feature = "udp")))]
53
pub(crate) fn new_ip_socket(
64
addr: SocketAddr,
75
socket_type: libc::c_int,
@@ -15,10 +13,6 @@ pub(crate) fn new_ip_socket(
1513
}
1614

1715
/// Create a new non-blocking socket.
18-
#[cfg(all(
19-
feature = "os-poll",
20-
any(feature = "tcp", feature = "udp", feature = "uds")
21-
))]
2216
pub(crate) fn new_socket(
2317
domain: libc::c_int,
2418
socket_type: libc::c_int,
@@ -70,7 +64,6 @@ pub(crate) fn new_socket(
7064
socket
7165
}
7266

73-
#[cfg(all(feature = "os-poll", any(feature = "tcp", feature = "udp")))]
7467
pub(crate) fn socket_addr(addr: &SocketAddr) -> (*const libc::sockaddr, libc::socklen_t) {
7568
use std::mem::size_of_val;
7669

@@ -87,7 +80,6 @@ pub(crate) fn socket_addr(addr: &SocketAddr) -> (*const libc::sockaddr, libc::so
8780
}
8881

8982
/// `storage` must be initialised to `sockaddr_in` or `sockaddr_in6`.
90-
#[cfg(all(feature = "os-poll", feature = "tcp"))]
9183
pub(crate) unsafe fn to_socket_addr(
9284
storage: *const libc::sockaddr_storage,
9385
) -> std::io::Result<SocketAddr> {

src/sys/windows/mod.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,10 @@ cfg_net! {
2525
}
2626
}};
2727
}
28-
}
2928

30-
cfg_tcp! {
31-
pub(crate) mod tcp;
32-
}
29+
mod net;
3330

34-
cfg_udp! {
31+
pub(crate) mod tcp;
3532
pub(crate) mod udp;
3633
}
3734

@@ -41,10 +38,6 @@ pub(crate) mod named_pipe;
4138
mod waker;
4239
pub(crate) use waker::Waker;
4340

44-
cfg_net! {
45-
mod net;
46-
}
47-
4841
cfg_io_source! {
4942
use std::io;
5043
use std::os::windows::io::RawSocket;

src/sys/windows/net.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ use std::sync::Once;
55

66
use winapi::ctypes::c_int;
77
use winapi::shared::ws2def::SOCKADDR;
8-
use winapi::um::winsock2::{
9-
ioctlsocket, socket, FIONBIO, INVALID_SOCKET, SOCKET,
10-
};
8+
use winapi::um::winsock2::{ioctlsocket, socket, FIONBIO, INVALID_SOCKET, SOCKET};
119

1210
/// Initialise the network stack for Windows.
1311
pub(crate) fn init() {
@@ -21,7 +19,6 @@ pub(crate) fn init() {
2119
}
2220

2321
/// Create a new non-blocking socket.
24-
#[cfg(feature = "udp")]
2522
pub(crate) fn new_ip_socket(addr: SocketAddr, socket_type: c_int) -> io::Result<SOCKET> {
2623
use winapi::um::winsock2::{PF_INET, PF_INET6};
2724

0 commit comments

Comments
 (0)