2015-02-05 18:50:11 -06:00
|
|
|
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
|
|
|
use prelude::v1::*;
|
|
|
|
|
|
|
|
use env;
|
2015-04-15 15:48:42 -05:00
|
|
|
use net::{SocketAddr, SocketAddrV4, SocketAddrV6, Ipv4Addr, Ipv6Addr, ToSocketAddrs};
|
2015-05-27 03:18:36 -05:00
|
|
|
use sync::atomic::{AtomicUsize, Ordering};
|
2015-02-05 18:50:11 -06:00
|
|
|
|
2015-05-27 03:18:36 -05:00
|
|
|
static PORT: AtomicUsize = AtomicUsize::new(0);
|
2015-02-26 21:04:42 -06:00
|
|
|
|
2015-02-05 18:50:11 -06:00
|
|
|
pub fn next_test_ip4() -> SocketAddr {
|
std: Stabilize the `net` module
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]
2015-03-13 16:22:33 -05:00
|
|
|
let port = PORT.fetch_add(1, Ordering::SeqCst) as u16 + base_port();
|
|
|
|
SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::new(127, 0, 0, 1), port))
|
2015-02-05 18:50:11 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn next_test_ip6() -> SocketAddr {
|
std: Stabilize the `net` module
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]
2015-03-13 16:22:33 -05:00
|
|
|
let port = PORT.fetch_add(1, Ordering::SeqCst) as u16 + base_port();
|
|
|
|
SocketAddr::V6(SocketAddrV6::new(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1),
|
|
|
|
port, 0, 0))
|
2015-02-05 18:50:11 -06:00
|
|
|
}
|
|
|
|
|
2015-04-15 15:48:42 -05:00
|
|
|
pub fn sa4(a: Ipv4Addr, p: u16) -> SocketAddr {
|
|
|
|
SocketAddr::V4(SocketAddrV4::new(a, p))
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn sa6(a: Ipv6Addr, p: u16) -> SocketAddr {
|
|
|
|
SocketAddr::V6(SocketAddrV6::new(a, p, 0, 0))
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn tsa<A: ToSocketAddrs>(a: A) -> Result<Vec<SocketAddr>, String> {
|
|
|
|
match a.to_socket_addrs() {
|
|
|
|
Ok(a) => Ok(a.collect()),
|
|
|
|
Err(e) => Err(e.to_string()),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-05 18:50:11 -06:00
|
|
|
// The bots run multiple builds at the same time, and these builds
|
|
|
|
// all want to use ports. This function figures out which workspace
|
|
|
|
// it is running in and assigns a port range based on it.
|
|
|
|
fn base_port() -> u16 {
|
|
|
|
let cwd = env::current_dir().unwrap();
|
2015-10-23 12:50:53 -05:00
|
|
|
let dirs = ["32-opt", "32-nopt",
|
|
|
|
"musl-64-opt", "cross-opt",
|
|
|
|
"64-opt", "64-nopt", "64-opt-vg", "64-debug-opt",
|
2015-02-05 18:50:11 -06:00
|
|
|
"all-opt", "snap3", "dist"];
|
2015-02-19 11:57:25 -06:00
|
|
|
dirs.iter().enumerate().find(|&(_, dir)| {
|
2015-02-23 12:59:17 -06:00
|
|
|
cwd.to_str().unwrap().contains(dir)
|
2015-02-05 18:50:11 -06:00
|
|
|
}).map(|p| p.0).unwrap_or(0) as u16 * 1000 + 19600
|
|
|
|
}
|