Skip to content
Snippets Groups Projects
Commit c85e7359 authored by Rob Swindell's avatar Rob Swindell :speech_balloon:
Browse files

Report (via exception) more potential failures in MQTT constructor

parent 353530d9
No related branches found
No related tags found
1 merge request!463MRC mods by Codefenix (2024-10-20)
......@@ -707,13 +707,23 @@ static JSBool js_mqtt_constructor(JSContext* cx, uintN argc, jsval *arglist)
p->cfg = scfg->mqtt;
p->handle = mosquitto_new(client_id, /* clean_session: */true, /* userdata: */p);
free(client_id);
if(p->handle == NULL) {
JS_ReportError(cx, "mosquitto_new failure (errno=%d)", errno);
free(p);
return JS_FALSE;
}
if(!JS_SetPrivate(cx, obj, p)) {
JS_ReportError(cx,"JS_SetPrivate failed");
free(p);
return JS_FALSE;
}
mosquitto_message_callback_set(p->handle, mqtt_message_received);
mosquitto_loop_start(p->handle);
int result = mosquitto_loop_start(p->handle);
if(result != MOSQ_ERR_SUCCESS) {
JS_ReportError(cx, "mosquitto_loop_start error %d", result);
free(p);
return JS_FALSE;
}
#ifdef BUILD_JSDOCS
js_DescribeSyncObject(cx,obj,"Class used for MQTT communications",320);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment