Skip to content
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

add connection mode for udp sockets (work in progress) #6

Closed
wants to merge 2 commits into from

Conversation

little-dude
Copy link
Contributor

Hi,

This PR adds a connection mode for UDP sockets, which correspond to std::net::UdpSocket::connect().

This behavior is also described in 2008 POSIX standard.

UDP is a connection-less protocol, but Unix sockets offer a `connect`
function that allow the socket to send/receive datagrams to/from a
given remote endpoint.

See POSIX.1‐2008:
http://pubs.opengroup.org/onlinepubs/9699919799/functions/connect.html

The behavior for connection-less sockets is described as:

>  If the initiating socket is not connection-mode, then connect() shall
>  set the socket's peer address, and no connection is made. For
>  SOCK_DGRAM sockets, the peer address identifies where all datagrams
>  are sent on subsequent send() functions, and limits the remote sender
>  for subsequent recv() functions. If the sa_family member of address
>  is AF_UNSPEC, the socket's peer address shall be reset. Note that
>  despite no connection being made, the term ``connected'' is used to
>  describe a connectionless-mode socket for which a peer address has
>  been set.

This commit implements this behavior for UDP sockets in smoltcp.
@little-dude little-dude changed the title add connection mode for udp sockets add connection mode for udp sockets (work in progress) Feb 9, 2017
@little-dude
Copy link
Contributor Author

This needs tests obviously, but I'm opening the PR to get early feedback.

@whitequark
Copy link
Contributor

This PR adds a connection mode for UDP sockets, which correspond to std::net::UdpSocket::connect().

This behavior is also described in 2008 POSIX standard.

Note that smoltcp, by design, makes no effort to conform to POSIX or behave like std::net. In particular the TCP sockets are nothing like TcpListener/TcpStream; that is the job of a higher-level abstraction to present them like that. They are rather like TCBs (transmission control blocks) from RFC 793.

Anyway. I am partial to the idea behind this socket, but I strongly dislike the added branching in the API. Not sure what to make of it.

@little-dude
Copy link
Contributor Author

I see, thanks for the explanation. I think in this specific case, I can indeed provide this abstraction at a higher level (for the context I'm trying to use smoltcp as the network stack for redox).

@whitequark
Copy link
Contributor

@little-dude It's virtually certain that you will need to provide a higher-level abstraction, at least for TCP and to account for blocking. Therefore it seems alright to also do that for UDP sockets.

By the way, I am rather happy about the use of smoltcp in redox--the existing redox network stack wasn't exactly inspiring...

@whitequark whitequark closed this Feb 10, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants