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 asynchronous connection method for MQTT v5 #2345

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

JacobsJohan
Copy link

@JacobsJohan JacobsJohan commented Oct 18, 2021

Description

It is currently only possible to make a blocking MQTT v5 connection to a broker by using mosquitto_connect_bind_v5. The non-blocking alternative mosquitto_connect_bind_async can only be used for MQTT v3, because it does not allow passing MQTT v5 properties.

This pull request adds 2 new API functions to the mosquitto library:

  • mosquitto_connect_bind_async_v5: This function will create a non-blocking socket connection to the MQTT broker. It will return with MOSQ_ERR_CONN_INPROGRESS when the socket connection was created, but the connection is still in progress. The socket can be added to an event loop to check when it becomes ready for writing.
  • mosquitto_send_connect: This function must be called once the connection is ready for writing to send the actual MQTT CONNECT message.

Started from this issue: #1835

Checklist

Signed-off-by: Johan Jacobs [email protected]

Thank you for contributing your time to the Mosquitto project!

Before you go any further, please note that we cannot accept contributions if
you haven't signed the Eclipse Contributor Agreement.
If you aren't able to do that, or just don't want to, please describe your bug
fix/feature change in an issue. For simple bug fixes it is can be just as easy
for us to be told about the problem and then go fix it directly.

Then please check the following list of things we ask for in your pull request:

  • Have you signed the Eclipse Contributor Agreement, using the same email address as you used in your commits?
  • Do each of your commits have a "Signed-off-by" line, with the correct email address? Use "git commit -s" to generate this line for you.
  • If you are contributing a new feature, is your work based off the develop branch?
  • If you are contributing a bugfix, is your work based off the fixes branch?
  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you successfully run make test with your changes locally?

@JacobsJohan
Copy link
Author

The only difference between the existing and new code is a change of return value from MOSQ_ERR_CONN_PENDING to MOSQ_ERR_CONN_INPROGRESS when the connect function returns with errno set to EINPROGRESS. This is needed because the return value needs to be larger than 0 and MOSQ_ERR_CONN_PENDING = -1.

For some reason, the connection setup continues when rc < 0 and only stops when rc > 0. So an MQTT connect message is always sent to the broker, even if the socket is not yet writable. This does not make much sense to me, because the connect message will never arrive in this situation.

Besides this, only new code has been added to extend the asynchronous connect to MQTT v5, so it should not break any existing code.

@ahoarau
Copy link

ahoarau commented Dec 23, 2021

This is a good feature, I would also vote for merging this !

@JacobsJohan
Copy link
Author

What would be the next steps to get this integrated @ralight ? Is there anything else I can do?

@JacobsJohan JacobsJohan force-pushed the feature_connect_async_v5 branch 2 times, most recently from 49b2a65 to 0eb5149 Compare January 27, 2022 09:00
@dvsmd
Copy link

dvsmd commented Oct 12, 2022

This is a good addition. Can this please be merged?

@Project579
Copy link

FYI, the C++ methods for this functionality are missing, they should be added before merging.

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 this pull request may close these issues.

None yet

4 participants