|
1 | 1 | /*
|
2 |
| - * SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD |
| 2 | + * SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD |
3 | 3 | *
|
4 | 4 | * SPDX-License-Identifier: Apache-2.0
|
5 | 5 | */
|
@@ -550,9 +550,13 @@ static int esp_websocket_client_send_with_exact_opcode(esp_websocket_client_hand
|
550 | 550 | int ret = -1;
|
551 | 551 | int need_write = len;
|
552 | 552 | int wlen = 0, widx = 0;
|
553 |
| - |
554 | 553 | bool contained_fin = opcode & WS_TRANSPORT_OPCODES_FIN;
|
555 | 554 |
|
| 555 | + if (esp_websocket_new_buf(client, true) != ESP_OK) { |
| 556 | + ESP_LOGE(TAG, "Failed to setup tx buffer"); |
| 557 | + return -1; |
| 558 | + } |
| 559 | + |
556 | 560 | while (widx < len || opcode) { // allow for sending "current_opcode" only message with len==0
|
557 | 561 | if (need_write > client->buffer_size) {
|
558 | 562 | need_write = client->buffer_size;
|
@@ -1204,33 +1208,27 @@ int esp_websocket_client_send_fin(esp_websocket_client_handle_t client, TickType
|
1204 | 1208 |
|
1205 | 1209 | int esp_websocket_client_send_with_opcode(esp_websocket_client_handle_t client, ws_transport_opcodes_t opcode, const uint8_t *data, int len, TickType_t timeout)
|
1206 | 1210 | {
|
1207 |
| - int ret = ESP_OK; |
| 1211 | + int ret = -1; |
1208 | 1212 | if (client == NULL || len < 0 || (data == NULL && len > 0)) {
|
1209 | 1213 | ESP_LOGE(TAG, "Invalid arguments");
|
1210 |
| - return ESP_FAIL; |
| 1214 | + return -1; |
1211 | 1215 | }
|
1212 | 1216 |
|
1213 | 1217 | if (xSemaphoreTakeRecursive(client->lock, timeout) != pdPASS) {
|
1214 | 1218 | ESP_LOGE(TAG, "Could not lock ws-client within %" PRIu32 " timeout", timeout);
|
1215 |
| - return ESP_FAIL; |
| 1219 | + return -1; |
1216 | 1220 | }
|
1217 | 1221 |
|
1218 | 1222 | if (!esp_websocket_client_is_connected(client)) {
|
1219 | 1223 | ESP_LOGE(TAG, "Websocket client is not connected");
|
1220 |
| - ret = ESP_FAIL; |
1221 | 1224 | goto unlock_and_return;
|
1222 | 1225 | }
|
1223 | 1226 |
|
1224 | 1227 | if (client->transport == NULL) {
|
1225 | 1228 | ESP_LOGE(TAG, "Invalid transport");
|
1226 |
| - ret = ESP_FAIL; |
1227 |
| - goto unlock_and_return; |
1228 |
| - } |
1229 |
| - if (esp_websocket_new_buf(client, true) != ESP_OK) { |
1230 |
| - ESP_LOGE(TAG, "Failed to setup tx buffer"); |
1231 |
| - ret = ESP_FAIL; |
1232 | 1229 | goto unlock_and_return;
|
1233 | 1230 | }
|
| 1231 | + |
1234 | 1232 | ret = esp_websocket_client_send_with_exact_opcode(client, opcode | WS_TRANSPORT_OPCODES_FIN, data, len, timeout);
|
1235 | 1233 | if (ret < 0) {
|
1236 | 1234 | ESP_LOGE(TAG, "Failed to send the buffer");
|
|
0 commit comments