std/net/
mod.rs

1//! Networking primitives for TCP/UDP communication.
2//!
3//! This module provides networking functionality for the Transmission Control and User
4//! Datagram Protocols, as well as types for IP and socket addresses and functions related
5//! to network properties.
6//!
7//! # Organization
8//!
9//! * [`TcpListener`] and [`TcpStream`] provide functionality for communication over TCP
10//! * [`UdpSocket`] provides functionality for communication over UDP
11//! * [`IpAddr`] represents IP addresses of either IPv4 or IPv6; [`Ipv4Addr`] and
12//!   [`Ipv6Addr`] are respectively IPv4 and IPv6 addresses
13//! * [`SocketAddr`] represents socket addresses of either IPv4 or IPv6; [`SocketAddrV4`]
14//!   and [`SocketAddrV6`] are respectively IPv4 and IPv6 socket addresses
15//! * [`ToSocketAddrs`] is a trait that is used for generic address resolution when interacting
16//!   with networking objects like [`TcpListener`], [`TcpStream`] or [`UdpSocket`]
17//! * Other types are return or parameter types for various methods in this module
18//!
19//! Rust disables inheritance of socket objects to child processes by default when possible.  For
20//! example, through the use of the `CLOEXEC` flag in UNIX systems or the `HANDLE_FLAG_INHERIT`
21//! flag on Windows.
22
23#![stable(feature = "rust1", since = "1.0.0")]
24
25#[stable(feature = "rust1", since = "1.0.0")]
26pub use core::net::AddrParseError;
27
28#[unstable(feature = "gethostname", issue = "135142")]
29pub use self::hostname::hostname;
30#[stable(feature = "rust1", since = "1.0.0")]
31pub use self::ip_addr::{IpAddr, Ipv4Addr, Ipv6Addr, Ipv6MulticastScope};
32#[stable(feature = "rust1", since = "1.0.0")]
33pub use self::socket_addr::{SocketAddr, SocketAddrV4, SocketAddrV6, ToSocketAddrs};
34#[unstable(feature = "tcplistener_into_incoming", issue = "88373")]
35pub use self::tcp::IntoIncoming;
36#[stable(feature = "rust1", since = "1.0.0")]
37pub use self::tcp::{Incoming, TcpListener, TcpStream};
38#[stable(feature = "rust1", since = "1.0.0")]
39pub use self::udp::UdpSocket;
40
41mod hostname;
42mod ip_addr;
43mod socket_addr;
44mod tcp;
45#[cfg(test)]
46pub(crate) mod test;
47mod udp;
48
49/// Possible values which can be passed to the [`TcpStream::shutdown`] method.
50#[derive(Copy, Clone, PartialEq, Eq, Debug)]
51#[stable(feature = "rust1", since = "1.0.0")]
52pub enum Shutdown {
53    /// The reading portion of the [`TcpStream`] should be shut down.
54    ///
55    /// All currently blocked and future [reads] will return <code>[Ok]\(0)</code>.
56    ///
57    /// [reads]: crate::io::Read "io::Read"
58    #[stable(feature = "rust1", since = "1.0.0")]
59    Read,
60    /// The writing portion of the [`TcpStream`] should be shut down.
61    ///
62    /// All currently blocked and future [writes] will return an error.
63    ///
64    /// [writes]: crate::io::Write "io::Write"
65    #[stable(feature = "rust1", since = "1.0.0")]
66    Write,
67    /// Both the reading and the writing portions of the [`TcpStream`] should be shut down.
68    ///
69    /// See [`Shutdown::Read`] and [`Shutdown::Write`] for more information.
70    #[stable(feature = "rust1", since = "1.0.0")]
71    Both,
72}