From f24322552190936f34d8287f37013f48c78e3ace Mon Sep 17 00:00:00 2001 From: David Cermak Date: Tue, 10 Mar 2020 15:26:49 +0100 Subject: [PATCH 1/2] config: option to configure output buffer size Both input and output buffers had the same size, but it is desirable in embedded environment to use asymetric buffers. Added configuration option to defined output buffer size, if not defined output buffer defaults to the same size as the input buffer. Closes https://github.com/espressif/esp-mqtt/issues/152 --- include/mqtt_client.h | 3 ++- mqtt_client.c | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/include/mqtt_client.h b/include/mqtt_client.h index 37f416a..c90b2f7 100644 --- a/include/mqtt_client.h +++ b/include/mqtt_client.h @@ -165,7 +165,7 @@ typedef struct { void *user_context; /*!< pass user context to this option, then can receive that context in ``event->user_context`` */ int task_prio; /*!< MQTT task priority, default is 5, can be changed in ``make menuconfig`` */ int task_stack; /*!< MQTT task stack size, default is 6144 bytes, can be changed in ``make menuconfig`` */ - int buffer_size; /*!< size of MQTT send/receive buffer, default is 1024 */ + int buffer_size; /*!< size of MQTT send/receive buffer, default is 1024 (only receive buffer size if ``out_buffer_size`` defined) */ const char *cert_pem; /*!< Pointer to certificate data in PEM or DER format for server verify (with SSL), default is NULL, not required to verify the server. PEM-format must have a terminating NULL-character. DER-format requires the length to be passed in cert_len. */ size_t cert_len; /*!< Length of the buffer pointed to by cert_pem. May be 0 for null-terminated pem */ const char *client_cert_pem; /*!< Pointer to certificate data in PEM or DER format for SSL mutual authentication, default is NULL, not required if mutual authentication is not needed. If it is not NULL, also `client_key_pem` has to be provided. PEM-format must have a terminating NULL-character. DER-format requires the length to be passed in client_cert_len. */ @@ -181,6 +181,7 @@ typedef struct { const char *clientkey_password; /*!< Client key decryption password string */ int clientkey_password_len; /*!< String length of the password pointed to by clientkey_password */ esp_mqtt_protocol_ver_t protocol_ver; /*!< MQTT protocol version used for connection, defaults to value from menuconfig*/ + int out_buffer_size; /*!< size of MQTT output buffer. If not defined, both output and input buffers have the same size defined as ``buffer_size`` */ } esp_mqtt_client_config_t; /** diff --git a/mqtt_client.c b/mqtt_client.c index 3ee2028..9372512 100644 --- a/mqtt_client.c +++ b/mqtt_client.c @@ -654,14 +654,16 @@ esp_mqtt_client_handle_t esp_mqtt_client_init(const esp_mqtt_client_config_t *co if (buffer_size <= 0) { buffer_size = MQTT_BUFFER_SIZE_BYTE; } + // use separate value for output buffer size if configured + int out_buffer_size = config->out_buffer_size > 0 ? config->out_buffer_size : buffer_size; client->mqtt_state.in_buffer = (uint8_t *)malloc(buffer_size); ESP_MEM_CHECK(TAG, client->mqtt_state.in_buffer, goto _mqtt_init_failed); client->mqtt_state.in_buffer_length = buffer_size; - client->mqtt_state.out_buffer = (uint8_t *)malloc(buffer_size); + client->mqtt_state.out_buffer = (uint8_t *)malloc(out_buffer_size); ESP_MEM_CHECK(TAG, client->mqtt_state.out_buffer, goto _mqtt_init_failed); - client->mqtt_state.out_buffer_length = buffer_size; + client->mqtt_state.out_buffer_length = out_buffer_size; client->mqtt_state.connect_info = &client->connect_info; client->outbox = outbox_init(); ESP_MEM_CHECK(TAG, client->outbox, goto _mqtt_init_failed); From 61a8f4b63c3258bc4dc9ecb088cf80c1d160d530 Mon Sep 17 00:00:00 2001 From: David Cermak Date: Tue, 10 Mar 2020 16:19:51 +0100 Subject: [PATCH 2/2] ci: fix build issue (stale CMake cache) between 4.1 and 4.2 --- ci/build_examples.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/ci/build_examples.sh b/ci/build_examples.sh index 2de91e4..424b153 100755 --- a/ci/build_examples.sh +++ b/ci/build_examples.sh @@ -16,6 +16,7 @@ for i in $examples; do make defconfig make -j 4 else + rm -rf build idf.py build fi; done