Rename networking constructors with _std

This commit renames the various constructors of networking types to have a
`_std` suffix instead of a smorgasboard of other suffixes, canonicalizing on
`_std` as the suffix for constructors which take the libstd corresponding types.
This commit is contained in:
Alex Crichton
2017-12-05 08:24:26 -08:00
parent 259996d805
commit 8fcce957cd
4 changed files with 17 additions and 15 deletions
+1 -1
View File
@@ -79,7 +79,7 @@ fn worker(rx: mpsc::UnboundedReceiver<net::TcpStream>) {
// using the `TcpStream::from_stream` API. After that the socket is not // using the `TcpStream::from_stream` API. After that the socket is not
// a `tokio::net::TcpStream` meaning it's in nonblocking mode and // a `tokio::net::TcpStream` meaning it's in nonblocking mode and
// ready to be used with Tokio // ready to be used with Tokio
let socket = TcpStream::from_stream(socket, &handle) let socket = TcpStream::from_std(socket, &handle)
.expect("failed to associate TCP stream"); .expect("failed to associate TCP stream");
let addr = socket.peer_addr().expect("failed to get remote address"); let addr = socket.peer_addr().expect("failed to get remote address");
+1 -1
View File
@@ -81,7 +81,7 @@ fn worker(rx: mpsc::UnboundedReceiver<net::TcpStream>) {
// request/response types instead of bytes. Here we'll just use our // request/response types instead of bytes. Here we'll just use our
// framing defined below and then use the `send_all` helper to send the // framing defined below and then use the `send_all` helper to send the
// responses back on the socket after we've processed them // responses back on the socket after we've processed them
let socket = future::result(TcpStream::from_stream(socket, &handle)); let socket = future::result(TcpStream::from_std(socket, &handle));
let req = socket.and_then(|socket| { let req = socket.and_then(|socket| {
let (tx, rx) = socket.framed(Http).split(); let (tx, rx) = socket.framed(Http).split();
tx.send_all(rx.and_then(respond)) tx.send_all(rx.and_then(respond))
+13 -11
View File
@@ -103,10 +103,10 @@ impl TcpListener {
/// will only be for the same IP version as `addr` specified. That is, if /// will only be for the same IP version as `addr` specified. That is, if
/// `addr` is an IPv4 address then all sockets accepted will be IPv4 as /// `addr` is an IPv4 address then all sockets accepted will be IPv4 as
/// well (same for IPv6). /// well (same for IPv6).
pub fn from_listener(listener: net::TcpListener, pub fn from_std(listener: net::TcpListener,
addr: &SocketAddr, addr: &SocketAddr,
handle: &Handle) -> io::Result<TcpListener> { handle: &Handle) -> io::Result<TcpListener> {
let l = try!(mio::net::TcpListener::from_listener(listener, addr)); let l = mio::net::TcpListener::from_listener(listener, addr)?;
TcpListener::new(l, handle) TcpListener::new(l, handle)
} }
@@ -252,9 +252,10 @@ impl TcpStream {
/// to a TCP stream ready to be used with the provided event loop handle. /// to a TCP stream ready to be used with the provided event loop handle.
/// The stream returned is associated with the event loop and ready to /// The stream returned is associated with the event loop and ready to
/// perform I/O. /// perform I/O.
pub fn from_stream(stream: net::TcpStream, handle: &Handle) pub fn from_std(stream: net::TcpStream, handle: &Handle)
-> io::Result<TcpStream> { -> io::Result<TcpStream>
let inner = try!(mio::net::TcpStream::from_stream(stream)); {
let inner = mio::net::TcpStream::from_stream(stream)?;
Ok(TcpStream { Ok(TcpStream {
io: try!(PollEvented::new(inner, handle)), io: try!(PollEvented::new(inner, handle)),
}) })
@@ -278,10 +279,11 @@ impl TcpStream {
/// loop. Note that on Windows you must `bind` a socket before it can be /// loop. Note that on Windows you must `bind` a socket before it can be
/// connected, so if a custom `TcpBuilder` is used it should be bound /// connected, so if a custom `TcpBuilder` is used it should be bound
/// (perhaps to `INADDR_ANY`) before this method is called. /// (perhaps to `INADDR_ANY`) before this method is called.
pub fn connect_stream(stream: net::TcpStream, pub fn connect_std(stream: net::TcpStream,
addr: &SocketAddr, addr: &SocketAddr,
handle: &Handle) handle: &Handle)
-> Box<Future<Item=TcpStream, Error=io::Error> + Send> { -> Box<Future<Item=TcpStream, Error=io::Error> + Send>
{
let state = match mio::net::TcpStream::connect_stream(stream, addr) { let state = match mio::net::TcpStream::connect_stream(stream, addr) {
Ok(tcp) => TcpStream::new(tcp, handle), Ok(tcp) => TcpStream::new(tcp, handle),
Err(e) => TcpStreamNewState::Error(e), Err(e) => TcpStreamNewState::Error(e),
+2 -2
View File
@@ -37,8 +37,8 @@ impl UdpSocket {
/// This can be used in conjunction with net2's `UdpBuilder` interface to /// This can be used in conjunction with net2's `UdpBuilder` interface to
/// configure a socket before it's handed off, such as setting options like /// configure a socket before it's handed off, such as setting options like
/// `reuse_address` or binding to multiple addresses. /// `reuse_address` or binding to multiple addresses.
pub fn from_socket(socket: net::UdpSocket, pub fn from_std(socket: net::UdpSocket,
handle: &Handle) -> io::Result<UdpSocket> { handle: &Handle) -> io::Result<UdpSocket> {
let udp = try!(mio::net::UdpSocket::from_socket(socket)); let udp = try!(mio::net::UdpSocket::from_socket(socket));
UdpSocket::new(udp, handle) UdpSocket::new(udp, handle)
} }