Files
MeshCore-mqtt-observer/lib/PsychicMqttClient/src/MqttClientInit.h
T
agessaman 665ece1e12 fix(mqtt): never hand back a half-initialized client or transport
esp_mqtt_client_init() succeeded without a registered event sink when
registration failed, and the WebSocket wrap returned a transport with
the unpadded SDK buffer when the padded allocation failed. Both paths
now fail cleanly instead, the IDF 4 WebSocket layout is pinned to the
validated patch level, and the connection flags esp-mqtt tasks write
become atomic.
2026-09-21 16:05:39 -07:00

18 lines
590 B
C++

#pragma once
// Initialization is incomplete until lifecycle events have a registered sink.
// The candidate has never started, so registration failure can destroy it.
template<class Handle, class Init, class Register, class Destroy>
int initializeMqttClient(Handle& target, Init init, Register register_events,
Destroy destroy, int no_memory) {
Handle candidate = init();
if (!candidate) return no_memory;
const int result = register_events(candidate);
if (result != 0) {
destroy(candidate);
return result;
}
target = candidate;
return 0;
}