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

TCP: Typestate client and server sockets #63

Open
chrysn opened this issue Nov 10, 2021 · 1 comment
Open

TCP: Typestate client and server sockets #63

chrysn opened this issue Nov 10, 2021 · 1 comment

Comments

@chrysn
Copy link
Contributor

chrysn commented Nov 10, 2021

For TCP, there are two kinds of sockets, those bound (on which accept makes sense), and those connected or accepted (on which read/write makes sense). These are the same type in POSIX systems, but completely different eg. in RIOT.

This is similar to #33 in methods, but different in goals (#33 is about when what can be called on the same sockets; feel free to close as duplicate if you disagree).

I suggest that the Socket associated type of TcpClientStack be split into a ConnectionSocket and a ListeningSocket, which can still be the same types on POSIX-style systems but distinct on others. (If #33 is followed, a ConnectionSocket would then be further split into its unconnected and its connected version, and the listening into its unbound, bound and listening versions).

Alternatively, sockets on such platforms need to be union-typed (enum Socket { Unspecified, ConnectionSocket(sock_t), ListeningSocket(sock_listener_t) }), and always check on runtime whether the right kind is used, which feels not very idiomatic.

@chrysn
Copy link
Contributor Author

chrysn commented Aug 15, 2022

Some of this is now implemented in the TcpConnect API introduced in embedded-nal-async 0.2: Rather than having sockets that mutate through the connection process, the connect() method returns a future whose result is a connected socket at the type level.

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

1 participant