Skip to content

Support for asynchronous TCP connections #10

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
ryan-summers opened this issue Aug 26, 2020 · 1 comment · Fixed by #30
Closed

Support for asynchronous TCP connections #10

ryan-summers opened this issue Aug 26, 2020 · 1 comment · Fixed by #30

Comments

@ryan-summers
Copy link
Member

ryan-summers commented Aug 26, 2020

The current TcpStack trait doesn't facilitate well for a connect() operation that cannot be completed in a blocking manner. For example, a socket may have called connect(), but is_connected() may return false because the TCP handshake has not completed.

As such, it's required that an application repeatedly call connect() on a socket whenever is_connected() returns false to ensure that an active connection is being made. A single call to connect() may fail due to TCP state mismatch and other related problems within the network stack (see smoltcp-rs/smoltcp#367).

If the network stack isn't implemented to support repeatedly calling connect() on a socket that may already be connecting (but not yet connected), this can have unexpected consequences.

Is it possible for us to extend the TcpStack trait to either:

  1. include an is_connecting() API
  2. Modify the is_connected() API to return an enum indicating the state of the TCP connection (e.g. connecting, disconnected, or connected)
  3. Have connect() return a non-exhaustive error enumeration that allows us to specify if a socket is already in the connecting process

I'm curious to hear some other thoughts on this as well. I'm looking to use these traits for an embedded MQTT client library that's targeting multiple network stacks (e.g. an external "hardware" network stack on a W5500 and a smoltcp network stack for a different device).

I've tried to describe the problem I'm having in an issue for minimq, which relies on a TCP network stack, so there's further context attached there.

@ryan-summers ryan-summers changed the title Support for asyncrhonous TCP connections Support for asynchronous TCP connections Aug 26, 2020
@ryan-summers
Copy link
Member Author

ryan-summers commented Sep 4, 2020

Perhaps the best approach to dealing with this is instead to return an error if the connect() method fails and then allow connect() to be a blocking operation. See #18

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

Successfully merging a pull request may close this issue.

1 participant