1
0
mirror of https://github.com/fafhrd91/actix-net synced 2024-11-27 19:12:56 +01:00

Fix error handling for single address

This commit is contained in:
Nikolay Kim 2019-03-15 11:37:51 -07:00
parent b290273e81
commit 27c28d6597
6 changed files with 23 additions and 4 deletions

View File

@ -1,5 +1,12 @@
# Changes
## [0.1.1] - 2019-03-15
### Fixed
* Fix error handling for single address
## [0.1.0] - 2019-03-14
* Refactor resolver and connector services

View File

@ -1,6 +1,6 @@
[package]
name = "actix-connect"
version = "0.1.0"
version = "0.1.1"
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
description = "Actix Connector - tcp connector service"
keywords = ["network", "framework", "async", "futures"]

View File

@ -140,7 +140,7 @@ impl<T: Address> Future for ConnectorResponse<T> {
self.req.as_ref().unwrap().host(),
self.port,
);
if self.addrs.as_ref().unwrap().is_empty() {
if self.addrs.is_none() || self.addrs.as_ref().unwrap().is_empty() {
return Err(err.into());
}
}

View File

@ -153,7 +153,9 @@ impl<T: Address> Future for ResolverFuture<T> {
req.host(),
addrs
);
if addrs.len() == 1 {
if addrs.is_empty() {
Err(ConnectError::NoRecords)
} else if addrs.len() == 1 {
req.addr = Some(either::Either::Left(addrs.pop_front().unwrap()));
Ok(Async::Ready(req))
} else {

View File

@ -26,6 +26,7 @@ fn port(scheme: Option<&str>) -> Option<u16> {
"wss" => Some(443),
"amqp" => Some(5672),
"amqps" => Some(5671),
"sb" => Some(5671),
"mqtt" => Some(1883),
"mqtts" => Some(8883),
_ => None,

View File

@ -43,13 +43,22 @@ fn test_static_str() {
))
.unwrap();
let mut conn = srv
.block_on(lazy(|| Ok::<_, ()>(actix_connect::new_connector(resolver))))
.block_on(lazy(|| {
Ok::<_, ()>(actix_connect::new_connector(resolver.clone()))
}))
.unwrap();
let con = srv
.block_on(conn.call(Connect::with("10", srv.addr())))
.unwrap();
assert_eq!(con.peer_addr().unwrap(), srv.addr());
let connect = Connect::new(srv.host().to_owned());
let mut conn = srv
.block_on(lazy(|| Ok::<_, ()>(actix_connect::new_connector(resolver))))
.unwrap();
let con = srv.block_on(conn.call(connect));
assert!(con.is_err());
}
#[test]