mirror of
https://github.com/espressif/esp-mqtt.git
synced 2025-07-31 19:25:14 +02:00
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
This commit is contained in:
@@ -165,7 +165,7 @@ typedef struct {
|
|||||||
void *user_context; /*!< pass user context to this option, then can receive that context in ``event->user_context`` */
|
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_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 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. */
|
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 */
|
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. */
|
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 */
|
const char *clientkey_password; /*!< Client key decryption password string */
|
||||||
int clientkey_password_len; /*!< String length of the password pointed to by clientkey_password */
|
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*/
|
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;
|
} esp_mqtt_client_config_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -654,14 +654,16 @@ esp_mqtt_client_handle_t esp_mqtt_client_init(const esp_mqtt_client_config_t *co
|
|||||||
if (buffer_size <= 0) {
|
if (buffer_size <= 0) {
|
||||||
buffer_size = MQTT_BUFFER_SIZE_BYTE;
|
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);
|
client->mqtt_state.in_buffer = (uint8_t *)malloc(buffer_size);
|
||||||
ESP_MEM_CHECK(TAG, client->mqtt_state.in_buffer, goto _mqtt_init_failed);
|
ESP_MEM_CHECK(TAG, client->mqtt_state.in_buffer, goto _mqtt_init_failed);
|
||||||
client->mqtt_state.in_buffer_length = buffer_size;
|
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);
|
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->mqtt_state.connect_info = &client->connect_info;
|
||||||
client->outbox = outbox_init();
|
client->outbox = outbox_init();
|
||||||
ESP_MEM_CHECK(TAG, client->outbox, goto _mqtt_init_failed);
|
ESP_MEM_CHECK(TAG, client->outbox, goto _mqtt_init_failed);
|
||||||
|
Reference in New Issue
Block a user