mirror of
https://github.com/fafhrd91/actix-net
synced 2025-02-17 14:43:31 +01:00
make port required
This commit is contained in:
parent
3a133e3974
commit
ff914f79fc
@ -43,23 +43,15 @@ impl From<ResolverError> for ConnectorError {
|
|||||||
#[derive(Eq, PartialEq, Debug)]
|
#[derive(Eq, PartialEq, Debug)]
|
||||||
pub struct Connect {
|
pub struct Connect {
|
||||||
pub host: String,
|
pub host: String,
|
||||||
pub port: Option<u16>,
|
pub port: u16,
|
||||||
pub timeout: Duration,
|
pub timeout: Duration,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Connect {
|
impl Connect {
|
||||||
pub fn host<T: AsRef<str>>(host: T) -> Connect {
|
pub fn new<T: AsRef<str>>(host: T, port: u16) -> Connect {
|
||||||
Connect {
|
Connect {
|
||||||
|
port,
|
||||||
host: host.as_ref().to_owned(),
|
host: host.as_ref().to_owned(),
|
||||||
port: None,
|
|
||||||
timeout: Duration::from_secs(1),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn host_and_port<T: AsRef<str>>(host: T, port: u16) -> Connect {
|
|
||||||
Connect {
|
|
||||||
host: host.as_ref().to_owned(),
|
|
||||||
port: Some(port),
|
|
||||||
timeout: Duration::from_secs(1),
|
timeout: Duration::from_secs(1),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -171,10 +163,21 @@ impl Future for ConnectorFuture {
|
|||||||
return fut.poll();
|
return fut.poll();
|
||||||
}
|
}
|
||||||
match self.fut.poll().map_err(ConnectorError::from)? {
|
match self.fut.poll().map_err(ConnectorError::from)? {
|
||||||
Async::Ready((req, _, addrs)) => {
|
Async::Ready((req, _, mut addrs)) => {
|
||||||
if addrs.is_empty() {
|
if addrs.is_empty() {
|
||||||
Err(ConnectorError::NoRecords)
|
Err(ConnectorError::NoRecords)
|
||||||
} else {
|
} else {
|
||||||
|
for addr in &mut addrs {
|
||||||
|
match addr {
|
||||||
|
SocketAddr::V4(ref mut addr) if addr.port() == 0 => {
|
||||||
|
addr.set_port(req.port)
|
||||||
|
}
|
||||||
|
SocketAddr::V6(ref mut addr) if addr.port() == 0 => {
|
||||||
|
addr.set_port(req.port)
|
||||||
|
}
|
||||||
|
_ => (),
|
||||||
|
}
|
||||||
|
}
|
||||||
self.fut2 = Some(TcpConnector::new(req, addrs));
|
self.fut2 = Some(TcpConnector::new(req, addrs));
|
||||||
self.poll()
|
self.poll()
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user