Auto merge of #23352 - alexcrichton:stabilize-net, r=aturon
This commit performs a stabilization pass over the std::net module,
incorporating the changes from RFC 923. Specifically, the following actions were
taken:
Stable functionality:
* `net` (the name)
* `Shutdown`
* `Shutdown::{Read, Write, Both}`
* `lookup_host`
* `LookupHost`
* `SocketAddr`
* `SocketAddr::{V4, V6}`
* `SocketAddr::port`
* `SocketAddrV4`
* `SocketAddrV4::{new, ip, port}`
* `SocketAddrV6`
* `SocketAddrV4::{new, ip, port, flowinfo, scope_id}`
* Common trait impls for socket addr structures
* `ToSocketAddrs`
* `ToSocketAddrs::Iter`
* `ToSocketAddrs::to_socket_addrs`
* `ToSocketAddrs for {SocketAddr*, (Ipv*Addr, u16), str, (str, u16)}`
* `Ipv4Addr`
* `Ipv4Addr::{new, octets, to_ipv6_compatible, to_ipv6_mapped}`
* `Ipv6Addr`
* `Ipv6Addr::{new, segments, to_ipv4}`
* `TcpStream`
* `TcpStream::connect`
* `TcpStream::{peer_addr, local_addr, shutdown, try_clone}`
* `{Read,Write} for {TcpStream, &TcpStream}`
* `TcpListener`
* `TcpListener::bind`
* `TcpListener::{local_addr, try_clone, accept, incoming}`
* `Incoming`
* `UdpSocket`
* `UdpSocket::bind`
* `UdpSocket::{recv_from, send_to, local_addr, try_clone}`
Unstable functionality:
* Extra methods on `Ipv{4,6}Addr` for various methods of inspecting the address
and determining qualities of it.
* Extra methods on `TcpStream` to configure various protocol options.
* Extra methods on `UdpSocket` to configure various protocol options.
Deprecated functionality:
* The `socket_addr` method has been renamed to `local_addr`
This commit is a breaking change due to the restructuring of the `SocketAddr`
type as well as the renaming of the `socket_addr` method. Migration should be
fairly straightforward, however, after accounting for the new level of
abstraction in `SocketAddr` (protocol distinction at the socket address level,
not the IP address).
[breaking-change]
This commit is contained in:
@@ -13,7 +13,7 @@
|
||||
//! > **NOTE**: This module is very much a work in progress and is under active
|
||||
//! > development.
|
||||
|
||||
#![unstable(feature = "net")]
|
||||
#![stable(feature = "rust1", since = "1.0.0")]
|
||||
|
||||
use prelude::v1::*;
|
||||
|
||||
@@ -21,8 +21,8 @@ use io::{self, Error, ErrorKind};
|
||||
use num::Int;
|
||||
use sys_common::net2 as net_imp;
|
||||
|
||||
pub use self::ip::{IpAddr, Ipv4Addr, Ipv6Addr, Ipv6MulticastScope};
|
||||
pub use self::addr::{SocketAddr, ToSocketAddrs};
|
||||
pub use self::ip::{Ipv4Addr, Ipv6Addr, Ipv6MulticastScope};
|
||||
pub use self::addr::{SocketAddr, SocketAddrV4, SocketAddrV6, ToSocketAddrs};
|
||||
pub use self::tcp::{TcpStream, TcpListener};
|
||||
pub use self::udp::UdpSocket;
|
||||
|
||||
@@ -36,23 +36,27 @@ mod parser;
|
||||
/// Possible values which can be passed to the `shutdown` method of `TcpStream`
|
||||
/// and `UdpSocket`.
|
||||
#[derive(Copy, Clone, PartialEq)]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub enum Shutdown {
|
||||
/// Indicates that the reading portion of this stream/socket should be shut
|
||||
/// down. All currently blocked and future reads will return `Ok(0)`.
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
Read,
|
||||
/// Indicates that the writing portion of this stream/socket should be shut
|
||||
/// down. All currently blocked and future writes will return an error.
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
Write,
|
||||
/// Shut down both the reading and writing portions of this stream.
|
||||
///
|
||||
/// See `Shutdown::Read` and `Shutdown::Write` for more information.
|
||||
Both
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
Both,
|
||||
}
|
||||
|
||||
fn hton<I: Int>(i: I) -> I { i.to_be() }
|
||||
fn ntoh<I: Int>(i: I) -> I { Int::from_be(i) }
|
||||
|
||||
fn each_addr<A: ToSocketAddrs + ?Sized, F, T>(addr: &A, mut f: F) -> io::Result<T>
|
||||
fn each_addr<A: ToSocketAddrs, F, T>(addr: A, mut f: F) -> io::Result<T>
|
||||
where F: FnMut(&SocketAddr) -> io::Result<T>
|
||||
{
|
||||
let mut last_err = None;
|
||||
@@ -69,8 +73,10 @@ fn each_addr<A: ToSocketAddrs + ?Sized, F, T>(addr: &A, mut f: F) -> io::Result<
|
||||
}
|
||||
|
||||
/// An iterator over `SocketAddr` values returned from a host lookup operation.
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub struct LookupHost(net_imp::LookupHost);
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl Iterator for LookupHost {
|
||||
type Item = io::Result<SocketAddr>;
|
||||
fn next(&mut self) -> Option<io::Result<SocketAddr>> { self.0.next() }
|
||||
@@ -93,6 +99,7 @@ impl Iterator for LookupHost {
|
||||
/// # Ok(())
|
||||
/// # }
|
||||
/// ```
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub fn lookup_host(host: &str) -> io::Result<LookupHost> {
|
||||
net_imp::lookup_host(host).map(LookupHost)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user