-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Tweaks to std::net address types #923
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
Changes from 1 commit
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 |
|---|---|---|
|
|
@@ -1370,6 +1370,91 @@ The contents of `std::io::net` submodules `tcp`, `udp`, `ip` and | |
| the other modules are being moved or removed and are described | ||
| elsewhere. | ||
|
|
||
| #### InetAddr | ||
|
|
||
| The composition of an `IpAddr` and a port. It has the following interface: | ||
|
|
||
| ```rust | ||
| impl InetAddr { | ||
|
Member
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. Just to clarify, did this purposefully omit the 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. I don't know what arguments a 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. Oops, ignore that. I thought you were talking about IpAddr. |
||
| /// Returns a new InetAddr composed of an unspecified v4 IP and a 0 | ||
| /// port | ||
| fn any_v4() -> InetAddr; | ||
|
|
||
| /// Returns a new InetAddr composed of an unspecified v6 IP and a 0 | ||
| /// port | ||
| fn any_v6() -> InetAddr; | ||
|
|
||
| fn ip(&self) -> IpAddr; | ||
| fn port(&self) -> u16; | ||
|
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. Note that That said: I'm not sure such a protocol exists. |
||
|
|
||
| /// Returns true if the IpAddr is unspecified and port == 0 | ||
| fn is_unspecified(&self) -> bool; | ||
| } | ||
| ``` | ||
|
|
||
| #### IpAddr | ||
|
|
||
| Represents an IP address. It has the following interface: | ||
|
|
||
| ```rust | ||
| impl IpAddr { | ||
| fn new_v4(a: u8, b: u8, c: u8, d: u8) -> IpAddr; | ||
|
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. Is there a reason there isn't a new that accepts an 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. There is a |
||
| fn any_v4() -> IpAddr; | ||
|
|
||
| fn new_v6(a: u16, b: u16, c: u16, d: u16, e: u16, f: u16, g: u16, h: u16) -> IpAddr; | ||
| fn any_v6() -> IpAddr; | ||
|
|
||
| // The following functions proxy to the versioned IP address value | ||
| fn is_unspecified(&self) -> bool; | ||
| fn is_loopback(&self) -> bool; | ||
| fn is_global(&self) -> bool; | ||
| fn is_private(&self) -> bool; | ||
| fn is_multicast(&self) -> bool; | ||
| } | ||
| ``` | ||
|
|
||
| #### Ipv4Addr | ||
|
|
||
| Represents a version 4 IP address. It has the following interface: | ||
|
|
||
| ```rust | ||
| impl Ipv4Addr { | ||
| fn new(a: u8, b: u8, c: u8, d: u8) -> Ipv4Addr; | ||
| fn any() -> Ipv4Addr; | ||
| fn octets(&self) -> [u8; 4]; | ||
| fn is_unspecified(&self) -> bool; | ||
| fn is_loopback(&self) -> bool; | ||
| fn is_private(&self) -> bool; | ||
| fn is_link_local(&self) -> bool; | ||
| fn is_global(&self) -> bool; | ||
| fn is_multicast(&self) -> bool; | ||
| fn to_ipv6_compatible(&self) -> Ipv6Addr; | ||
| fn to_ipv6_mapped(&self) -> Ipv6Addr; | ||
| } | ||
| ``` | ||
|
|
||
| #### Ipv6Addr | ||
|
|
||
| Represents a version 6 IP address. It has the following interface: | ||
|
|
||
| ```rust | ||
| impl Ipv6Addr { | ||
| fn new(a: u16, b: u16, c: u16, d: u16, e: u16, f: u16, g: u16, h: u16) -> Ipv6Addr; | ||
|
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. Is there a reason 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. Only that this made it easier for users to switch from the old enum-based 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. ... and the appropriate changes for |
||
| fn any() -> Ipv6Addr; | ||
| fn segments(&self) -> [u16; 8] | ||
| fn is_unspecified(&self) -> bool; | ||
| fn is_loopback(&self) -> bool; | ||
| fn is_global(&self) -> bool; | ||
| fn is_unique_local(&self) -> bool; | ||
| fn is_unicast_link_local(&self) -> bool; | ||
| fn is_unicast_site_local(&self) -> bool; | ||
| fn is_unicast_global(&self) -> bool; | ||
| fn multicast_scope(&self) -> Option<Ipv6MulticastScope>; | ||
| fn is_multicast(&self) -> bool; | ||
| fn to_ipv4(&self) -> Option<Ipv4Addr>; | ||
|
Member
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. If we're going to spell this out in the RFC I think we may want to hold off on some of these methods. These are pretty ambitious and a more conservative design would only have
Member
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. (same for the v4 addr) 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 would keep is_unspecific, to_ipv4 and maybe is_multicast, but +1 for marking the others as experimental or removing them, at least until more people can read through the IP RFCs and validate the code. |
||
| } | ||
| ``` | ||
|
|
||
| #### TCP | ||
| [TCP]: #tcp | ||
|
|
||
|
|
@@ -1380,9 +1465,9 @@ following interface: | |
| // TcpStream, which contains both a reader and a writer | ||
|
|
||
| impl TcpStream { | ||
| fn connect<A: ToSocketAddrs>(addr: &A) -> io::Result<TcpStream>; | ||
| fn peer_addr(&self) -> io::Result<SocketAddr>; | ||
| fn socket_addr(&self) -> io::Result<SocketAddr>; | ||
| fn connect<A: ToInetAddrs>(addr: &A) -> io::Result<TcpStream>; | ||
| fn peer_addr(&self) -> io::Result<InetAddr>; | ||
| fn inet_addr(&self) -> io::Result<InetAddr>; | ||
|
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. Perhaps we should take this opportunity to rename |
||
| fn shutdown(&self, how: Shutdown) -> io::Result<()>; | ||
| fn duplicate(&self) -> io::Result<TcpStream>; | ||
| } | ||
|
|
@@ -1420,10 +1505,10 @@ into the `TcpListener` structure. Specifically, this will be the resulting API: | |
|
|
||
| ```rust | ||
| impl TcpListener { | ||
| fn bind<A: ToSocketAddrs>(addr: &A) -> io::Result<TcpListener>; | ||
| fn socket_addr(&self) -> io::Result<SocketAddr>; | ||
| fn bind<A: ToInetAddrs>(addr: &A) -> io::Result<TcpListener>; | ||
| fn inet_addr(&self) -> io::Result<InetAddr>; | ||
| fn duplicate(&self) -> io::Result<TcpListener>; | ||
| fn accept(&self) -> io::Result<(TcpStream, SocketAddr)>; | ||
| fn accept(&self) -> io::Result<(TcpStream, InetAddr)>; | ||
| fn incoming(&self) -> Incoming; | ||
| } | ||
|
|
||
|
|
@@ -1447,10 +1532,10 @@ Some major changes from today's API include: | |
| date with a more robust interface. | ||
| * The `set_timeout` functionality has also been removed in favor of returning at | ||
| a later date in a more robust fashion with `select`. | ||
| * The `accept` function no longer takes `&mut self` and returns `SocketAddr`. | ||
| * The `accept` function no longer takes `&mut self` and returns `InetAddr`. | ||
| The change in mutability is done to express that multiple `accept` calls can | ||
| happen concurrently. | ||
| * For convenience the iterator does not yield the `SocketAddr` from `accept`. | ||
| * For convenience the iterator does not yield the `InetAddr` from `accept`. | ||
|
|
||
| The `TcpListener` type will also adhere to `Send` and `Sync`. | ||
|
|
||
|
|
@@ -1462,10 +1547,10 @@ infrastructure will: | |
|
|
||
| ```rust | ||
| impl UdpSocket { | ||
| fn bind<A: ToSocketAddrs>(addr: &A) -> io::Result<UdpSocket>; | ||
| fn recv_from(&self, buf: &mut [u8]) -> io::Result<(usize, SocketAddr)>; | ||
| fn send_to<A: ToSocketAddrs>(&self, buf: &[u8], addr: &A) -> io::Result<usize>; | ||
| fn socket_addr(&self) -> io::Result<SocketAddr>; | ||
| fn bind<A: ToInetAddrs>(addr: &A) -> io::Result<UdpSocket>; | ||
| fn recv_from(&self, buf: &mut [u8]) -> io::Result<(usize, InetAddr)>; | ||
| fn send_to<A: ToInetAddrs>(&self, buf: &[u8], addr: &A) -> io::Result<usize>; | ||
| fn inet_addr(&self) -> io::Result<InetAddr>; | ||
| fn duplicate(&self) -> io::Result<UdpSocket>; | ||
| } | ||
|
|
||
|
|
@@ -1514,7 +1599,7 @@ For the current `addrinfo` module: | |
|
|
||
| For the current `ip` module: | ||
|
|
||
| * The `ToSocketAddr` trait should become `ToSocketAddrs` | ||
| * The `ToInetAddr` trait should become `ToInetAddrs` | ||
|
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. There doesn't seem to be an existing Assuming that is the case, might also want to mention how |
||
| * The default `to_socket_addr_all` method should be removed. | ||
|
|
||
| The actual address structures could use some scrutiny, but any | ||
|
|
||
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 don't like how similar IpAddr and InetAddr are, and I think it's not obvious which one is which, just from looking at the names.
Could we choose either Inet or Ip and have, say, InetAddr (host address) and InetSocketAddr?