-
Notifications
You must be signed in to change notification settings - Fork 13.8k
std: simplify host lookup #146541
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
std: simplify host lookup #146541
Conversation
This comment has been minimized.
This comment has been minimized.
cd0ffd9
to
3f42540
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
ca886bc
to
61d02fa
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like another great cleanup! r=me with a squash
| | ||
|
||
error: aborting due to 2 previous errors | ||
error: aborting due to 1 previous error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it doesn't hurt anything, but it is interesting that this was the only competing implementer.
61d02fa
to
09d3120
Compare
…oss35 std: simplify host lookup The logic for splitting up a string into a hostname and port is currently duplicated across (nearly) all of the networking implementations in `sys`. Since it does not actually rely on any system internals, this PR moves it to the `ToSocketAddr` implementation for `&str`, making it easier to discover and maintain. On the other hand, the `ToSocketAddr` implementation (or rather the `resolve_socket_addr` function) contained logic to overwrite the port on the socket addresses returned by `LookupHost`, even though `LookupHost` is already aware of the port and sets the port already on Xous. This PR thus removes this logic by moving the responsibility of setting the port to the system-specific `LookupHost` implementation. As a consequence of these changes, there remains only one way of creating `LookupHost`, hence I've removed the `TryFrom` implementations in favour of a `lookup_host` function, mirroring other, public iterator-based features. And finally, I've simplified the parsing logic responsible for recognising IP addresses passed to `<(&str, u16)>::to_socket_addrs()` by using the `FromStr` impl of `IpAddr` rather than duplicating the parsing for both IP versions.
Rollup of 10 pull requests Successful merges: - #146229 (Automatically switch to lto-fat when flag RUSTFLAGS="- Zautodiff=Enable" is set) - #146484 (rustdoc-search: JavaScript optimization based on Firefox Profiler output) - #146541 (std: simplify host lookup) - #146615 (rustc_codegen_llvm: Feature Conversion Tidying) - #146638 (`rustc_next_trait_solver`: canonical out of `EvalCtxt`) - #146663 (Allow windows resource compiler to be overridden) - #146691 (std: Fix WASI implementation of `remove_dir_all`) - #146709 (stdarch subtree update) - #146738 (Fix tidy spellchecking on Windows) - #146740 (miri subtree update) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of #146541 - joboet:simplify-lookup-host, r=tgross35 std: simplify host lookup The logic for splitting up a string into a hostname and port is currently duplicated across (nearly) all of the networking implementations in `sys`. Since it does not actually rely on any system internals, this PR moves it to the `ToSocketAddr` implementation for `&str`, making it easier to discover and maintain. On the other hand, the `ToSocketAddr` implementation (or rather the `resolve_socket_addr` function) contained logic to overwrite the port on the socket addresses returned by `LookupHost`, even though `LookupHost` is already aware of the port and sets the port already on Xous. This PR thus removes this logic by moving the responsibility of setting the port to the system-specific `LookupHost` implementation. As a consequence of these changes, there remains only one way of creating `LookupHost`, hence I've removed the `TryFrom` implementations in favour of a `lookup_host` function, mirroring other, public iterator-based features. And finally, I've simplified the parsing logic responsible for recognising IP addresses passed to `<(&str, u16)>::to_socket_addrs()` by using the `FromStr` impl of `IpAddr` rather than duplicating the parsing for both IP versions.
Rollup of 10 pull requests Successful merges: - rust-lang/rust#146229 (Automatically switch to lto-fat when flag RUSTFLAGS="- Zautodiff=Enable" is set) - rust-lang/rust#146484 (rustdoc-search: JavaScript optimization based on Firefox Profiler output) - rust-lang/rust#146541 (std: simplify host lookup) - rust-lang/rust#146615 (rustc_codegen_llvm: Feature Conversion Tidying) - rust-lang/rust#146638 (`rustc_next_trait_solver`: canonical out of `EvalCtxt`) - rust-lang/rust#146663 (Allow windows resource compiler to be overridden) - rust-lang/rust#146691 (std: Fix WASI implementation of `remove_dir_all`) - rust-lang/rust#146709 (stdarch subtree update) - rust-lang/rust#146738 (Fix tidy spellchecking on Windows) - rust-lang/rust#146740 (miri subtree update) r? `@ghost` `@rustbot` modify labels: rollup
…oss35 std: simplify host lookup The logic for splitting up a string into a hostname and port is currently duplicated across (nearly) all of the networking implementations in `sys`. Since it does not actually rely on any system internals, this PR moves it to the `ToSocketAddr` implementation for `&str`, making it easier to discover and maintain. On the other hand, the `ToSocketAddr` implementation (or rather the `resolve_socket_addr` function) contained logic to overwrite the port on the socket addresses returned by `LookupHost`, even though `LookupHost` is already aware of the port and sets the port already on Xous. This PR thus removes this logic by moving the responsibility of setting the port to the system-specific `LookupHost` implementation. As a consequence of these changes, there remains only one way of creating `LookupHost`, hence I've removed the `TryFrom` implementations in favour of a `lookup_host` function, mirroring other, public iterator-based features. And finally, I've simplified the parsing logic responsible for recognising IP addresses passed to `<(&str, u16)>::to_socket_addrs()` by using the `FromStr` impl of `IpAddr` rather than duplicating the parsing for both IP versions.
Rollup of 10 pull requests Successful merges: - rust-lang#146229 (Automatically switch to lto-fat when flag RUSTFLAGS="- Zautodiff=Enable" is set) - rust-lang#146484 (rustdoc-search: JavaScript optimization based on Firefox Profiler output) - rust-lang#146541 (std: simplify host lookup) - rust-lang#146615 (rustc_codegen_llvm: Feature Conversion Tidying) - rust-lang#146638 (`rustc_next_trait_solver`: canonical out of `EvalCtxt`) - rust-lang#146663 (Allow windows resource compiler to be overridden) - rust-lang#146691 (std: Fix WASI implementation of `remove_dir_all`) - rust-lang#146709 (stdarch subtree update) - rust-lang#146738 (Fix tidy spellchecking on Windows) - rust-lang#146740 (miri subtree update) r? `@ghost` `@rustbot` modify labels: rollup
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great! Thanks a lot for this!
Err(io::Error::new( | ||
io::ErrorKind::Uncategorized, | ||
NonIpSockAddr { host: format!("{host}:{port}") }, | ||
)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I known that you've kept the old error, but shouldn't this return unsupported()
instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, the ErrorKind
should probably be Unsupported
. But we cannot replace the whole error with UNSUPPORTED_PLATFORM
as SGX uses the error to smuggle the hostname through to the socket implementation (I know, it's bad).
The logic for splitting up a string into a hostname and port is currently duplicated across (nearly) all of the networking implementations in
sys
. Since it does not actually rely on any system internals, this PR moves it to theToSocketAddr
implementation for&str
, making it easier to discover and maintain.On the other hand, the
ToSocketAddr
implementation (or rather theresolve_socket_addr
function) contained logic to overwrite the port on the socket addresses returned byLookupHost
, even thoughLookupHost
is already aware of the port and sets the port already on Xous. This PR thus removes this logic by moving the responsibility of setting the port to the system-specificLookupHost
implementation.As a consequence of these changes, there remains only one way of creating
LookupHost
, hence I've removed theTryFrom
implementations in favour of alookup_host
function, mirroring other, public iterator-based features.And finally, I've simplified the parsing logic responsible for recognising IP addresses passed to
<(&str, u16)>::to_socket_addrs()
by using theFromStr
impl ofIpAddr
rather than duplicating the parsing for both IP versions.