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

Improve mosquitto client C++ wrapper to support more MQTT v5 features. #3019

Open
wants to merge 2 commits into
base: fixes
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions include/mosquitto.h
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,8 @@ libmosq_EXPORT int mosquitto_connect_bind_v5(struct mosquitto *mosq, const char
*/
libmosq_EXPORT int mosquitto_connect_async(struct mosquitto *mosq, const char *host, int port, int keepalive);

libmosq_EXPORT int mosquitto_connect_async_v5(struct mosquitto *mosq, const char *host, int port, int keepalive, const mosquitto_property *properties);

/*
* Function: mosquitto_connect_bind_async
*
Expand Down Expand Up @@ -673,6 +675,8 @@ libmosq_EXPORT int mosquitto_connect_async(struct mosquitto *mosq, const char *h
*/
libmosq_EXPORT int mosquitto_connect_bind_async(struct mosquitto *mosq, const char *host, int port, int keepalive, const char *bind_address);

libmosq_EXPORT int mosquitto_connect_bind_async_v5(struct mosquitto *mosq, const char *host, int port, int keepalive, const char *bind_address, const mosquitto_property *properties);

/*
* Function: mosquitto_connect_srv
*
Expand Down
30 changes: 30 additions & 0 deletions lib/connect.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ int mosquitto_connect_async(struct mosquitto *mosq, const char *host, int port,
return mosquitto_connect_bind_async(mosq, host, port, keepalive, NULL);
}

int mosquitto_connect_async_v5(struct mosquitto *mosq, const char *host, int port, int keepalive, const mosquitto_property *properties)
{
return mosquitto_connect_bind_async_v5(mosq, host, port, keepalive, NULL, properties);
}

int mosquitto_connect_bind_async(struct mosquitto *mosq, const char *host, int port, int keepalive, const char *bind_address)
{
Expand All @@ -142,6 +146,32 @@ int mosquitto_connect_bind_async(struct mosquitto *mosq, const char *host, int p
return mosquitto__reconnect(mosq, false);
}

int mosquitto_connect_bind_async_v5(struct mosquitto *mosq, const char *host, int port, int keepalive, const char *bind_address, const mosquitto_property *properties)
{
int rc;

if(bind_address){
rc = mosquitto_string_option(mosq, MOSQ_OPT_BIND_ADDRESS, bind_address);
if(rc) return rc;
}

mosquitto_property_free_all(&mosq->connect_properties);
if(properties){
rc = mosquitto_property_check_all(CMD_CONNECT, properties);
if(rc) return rc;

rc = mosquitto_property_copy_all(&mosq->connect_properties, properties);
if(rc) return rc;
mosq->connect_properties->client_generated = true;
}

rc = mosquitto__connect_init(mosq, host, port, keepalive);
if(rc) return rc;

mosquitto__set_state(mosq, mosq_cs_new);

return mosquitto__reconnect(mosq, false);
}

int mosquitto_reconnect_async(struct mosquitto *mosq)
{
Expand Down
Loading