-
-
Notifications
You must be signed in to change notification settings - Fork 15k
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -499,35 +499,16 @@ impl fmt::Display for NonIpSockAddr { | |
|
|
||
| pub struct LookupHost(!); | ||
|
|
||
| impl LookupHost { | ||
| fn new(host: String) -> io::Result<LookupHost> { | ||
| Err(io::Error::new(io::ErrorKind::Uncategorized, NonIpSockAddr { host })) | ||
| } | ||
|
|
||
| pub fn port(&self) -> u16 { | ||
| self.0 | ||
| } | ||
| } | ||
|
|
||
| impl Iterator for LookupHost { | ||
| type Item = SocketAddr; | ||
| fn next(&mut self) -> Option<SocketAddr> { | ||
| self.0 | ||
| } | ||
| } | ||
|
|
||
| impl TryFrom<&str> for LookupHost { | ||
| type Error = io::Error; | ||
|
|
||
| fn try_from(v: &str) -> io::Result<LookupHost> { | ||
| LookupHost::new(v.to_owned()) | ||
| } | ||
| } | ||
|
|
||
| impl<'a> TryFrom<(&'a str, u16)> for LookupHost { | ||
| type Error = io::Error; | ||
|
|
||
| fn try_from((host, port): (&'a str, u16)) -> io::Result<LookupHost> { | ||
| LookupHost::new(format!("{host}:{port}")) | ||
| } | ||
| pub fn lookup_host(host: &str, port: u16) -> io::Result<LookupHost> { | ||
| Err(io::Error::new( | ||
| io::ErrorKind::Uncategorized, | ||
| NonIpSockAddr { host: format!("{host}:{port}") }, | ||
| )) | ||
|
Comment on lines
+510
to
+513
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, the |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -45,4 +45,4 @@ pub struct GetAddress { | |
| raw: [u8; 4096], | ||
| } | ||
|
|
||
| pub use dns::LookupHost; | ||
| pub use dns::lookup_host; | ||
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 change is bogus and breaks the
x86_64-fortanix-unknown-sgxtarget (and thex86_64-unknown-linux-fortanixvmetarget, but that hasn't been upstreamed yet). If the string can't be parsed, this function needs to return aNonIpSockAddrerror.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.
How so? The
lookup_hostfunction will reconstruct the exact same string, assuming that it can be parsed as a host:port pair.Uh oh!
There was an error while loading. Please reload this page.
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.
That is the problem. Strings that can't be parsed like that need to be passed in the error type to the underlying PAL.
Uh oh!
There was an error while loading. Please reload this page.
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.
Why would you want that? No other platform supports those.
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.
From the underlying interface specification from the platform:
https://edp.fortanix.com/docs/api/fortanix_sgx_abi/struct.Usercalls.html#networking