mirror of https://github.com/fafhrd91/actix-net
internal rename
This commit is contained in:
parent
a0e04c797b
commit
375597ad90
|
@ -13,12 +13,12 @@ pub(crate) enum ConnectAddrs {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ConnectAddrs {
|
impl ConnectAddrs {
|
||||||
pub(crate) fn is_none(&self) -> bool {
|
pub(crate) fn is_unresolved(&self) -> bool {
|
||||||
matches!(self, Self::None)
|
matches!(self, Self::None)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn is_some(&self) -> bool {
|
pub(crate) fn is_resolved(&self) -> bool {
|
||||||
!self.is_none()
|
!self.is_unresolved()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -80,8 +80,8 @@ impl<R: Host> ConnectInfo<R> {
|
||||||
|
|
||||||
/// Set local address to connection with.
|
/// Set local address to connection with.
|
||||||
///
|
///
|
||||||
/// Useful in situations where you know the IP address bound to a particular network interface
|
/// Useful in situations where the IP address bound to a particular network interface is known.
|
||||||
/// and want to make sure the socket is opened through that interface.
|
/// This would make sure the socket is opened through that interface.
|
||||||
pub fn set_local_addr(mut self, addr: impl Into<IpAddr>) -> Self {
|
pub fn set_local_addr(mut self, addr: impl Into<IpAddr>) -> Self {
|
||||||
self.local_addr = Some(addr.into());
|
self.local_addr = Some(addr.into());
|
||||||
self
|
self
|
||||||
|
|
|
@ -101,12 +101,14 @@ impl<R: Host> Service<ConnectInfo<R>> for ResolverService {
|
||||||
actix_service::always_ready!();
|
actix_service::always_ready!();
|
||||||
|
|
||||||
fn call(&self, req: ConnectInfo<R>) -> Self::Future {
|
fn call(&self, req: ConnectInfo<R>) -> Self::Future {
|
||||||
if req.addr.is_some() {
|
if req.addr.is_resolved() {
|
||||||
ResolverFut::Connected(Some(req))
|
// socket address(es) already resolved; return existing connection request
|
||||||
|
ResolverFut::Resolved(Some(req))
|
||||||
} else if let Ok(ip) = req.hostname().parse() {
|
} else if let Ok(ip) = req.hostname().parse() {
|
||||||
|
// request hostname is valid ip address; add address to request and return
|
||||||
let addr = SocketAddr::new(ip, req.port());
|
let addr = SocketAddr::new(ip, req.port());
|
||||||
let req = req.set_addr(Some(addr));
|
let req = req.set_addr(Some(addr));
|
||||||
ResolverFut::Connected(Some(req))
|
ResolverFut::Resolved(Some(req))
|
||||||
} else {
|
} else {
|
||||||
trace!("DNS resolver: resolving host {:?}", req.hostname());
|
trace!("DNS resolver: resolving host {:?}", req.hostname());
|
||||||
|
|
||||||
|
@ -127,7 +129,7 @@ impl<R: Host> Service<ConnectInfo<R>> for ResolverService {
|
||||||
|
|
||||||
let req = req.set_addrs(addrs);
|
let req = req.set_addrs(addrs);
|
||||||
|
|
||||||
if req.addr.is_none() {
|
if req.addr.is_unresolved() {
|
||||||
Err(ConnectError::NoRecords)
|
Err(ConnectError::NoRecords)
|
||||||
} else {
|
} else {
|
||||||
Ok(req)
|
Ok(req)
|
||||||
|
@ -140,8 +142,9 @@ impl<R: Host> Service<ConnectInfo<R>> for ResolverService {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Future for resolver service.
|
/// Future for resolver service.
|
||||||
|
#[doc(hidden)]
|
||||||
pub enum ResolverFut<R: Host> {
|
pub enum ResolverFut<R: Host> {
|
||||||
Connected(Option<ConnectInfo<R>>),
|
Resolved(Option<ConnectInfo<R>>),
|
||||||
LookUp(
|
LookUp(
|
||||||
JoinHandle<io::Result<IntoIter<SocketAddr>>>,
|
JoinHandle<io::Result<IntoIter<SocketAddr>>>,
|
||||||
Option<ConnectInfo<R>>,
|
Option<ConnectInfo<R>>,
|
||||||
|
@ -154,7 +157,7 @@ impl<R: Host> Future for ResolverFut<R> {
|
||||||
|
|
||||||
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
||||||
match self.get_mut() {
|
match self.get_mut() {
|
||||||
Self::Connected(conn) => Poll::Ready(Ok(conn
|
Self::Resolved(conn) => Poll::Ready(Ok(conn
|
||||||
.take()
|
.take()
|
||||||
.expect("ResolverFuture polled after finished"))),
|
.expect("ResolverFuture polled after finished"))),
|
||||||
|
|
||||||
|
@ -185,7 +188,7 @@ impl<R: Host> Future for ResolverFut<R> {
|
||||||
req.addrs()
|
req.addrs()
|
||||||
);
|
);
|
||||||
|
|
||||||
if req.addr.is_none() {
|
if req.addr.is_unresolved() {
|
||||||
Poll::Ready(Err(ConnectError::NoRecords))
|
Poll::Ready(Err(ConnectError::NoRecords))
|
||||||
} else {
|
} else {
|
||||||
Poll::Ready(Ok(req))
|
Poll::Ready(Ok(req))
|
||||||
|
|
|
@ -90,7 +90,7 @@ impl<R: Host> TcpConnectorFut<R> {
|
||||||
local_addr: Option<IpAddr>,
|
local_addr: Option<IpAddr>,
|
||||||
addr: ConnectAddrs,
|
addr: ConnectAddrs,
|
||||||
) -> TcpConnectorFut<R> {
|
) -> TcpConnectorFut<R> {
|
||||||
if addr.is_none() {
|
if addr.is_unresolved() {
|
||||||
error!("TCP connector: unresolved connection address");
|
error!("TCP connector: unresolved connection address");
|
||||||
return TcpConnectorFut::Error(Some(ConnectError::Unresolved));
|
return TcpConnectorFut::Error(Some(ConnectError::Unresolved));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue