Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

joboet
Copy link
Member

@joboet joboet commented Sep 14, 2025

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.

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Sep 14, 2025
@rustbot
Copy link
Collaborator

rustbot commented Sep 14, 2025

r? @tgross35

rustbot has assigned @tgross35.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rust-log-analyzer

This comment has been minimized.

@joboet joboet force-pushed the simplify-lookup-host branch from cd0ffd9 to 3f42540 Compare September 14, 2025 18:43
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@joboet joboet force-pushed the simplify-lookup-host branch from ca886bc to 61d02fa Compare September 15, 2025 11:16
Copy link
Contributor

@tgross35 tgross35 left a 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

View changes since this review

|

error: aborting due to 2 previous errors
error: aborting due to 1 previous error
Copy link
Contributor

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.

@joboet joboet force-pushed the simplify-lookup-host branch from 61d02fa to 09d3120 Compare September 19, 2025 09:31
@joboet
Copy link
Member Author

joboet commented Sep 19, 2025

@bors r=@tgross35

@bors
Copy link
Collaborator

bors commented Sep 19, 2025

📌 Commit 09d3120 has been approved by tgross35

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 19, 2025
Zalathar added a commit to Zalathar/rust that referenced this pull request Sep 19, 2025
…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.
bors added a commit that referenced this pull request Sep 19, 2025
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
@bors bors merged commit ff8d63a into rust-lang:master Sep 19, 2025
10 checks passed
@rustbot rustbot added this to the 1.92.0 milestone Sep 19, 2025
rust-timer added a commit that referenced this pull request Sep 19, 2025
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.
github-actions bot pushed a commit to rust-lang/miri that referenced this pull request Sep 20, 2025
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
Muscraft pushed a commit to Muscraft/rust that referenced this pull request Sep 24, 2025
…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.
Muscraft pushed a commit to Muscraft/rust that referenced this pull request Sep 24, 2025
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
Copy link
Contributor

@a1phyr a1phyr left a 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!

View changes since this review

Comment on lines +510 to +513
Err(io::Error::new(
io::ErrorKind::Uncategorized,
NonIpSockAddr { host: format!("{host}:{port}") },
))
Copy link
Contributor

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?

Copy link
Member Author

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants