Skip to content

Differents type signature (address, port) for TCP and UDP connection #18269

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

Closed
rach opened this issue Oct 23, 2014 · 5 comments
Closed

Differents type signature (address, port) for TCP and UDP connection #18269

rach opened this issue Oct 23, 2014 · 5 comments

Comments

@rach
Copy link

rach commented Oct 23, 2014

Hi,

The closest ticket that I could find was #14755 but it seems closed due to inactivity.
There is maybe a reason but I found a bit odd that TCP connection is done via ( &str , u16 ) and UDP via std::io::net::ip::SocketAddr . Looking at the history it seem like TCP changed to step away from SocketAddr.

TCP:

pub fn bind(addr: &str, port: u16) -> IoResult<TcpListener> {

UDP:

pub fn bind(addr: SocketAddr) -> IoResult<UdpSocket> {

Thanks.

@huonw huonw added the A-libs label Oct 24, 2014
@rach
Copy link
Author

rach commented Oct 24, 2014

By the way, I'm ok to submit a PR if somebody can tell me which version should be implemented (if it's not made on purpose)

@alexcrichton
Copy link
Member

The vague reasoning behind this was that by taking &str for the IP for a TCP socket we can handle hostnames as well as IPs. For UDP, however, there's no need to handle a hostname (b/c you're only binding a socket).

That's not a very strong argument, however, and these likely need to be redesigned to be unified.

@zonyitoo
Copy link

Another possible solution is to extend SocketAddr to something like

pub enum AddrType {
    HostNameAddress(String),
    IpAddress(IpAddr),
}

pub struct SocketAddr {
    pub addr: AddrType,
    pub port: Port,
}

just for illustration.

@barosl
Copy link
Contributor

barosl commented Nov 11, 2014

I think this issue can be closed now. Both bind() functions now accept the same arguments, and AddrType suggested by @zonyitoo was implemented using the std::io::net::ip::ToSocketAddr trait.

@steveklabnik
Copy link
Member

Yup!

lnicola pushed a commit to lnicola/rust that referenced this issue Oct 17, 2024
…-formatting, r=flodiebold

hir-ty: change struct + enum variant constructor formatting.

before, when formatting struct constructor for `struct S(usize, usize)` it would format as:

    extern "rust-call" S(usize, usize) -> S

but after this change, we'll format as:

    fn S(usize, usize) -> S

likewise the second commit, also makes this uniform for enum variants as well.

fixes rust-lang#18259
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

No branches or pull requests

6 participants