Skip to content
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
3 changes: 2 additions & 1 deletion c/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
or mbedTLS (`AZ_IOT_AZ_MQTT_TLS`), Schannel on Windows; WebSockets, HTTP CONNECT proxy, and
key references through an OpenSSL 3 provider. Per-client sizes are set when compiled, with or
without CMake: a footprint (`AZ_IOT_AZ_MQTT_FOOTPRINT`), separate send and receive sizes, or a
config header. See [docs/client-configuration.md](docs/client-configuration.md#az_mqtt-adapter-sizes).
config header. With `AZ_IOT_AZ_MQTT_STATIC_CLIENTS` > 0 (default 0) the adapter allocates nothing: a fixed number
of clients in static storage. See [docs/client-configuration.md](docs/client-configuration.md#az_mqtt-adapter-sizes).
- Logging for support diagnostics: rotating file sink (`az_iot_log_file_sink_open()`), lines
`<UTC ISO 8601 time> [LEVEL] [component] [thread] [file:line] message` from the built-in sinks, connection configuration,
state changes and retries at `INFO`, and a `...` marker on truncated messages.
Expand Down
13 changes: 12 additions & 1 deletion c/adapters/az_mqtt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ set(AZ_IOT_AZ_MQTT_INFLIGHT_MAX "" CACHE STRING
"az_mqtt adapter: requests in flight at once, 1-32767; MQTT 5: also the Receive Maximum advertised (empty: footprint's)")
set(AZ_IOT_AZ_MQTT_USER_PROPERTIES_MAX "" CACHE STRING
"az_mqtt adapter: MQTT 5 user properties per packet (empty: footprint's)")
set(AZ_IOT_AZ_MQTT_STATIC_CLIENTS "" CACHE STRING
"az_mqtt adapter: clients of each MQTT version in static storage, no heap; 0 or empty: allocated when created")
set(AZ_IOT_AZ_MQTT_TRANSPORT_SIZE "" CACHE STRING
"az_mqtt adapter, static clients: bytes for the transport (empty: 200 KiB on Windows, 8 KiB elsewhere)")
set(AZ_IOT_AZ_MQTT_CONNECT_STRINGS_SIZE "" CACHE STRING
"az_mqtt adapter, static clients: bytes for a connect's strings (empty: 8 KiB)")
set(AZ_IOT_AZ_MQTT_MESSAGE_STORAGE_SIZE "" CACHE STRING
"az_mqtt adapter: store of unacknowledged QoS 1/2 PUBLISH; 0: refuse clean_start false (MQTT 5: with session expiry > 0) (empty: send size + 18)")
set(AZ_IOT_AZ_MQTT_CONFIG_FILE "" CACHE STRING
"az_mqtt adapter: header with size definitions, as written in a quoted #include (empty: none)")

Expand Down Expand Up @@ -69,6 +77,8 @@ add_library(azure::iot::adapter_az_mqtt ALIAS az_iot_adapter_az_mqtt)
target_include_directories(az_iot_adapter_az_mqtt
PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/inc>
PRIVATE
${PROJECT_SOURCE_DIR}/src/core # internal/crypto.h: az_iot_crypto__wipe()
)
target_link_libraries(az_iot_adapter_az_mqtt
PUBLIC
Expand All @@ -86,7 +96,8 @@ elseif(NOT _az_mqtt_footprint STREQUAL "")
"AZ_IOT_AZ_MQTT_FOOTPRINT must be DEFAULT or CONSTRAINED (got '${AZ_IOT_AZ_MQTT_FOOTPRINT}')")
endif()
unset(_az_mqtt_footprint)
foreach(_v SEND_BUFFER_SIZE RECEIVE_BUFFER_SIZE INFLIGHT_MAX USER_PROPERTIES_MAX)
foreach(_v SEND_BUFFER_SIZE RECEIVE_BUFFER_SIZE INFLIGHT_MAX USER_PROPERTIES_MAX STATIC_CLIENTS
TRANSPORT_SIZE CONNECT_STRINGS_SIZE MESSAGE_STORAGE_SIZE)
if(NOT AZ_IOT_AZ_MQTT_${_v} STREQUAL "")
target_compile_definitions(az_iot_adapter_az_mqtt PRIVATE
AZ_IOT_AZ_MQTT_${_v}=${AZ_IOT_AZ_MQTT_${_v}})
Expand Down
30 changes: 30 additions & 0 deletions c/adapters/az_mqtt/az_iot_az_mqtt_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,30 @@
#define AZ_IOT_AZ_MQTT_USER_PROPERTIES_MAX 16
#endif

/** @brief Clients of each MQTT version kept in static storage, so the adapter allocates nothing;
* create() returns NULL when all are in use. 0: each client is allocated when created. */
#ifndef AZ_IOT_AZ_MQTT_STATIC_CLIENTS
#define AZ_IOT_AZ_MQTT_STATIC_CLIENTS 0
#endif

/** @brief Static clients: bytes reserved for the transport. create() returns NULL when
* az_mqtt_transport_sizeof() is larger (OpenSSL: under 1 KiB; mbedTLS: about 5 KiB; Schannel:
* about 197 KiB). */
#ifndef AZ_IOT_AZ_MQTT_TRANSPORT_SIZE
#ifdef _WIN32
#define AZ_IOT_AZ_MQTT_TRANSPORT_SIZE (200 * 1024)
#else
#define AZ_IOT_AZ_MQTT_TRANSPORT_SIZE (8 * 1024)
#endif
#endif

/** @brief Static clients: bytes for the copies of a connect's strings (host, credentials, TLS
* paths or PEM, proxy, will, user properties), each with a NUL. A connect whose copies do not
* fit returns AZ_IOT_ERR_NOT_ENOUGH_SPACE. */
#ifndef AZ_IOT_AZ_MQTT_CONNECT_STRINGS_SIZE
#define AZ_IOT_AZ_MQTT_CONNECT_STRINGS_SIZE (8 * 1024)
#endif

#if AZ_IOT_AZ_MQTT_SEND_BUFFER_SIZE < 1 || AZ_IOT_AZ_MQTT_SEND_BUFFER_SIZE > 268435455
#error "AZ_IOT_AZ_MQTT_SEND_BUFFER_SIZE must be 1 to 268435455"
#endif
Expand All @@ -93,6 +117,12 @@
#if AZ_IOT_AZ_MQTT_INFLIGHT_MAX < 1 || AZ_IOT_AZ_MQTT_INFLIGHT_MAX > 32767
#error "AZ_IOT_AZ_MQTT_INFLIGHT_MAX must be 1 to 32767"
#endif
#if AZ_IOT_AZ_MQTT_STATIC_CLIENTS < 0
#error "AZ_IOT_AZ_MQTT_STATIC_CLIENTS must be 0 or more"
#endif
#if AZ_IOT_AZ_MQTT_TRANSPORT_SIZE < 1 || AZ_IOT_AZ_MQTT_CONNECT_STRINGS_SIZE < 1
#error "AZ_IOT_AZ_MQTT_TRANSPORT_SIZE and AZ_IOT_AZ_MQTT_CONNECT_STRINGS_SIZE must be 1 or more"
#endif
#if AZ_IOT_AZ_MQTT_USER_PROPERTIES_MAX < 1
#error "AZ_IOT_AZ_MQTT_USER_PROPERTIES_MAX must be at least 1"
#endif
Expand Down
20 changes: 6 additions & 14 deletions c/adapters/az_mqtt/az_iot_mqtt_az_mqtt.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,10 @@
#include <stdlib.h>
#include <string.h>

char* az_iot_az_mqtt_strdup(const char* s)
{
if (s == NULL)
{
return NULL;
}
size_t const n = strlen(s) + 1;
char* copy = (char*)malloc(n);
if (copy != NULL)
{
memcpy(copy, s, n);
}
return copy;
}
#if AZ_IOT_AZ_MQTT_STATIC_CLIENTS > 0 && defined(__GNUC__)
// Static clients allocate nothing: a heap call below fails to compile.
#pragma GCC poison malloc calloc realloc free
#endif

bool az_iot_az_mqtt_has_text(const char* s) { return s != NULL && s[0] != '\0'; }

Expand Down Expand Up @@ -141,7 +131,9 @@ const char* az_iot_az_mqtt_string_writer_add(az_iot_az_mqtt_string_writer* w, az
return out;
}

#if AZ_IOT_AZ_MQTT_STATIC_CLIENTS == 0
void az_iot_az_mqtt_factory_free(void* factory_ctx) { free(factory_ctx); }
#endif

void az_iot_az_mqtt_factory_destroy(az_iot_mqtt_factory* factory)
{
Expand Down
Loading
Loading