Skip to content
This repository has been archived by the owner on May 1, 2021. It is now read-only.

Commit

Permalink
tcp: simplify logic
Browse files Browse the repository at this point in the history
Signed-off-by: Marc-Antoine Perennou <Marc-Antoine@Perennou.com>
  • Loading branch information
Keruspe committed Jan 11, 2021
1 parent ce63417 commit 1e625b9
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,8 @@ pub fn unix<P: AsRef<Path>>(path: P) -> io::Result<UnixStream> {
/// # std::io::Result::Ok(())
/// ```
pub fn tcp<A: Into<SocketAddr>>(addr: A) -> io::Result<TcpStream> {
let addr: SockAddr = addr.into().into();
let domain = if addr.as_socket().map_or(false, |addr| addr.is_ipv6()) {
Domain::IPV6
} else {
Domain::IPV4
};
let socket = connect(addr, domain, Some(Protocol::TCP))?;
let addr = addr.into();
let domain = Domain::for_address(addr);
let socket = connect(addr.into(), domain, Some(Protocol::TCP))?;
Ok(socket.into())
}

0 comments on commit 1e625b9

Please sign in to comment.