Skip to content

Conversation

samvrlewis
Copy link
Contributor

Moves to try all resolved addresses from the user specified host name,
rather than just the first one returned. This makes the console behave
in line with the old console, which used Python's
socket.create_connection
(https://docs.python.org/3/library/socket.html#socket.create_connection)
under the covers to connect to the TCP socket.

Moves to try all resolved addresses from the user specified host name,
rather than just the first one returned. This makes the console behave
in line with the old console, which used Python's
`socket.create_connection`
(https://docs.python.org/3/library/socket.html#socket.create_connection)
under the covers to connect to the TCP socket.
@samvrlewis samvrlewis requested a review from a team December 13, 2021 01:01
if let Some(s) = socket.next() {
Ok(s)
} else {
Err(anyhow!("{}", TCP_CONNECTION_PARSING_FAILURE))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this line will have ever been triggered, as it looks like to_socket_addr will return an error both if the name can't be resolved to an address or if it can't be parsed - so I've removed this error for now.

fn open_connection(&self) -> io::Result<TcpStream> {
let addresses = self.name.to_socket_addrs()?;

let mut errors = vec![];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This errors vec is not being used anywhere, maybe just log the errors instead? Or you could maybe return them instead of the the last error you have at the bottom

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, good catch - was meaning to add the errors to the returned error if no connection worked, which I've done now.

@samvrlewis samvrlewis merged commit 8f03ef4 into main Dec 13, 2021
@samvrlewis samvrlewis deleted the slewis/cpp-470-try-all-resolved-addresses branch December 13, 2021 21:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants