From 1fcc001ae82b598349ab57280a3b63fbff5fae07 Mon Sep 17 00:00:00 2001 From: David Cermak Date: Tue, 12 Nov 2019 17:42:51 +0100 Subject: [PATCH] ws_client: fix handling timeouts by websocket client. tcp-transport component did not support wait forever. this update uses value of -1 to request this state. websocket client uses timeouts in RTOS ticks. fixed recalculation to ms (including special value of -1) to use correctly tcp-transport component Closes https://github.com/espressif/esp-idf/issues/4316 * Original commit: espressif/esp-idf@e1f982921a08022ca4307900fc058ccacccd26d0 --- components/esp_websocket_client/esp_websocket_client.c | 4 ++-- .../esp_websocket_client/include/esp_websocket_client.h | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/components/esp_websocket_client/esp_websocket_client.c b/components/esp_websocket_client/esp_websocket_client.c index b509463cf..08d2ba21f 100644 --- a/components/esp_websocket_client/esp_websocket_client.c +++ b/components/esp_websocket_client/esp_websocket_client.c @@ -606,14 +606,14 @@ static int esp_websocket_client_send_with_opcode(esp_websocket_client_handle_t c goto unlock_and_return; } - while (widx < len) { if (need_write > client->buffer_size) { need_write = client->buffer_size; } memcpy(client->tx_buffer, data + widx, need_write); // send with ws specific way and specific opcode - wlen = esp_transport_ws_send_raw(client->transport, opcode, (char *)client->tx_buffer, need_write, timeout); + wlen = esp_transport_ws_send_raw(client->transport, opcode, (char *)client->tx_buffer, need_write, + (timeout==portMAX_DELAY)? -1 : timeout * portTICK_PERIOD_MS); if (wlen <= 0) { ret = wlen; ESP_LOGE(TAG, "Network error: esp_transport_write() returned %d, errno=%d", ret, errno); diff --git a/components/esp_websocket_client/include/esp_websocket_client.h b/components/esp_websocket_client/include/esp_websocket_client.h index 444343c82..3dbe1df9a 100644 --- a/components/esp_websocket_client/include/esp_websocket_client.h +++ b/components/esp_websocket_client/include/esp_websocket_client.h @@ -155,7 +155,7 @@ esp_err_t esp_websocket_client_destroy(esp_websocket_client_handle_t client); * @param[in] client The client * @param[in] data The data * @param[in] len The length - * @param[in] timeout Write data timeout + * @param[in] timeout Write data timeout in RTOS ticks * * @return * - Number of data was sent @@ -169,7 +169,7 @@ int esp_websocket_client_send(esp_websocket_client_handle_t client, const char * * @param[in] client The client * @param[in] data The data * @param[in] len The length - * @param[in] timeout Write data timeout + * @param[in] timeout Write data timeout in RTOS ticks * * @return * - Number of data was sent @@ -183,7 +183,7 @@ int esp_websocket_client_send_bin(esp_websocket_client_handle_t client, const ch * @param[in] client The client * @param[in] data The data * @param[in] len The length - * @param[in] timeout Write data timeout + * @param[in] timeout Write data timeout in RTOS ticks * * @return * - Number of data was sent