mirror of
https://github.com/tokio-rs/tokio.git
synced 2025-10-01 12:20:39 +00:00
Rename TcpStreamNew -> ConnectFuture (#111)
This commit is contained in:
parent
a5e9c311bf
commit
3840ceafee
@ -6,7 +6,7 @@
|
|||||||
//! # TCP
|
//! # TCP
|
||||||
//!
|
//!
|
||||||
//! Connecting to an address, via TCP, can be done using [`TcpStream`]'s
|
//! Connecting to an address, via TCP, can be done using [`TcpStream`]'s
|
||||||
//! [`connect`] method, which returns [`TcpStreamNew`]. `TcpStreamNew`
|
//! [`connect`] method, which returns [`ConnectFuture`]. `ConnectFuture`
|
||||||
//! implements a future which returns a `TcpStream`.
|
//! implements a future which returns a `TcpStream`.
|
||||||
//!
|
//!
|
||||||
//! To listen on an address [`TcpListener`] can be used. `TcpListener`'s
|
//! To listen on an address [`TcpListener`] can be used. `TcpListener`'s
|
||||||
@ -16,7 +16,7 @@
|
|||||||
//!
|
//!
|
||||||
//! [`TcpStream`]: struct.TcpStream.html
|
//! [`TcpStream`]: struct.TcpStream.html
|
||||||
//! [`connect`]: struct.TcpStream.html#method.connect
|
//! [`connect`]: struct.TcpStream.html#method.connect
|
||||||
//! [`TcpStreamNew`]: struct.TcpStreamNew.html
|
//! [`ConnectFuture`]: struct.ConnectFuture.html
|
||||||
//! [`TcpListener`]: struct.TcpListener.html
|
//! [`TcpListener`]: struct.TcpListener.html
|
||||||
//! [incoming_method]: struct.TcpListener.html#method.incoming
|
//! [incoming_method]: struct.TcpListener.html#method.incoming
|
||||||
//! [`Incoming`]: struct.Incoming.html
|
//! [`Incoming`]: struct.Incoming.html
|
||||||
@ -41,6 +41,6 @@
|
|||||||
mod tcp;
|
mod tcp;
|
||||||
mod udp;
|
mod udp;
|
||||||
|
|
||||||
pub use self::tcp::{TcpStream, TcpStreamNew};
|
pub use self::tcp::{TcpStream, ConnectFuture};
|
||||||
pub use self::tcp::{TcpListener, Incoming};
|
pub use self::tcp::{TcpListener, Incoming};
|
||||||
pub use self::udp::{UdpSocket, UdpCodec, UdpFramed, SendDgram, RecvDgram};
|
pub use self::udp::{UdpSocket, UdpCodec, UdpFramed, SendDgram, RecvDgram};
|
||||||
|
@ -197,13 +197,13 @@ pub struct TcpStream {
|
|||||||
/// when the stream is connected.
|
/// when the stream is connected.
|
||||||
#[must_use = "futures do nothing unless polled"]
|
#[must_use = "futures do nothing unless polled"]
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct TcpStreamNew {
|
pub struct ConnectFuture {
|
||||||
inner: TcpStreamNewState,
|
inner: ConnectFutureState,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[must_use = "futures do nothing unless polled"]
|
#[must_use = "futures do nothing unless polled"]
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
enum TcpStreamNewState {
|
enum ConnectFutureState {
|
||||||
Waiting(TcpStream),
|
Waiting(TcpStream),
|
||||||
Error(io::Error),
|
Error(io::Error),
|
||||||
Empty,
|
Empty,
|
||||||
@ -216,19 +216,19 @@ impl TcpStream {
|
|||||||
/// the `addr` provided. The returned future will be resolved once the
|
/// the `addr` provided. The returned future will be resolved once the
|
||||||
/// stream has successfully connected, or it wil return an error if one
|
/// stream has successfully connected, or it wil return an error if one
|
||||||
/// occurs.
|
/// occurs.
|
||||||
pub fn connect(addr: &SocketAddr) -> TcpStreamNew {
|
pub fn connect(addr: &SocketAddr) -> ConnectFuture {
|
||||||
let inner = match mio::net::TcpStream::connect(addr) {
|
let inner = match mio::net::TcpStream::connect(addr) {
|
||||||
Ok(tcp) => TcpStream::new(tcp, &Handle::default()),
|
Ok(tcp) => TcpStream::new(tcp, &Handle::default()),
|
||||||
Err(e) => TcpStreamNewState::Error(e),
|
Err(e) => ConnectFutureState::Error(e),
|
||||||
};
|
};
|
||||||
TcpStreamNew { inner: inner }
|
ConnectFuture { inner: inner }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn new(connected_stream: mio::net::TcpStream, handle: &Handle)
|
fn new(connected_stream: mio::net::TcpStream, handle: &Handle)
|
||||||
-> TcpStreamNewState {
|
-> ConnectFutureState {
|
||||||
match PollEvented::new(connected_stream, handle) {
|
match PollEvented::new(connected_stream, handle) {
|
||||||
Ok(io) => TcpStreamNewState::Waiting(TcpStream { io: io }),
|
Ok(io) => ConnectFutureState::Waiting(TcpStream { io: io }),
|
||||||
Err(e) => TcpStreamNewState::Error(e),
|
Err(e) => ConnectFutureState::Error(e),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -268,13 +268,13 @@ impl TcpStream {
|
|||||||
pub fn connect_std(stream: net::TcpStream,
|
pub fn connect_std(stream: net::TcpStream,
|
||||||
addr: &SocketAddr,
|
addr: &SocketAddr,
|
||||||
handle: &Handle)
|
handle: &Handle)
|
||||||
-> TcpStreamNew
|
-> ConnectFuture
|
||||||
{
|
{
|
||||||
let inner = match mio::net::TcpStream::connect_stream(stream, addr) {
|
let inner = 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) => ConnectFutureState::Error(e),
|
||||||
};
|
};
|
||||||
TcpStreamNew { inner: inner }
|
ConnectFuture { inner: inner }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the local address that this stream is bound to.
|
/// Returns the local address that this stream is bound to.
|
||||||
@ -549,7 +549,7 @@ impl fmt::Debug for TcpStream {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Future for TcpStreamNew {
|
impl Future for ConnectFuture {
|
||||||
type Item = TcpStream;
|
type Item = TcpStream;
|
||||||
type Error = io::Error;
|
type Error = io::Error;
|
||||||
|
|
||||||
@ -558,22 +558,22 @@ impl Future for TcpStreamNew {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Future for TcpStreamNewState {
|
impl Future for ConnectFutureState {
|
||||||
type Item = TcpStream;
|
type Item = TcpStream;
|
||||||
type Error = io::Error;
|
type Error = io::Error;
|
||||||
|
|
||||||
fn poll(&mut self) -> Poll<TcpStream, io::Error> {
|
fn poll(&mut self) -> Poll<TcpStream, io::Error> {
|
||||||
{
|
{
|
||||||
let stream = match *self {
|
let stream = match *self {
|
||||||
TcpStreamNewState::Waiting(ref mut s) => s,
|
ConnectFutureState::Waiting(ref mut s) => s,
|
||||||
TcpStreamNewState::Error(_) => {
|
ConnectFutureState::Error(_) => {
|
||||||
let e = match mem::replace(self, TcpStreamNewState::Empty) {
|
let e = match mem::replace(self, ConnectFutureState::Empty) {
|
||||||
TcpStreamNewState::Error(e) => e,
|
ConnectFutureState::Error(e) => e,
|
||||||
_ => panic!(),
|
_ => panic!(),
|
||||||
};
|
};
|
||||||
return Err(e)
|
return Err(e)
|
||||||
}
|
}
|
||||||
TcpStreamNewState::Empty => panic!("can't poll TCP stream twice"),
|
ConnectFutureState::Empty => panic!("can't poll TCP stream twice"),
|
||||||
};
|
};
|
||||||
|
|
||||||
// Once we've connected, wait for the stream to be writable as
|
// Once we've connected, wait for the stream to be writable as
|
||||||
@ -589,8 +589,8 @@ impl Future for TcpStreamNewState {
|
|||||||
return Err(e)
|
return Err(e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
match mem::replace(self, TcpStreamNewState::Empty) {
|
match mem::replace(self, ConnectFutureState::Empty) {
|
||||||
TcpStreamNewState::Waiting(stream) => Ok(Async::Ready(stream)),
|
ConnectFutureState::Waiting(stream) => Ok(Async::Ready(stream)),
|
||||||
_ => panic!(),
|
_ => panic!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user