diff options
Diffstat (limited to 'tokio/src/net')
-rw-r--r-- | tokio/src/net/addr.rs | 8 | ||||
-rw-r--r-- | tokio/src/net/mod.rs | 9 | ||||
-rw-r--r-- | tokio/src/net/tcp/listener.rs | 46 | ||||
-rw-r--r-- | tokio/src/net/tcp/mod.rs | 25 | ||||
-rw-r--r-- | tokio/src/net/tcp/stream.rs | 60 | ||||
-rw-r--r-- | tokio/src/net/udp/mod.rs | 13 | ||||
-rw-r--r-- | tokio/src/net/udp/socket.rs | 8 | ||||
-rw-r--r-- | tokio/src/net/unix/datagram.rs | 8 | ||||
-rw-r--r-- | tokio/src/net/unix/listener.rs | 8 | ||||
-rw-r--r-- | tokio/src/net/unix/mod.rs | 15 | ||||
-rw-r--r-- | tokio/src/net/unix/stream.rs | 16 |
11 files changed, 107 insertions, 109 deletions
diff --git a/tokio/src/net/addr.rs b/tokio/src/net/addr.rs index aa66c5fa..8e3bf434 100644 --- a/tokio/src/net/addr.rs +++ b/tokio/src/net/addr.rs @@ -5,6 +5,14 @@ use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV /// Convert or resolve without blocking to one or more `SocketAddr` values. /// +/// # DNS +/// +/// Implementations of `ToSocketAddrs` for string types require a DNS lookup. +/// These implementations are only provided when Tokio is used with the +/// **`dns`** feature flag. +/// +/// # Calling +/// /// Currently, this trait is only used as an argument to Tokio functions that /// need to reference a target socket address. /// diff --git a/tokio/src/net/mod.rs b/tokio/src/net/mod.rs index ac913b21..a7b98cdb 100644 --- a/tokio/src/net/mod.rs +++ b/tokio/src/net/mod.rs @@ -28,15 +28,18 @@ pub use addr::ToSocketAddrs; cfg_tcp! { pub mod tcp; - pub use tcp::{TcpListener, TcpStream}; + pub use tcp::listener::TcpListener; + pub use tcp::stream::TcpStream; } cfg_udp! { pub mod udp; - pub use udp::UdpSocket; + pub use udp::socket::UdpSocket; } cfg_uds! { pub mod unix; - pub use unix::{UnixDatagram, UnixListener, UnixStream}; + pub use unix::datagram::UnixDatagram; + pub use unix::listener::UnixListener; + pub use unix::stream::UnixStream; } diff --git a/tokio/src/net/tcp/listener.rs b/tokio/src/net/tcp/listener.rs index 5db5ee80..59762b13 100644 --- a/tokio/src/net/tcp/listener.rs +++ b/tokio/src/net/tcp/listener.rs @@ -9,28 +9,30 @@ use std::io; use std::net::{self, SocketAddr}; use std::task::{Context, Poll}; -/// An I/O object representing a TCP socket listening for incoming connections. -/// -/// # Examples -/// -/// ```no_run -/// use tokio::net::TcpListener; -/// -/// use std::io; -/// # async fn process_socket<T>(_socket: T) {} -/// -/// #[tokio::main] -/// async fn main() -> io::Result<()> { -/// let mut listener = TcpListener::bind("127.0.0.1:8080").await?; -/// -/// loop { -/// let (socket, _) = listener.accept().await?; -/// process_socket(socket).await; -/// } -/// } -/// ``` -pub struct TcpListener { - io: PollEvented<mio::net::TcpListener>, +cfg_tcp! { + /// A TCP socket server, listening for connections. + /// + /// # Examples + /// + /// ```no_run + /// use tokio::net::TcpListener; + /// + /// use std::io; + /// # async fn process_socket<T>(_socket: T) {} + /// + /// #[tokio::main] + /// async fn main() -> io::Result<()> { + /// let mut listener = TcpListener::bind("127.0.0.1:8080").await?; + /// + /// loop { + /// let (socket, _) = listener.accept().await?; + /// process_socket(socket).await; + /// } + /// } + /// ``` + pub struct TcpListener { + io: PollEvented<mio::net::TcpListener>, + } } impl TcpListener { diff --git a/tokio/src/net/tcp/mod.rs b/tokio/src/net/tcp/mod.rs index 929a1e00..d5354b38 100644 --- a/tokio/src/net/tcp/mod.rs +++ b/tokio/src/net/tcp/mod.rs @@ -1,22 +1,7 @@ -//! TCP bindings for `tokio`. -//! -//! This module contains the TCP networking types, similar to the standard -//! library, which can be used to implement networking protocols. -//! -//! Connecting to an address, via TCP, can be done using [`TcpStream`]'s -//! [`connect`] method, which returns a future which returns a `TcpStream`. -//! -//! To listen on an address [`TcpListener`] can be used. `TcpListener`'s -//! [`incoming`][TcpListener::incoming] method can be used to accept new connections. -//! It return the [`Incoming`] struct, which implements a stream which returns -//! `TcpStream`s. -//! -//! [`TcpStream`]: struct.TcpStream.html -//! [`connect`]: struct.TcpStream.html#method.connect -//! [`TcpListener`]: struct.TcpListener.html +//! TCP utility types -mod listener; -pub use listener::TcpListener; +pub(crate) mod listener; +pub(crate) use listener::TcpListener; mod incoming; pub use incoming::Incoming; @@ -24,5 +9,5 @@ pub use incoming::Incoming; mod split; pub use split::{ReadHalf, WriteHalf}; -mod stream; -pub use stream::TcpStream; +pub(crate) mod stream; +pub(crate) use stream::TcpStream; diff --git a/tokio/src/net/tcp/stream.rs b/tokio/src/net/tcp/stream.rs index 34d3a493..b961e363 100644 --- a/tokio/src/net/tcp/stream.rs +++ b/tokio/src/net/tcp/stream.rs @@ -12,35 +12,37 @@ use std::pin::Pin; use std::task::{Context, Poll}; use std::time::Duration; -/// An I/O object representing a TCP stream connected to a remote endpoint. -/// -/// A TCP stream can either be created by connecting to an endpoint, via the -/// [`connect`] method, or by [accepting] a connection from a [listener]. -/// -/// [`connect`]: struct.TcpStream.html#method.connect -/// [accepting]: struct.TcpListener.html#method.accept -/// [listener]: struct.TcpListener.html -/// -/// # Examples -/// -/// ```no_run -/// use tokio::net::TcpStream; -/// use tokio::prelude::*; -/// use std::error::Error; -/// -/// #[tokio::main] -/// async fn main() -> Result<(), Box<dyn Error>> { -/// // Connect to a peer -/// let mut stream = TcpStream::connect("127.0.0.1:8080").await?; -/// -/// // Write some data. -/// stream.write_all(b"hello world!").await?; -/// -/// Ok(()) -/// } -/// ``` -pub struct TcpStream { - io: PollEvented<mio::net::TcpStream>, +cfg_tcp! { + /// A TCP stream between a local and a remote socket. + /// + /// A TCP stream can either be created by connecting to an endpoint, via the + /// [`connect`] method, or by [accepting] a connection from a [listener]. + /// + /// [`connect`]: struct.TcpStream.html#method.connect + /// [accepting]: struct.TcpListener.html#method.accept + /// [listener]: struct.TcpListener.html + /// + /// # Examples + /// + /// ```no_run + /// use tokio::net::TcpStream; + /// use tokio::prelude::*; + /// use std::error::Error; + /// + /// #[tokio::main] + /// async fn main() -> Result<(), Box<dyn Error>> { + /// // Connect to a peer + /// let mut stream = TcpStream::connect("127.0.0.1:8080").await?; + /// + /// // Write some data. + /// stream.write_all(b"hello world!").await?; + /// + /// Ok(()) + /// } + /// ``` + pub struct TcpStream { + io: PollEvented<mio::net::TcpStream>, + } } impl TcpStream { diff --git a/tokio/src/net/udp/mod.rs b/tokio/src/net/udp/mod.rs index b4d3ea46..a616f4d5 100644 --- a/tokio/src/net/udp/mod.rs +++ b/tokio/src/net/udp/mod.rs @@ -1,14 +1,7 @@ -//! UDP bindings for `tokio`. -//! -//! This module contains the UDP networking types, similar to the standard -//! library, which can be used to implement networking protocols. -//! -//! The main struct for UDP is the [`UdpSocket`], which represents a UDP socket. -//! -//! [`UdpSocket`]: struct.UdpSocket +//! UDP utility types. -mod socket; -pub use socket::UdpSocket; +pub(crate) mod socket; +pub(crate) use socket::UdpSocket; mod split; pub use split::{RecvHalf, SendHalf, ReuniteError}; diff --git a/tokio/src/net/udp/socket.rs b/tokio/src/net/udp/socket.rs index 30cc104e..c22ebd92 100644 --- a/tokio/src/net/udp/socket.rs +++ b/tokio/src/net/udp/socket.rs @@ -9,9 +9,11 @@ use std::io; use std::net::{self, Ipv4Addr, Ipv6Addr, SocketAddr}; use std::task::{Context, Poll}; -/// An I/O object representing a UDP socket. -pub struct UdpSocket { - io: PollEvented<mio::net::UdpSocket>, +cfg_udp! { + /// A UDP socket + pub struct UdpSocket { + io: PollEvented<mio::net::UdpSocket>, + } } impl UdpSocket { diff --git a/tokio/src/net/unix/datagram.rs b/tokio/src/net/unix/datagram.rs index eb8bfe4c..ae1372f6 100644 --- a/tokio/src/net/unix/datagram.rs +++ b/tokio/src/net/unix/datagram.rs @@ -10,9 +10,11 @@ use std::os::unix::net::{self, SocketAddr}; use std::path::Path; use std::task::{Context, Poll}; -/// An I/O object representing a Unix datagram socket. -pub struct UnixDatagram { - io: PollEvented<mio_uds::UnixDatagram>, +cfg_uds! { + /// An I/O object representing a Unix datagram socket. + pub struct UnixDatagram { + io: PollEvented<mio_uds::UnixDatagram>, + } } impl UnixDatagram { diff --git a/tokio/src/net/unix/listener.rs b/tokio/src/net/unix/listener.rs index 7791b05f..5f4787ec 100644 --- a/tokio/src/net/unix/listener.rs +++ b/tokio/src/net/unix/listener.rs @@ -12,9 +12,11 @@ use std::os::unix::net::{self, SocketAddr}; use std::path::Path; use std::task::{Context, Poll}; -/// A Unix socket which can accept connections from other Unix sockets. -pub struct UnixListener { - io: PollEvented<mio_uds::UnixListener>, +cfg_uds! { + /// A Unix socket which can accept connections from other Unix sockets. + pub struct UnixListener { + io: PollEvented<mio_uds::UnixListener>, + } } impl UnixListener { diff --git a/tokio/src/net/unix/mod.rs b/tokio/src/net/unix/mod.rs index 1ec6fa8e..ddba60d1 100644 --- a/tokio/src/net/unix/mod.rs +++ b/tokio/src/net/unix/mod.rs @@ -1,21 +1,18 @@ -//! Unix Domain Sockets for Tokio. -//! -//! This crate provides APIs for using Unix Domain Sockets with Tokio. +//! Unix domain socket utility types -mod datagram; -pub use datagram::UnixDatagram; +pub(crate) mod datagram; mod incoming; pub use incoming::Incoming; -mod listener; -pub use listener::UnixListener; +pub(crate) mod listener; +pub(crate) use listener::UnixListener; mod split; pub use split::{ReadHalf, WriteHalf}; -mod stream; -pub use stream::UnixStream; +pub(crate) mod stream; +pub(crate) use stream::UnixStream; mod ucred; pub use ucred::UCred; diff --git a/tokio/src/net/unix/stream.rs b/tokio/src/net/unix/stream.rs index a430fa17..5151b08a 100644 --- a/tokio/src/net/unix/stream.rs +++ b/tokio/src/net/unix/stream.rs @@ -14,13 +14,15 @@ use std::path::Path; use std::pin::Pin; use std::task::{Context, Poll}; -/// A structure representing a connected Unix socket. -/// -/// This socket can be connected directly with `UnixStream::connect` or accepted -/// from a listener with `UnixListener::incoming`. Additionally, a pair of -/// anonymous Unix sockets can be created with `UnixStream::pair`. -pub struct UnixStream { - io: PollEvented<mio_uds::UnixStream>, +cfg_uds! { + /// A structure representing a connected Unix socket. + /// + /// This socket can be connected directly with `UnixStream::connect` or accepted + /// from a listener with `UnixListener::incoming`. Additionally, a pair of + /// anonymous Unix sockets can be created with `UnixStream::pair`. + pub struct UnixStream { + io: PollEvented<mio_uds::UnixStream>, + } } impl UnixStream { |