mirror of
https://github.com/agessaman/MeshCore.git
synced 2026-10-15 11:10:12 +00:00
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.
18 lines
590 B
C++
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;
|
|
}
|