Skip to content

Commit ac8f1de

Browse files
sjamessuren-gabrielyan-espressif
authored andcommitted
fix(websocket): Return status code correctly on esp_websocket_client_send_with_opcode
1 parent 3e8de3a commit ac8f1de

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

components/esp_websocket_client/esp_websocket_client.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1200,6 +1200,7 @@ int esp_websocket_client_send_fin(esp_websocket_client_handle_t client, TickType
12001200

12011201
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)
12021202
{
1203+
int ret = ESP_OK;
12031204
if (client == NULL || len < 0 || (data == NULL && len > 0)) {
12041205
ESP_LOGE(TAG, "Invalid arguments");
12051206
return ESP_FAIL;
@@ -1212,24 +1213,28 @@ int esp_websocket_client_send_with_opcode(esp_websocket_client_handle_t client,
12121213

12131214
if (!esp_websocket_client_is_connected(client)) {
12141215
ESP_LOGE(TAG, "Websocket client is not connected");
1216+
ret = ESP_FAIL;
12151217
goto unlock_and_return;
12161218
}
12171219

12181220
if (client->transport == NULL) {
12191221
ESP_LOGE(TAG, "Invalid transport");
1222+
ret = ESP_FAIL;
12201223
goto unlock_and_return;
12211224
}
12221225
if (esp_websocket_new_buf(client, true) != ESP_OK) {
12231226
ESP_LOGE(TAG, "Failed to setup tx buffer");
1227+
ret = ESP_FAIL;
12241228
goto unlock_and_return;
12251229
}
12261230
if (esp_websocket_client_send_with_exact_opcode(client, opcode | WS_TRANSPORT_OPCODES_FIN, data, len, timeout) != true) {
12271231
ESP_LOGE(TAG, "Failed to send the buffer");
1232+
ret = ESP_FAIL;
12281233
goto unlock_and_return;
12291234
}
12301235
unlock_and_return:
12311236
xSemaphoreGiveRecursive(client->lock);
1232-
return ESP_FAIL;
1237+
return ret;
12331238
}
12341239

12351240
bool esp_websocket_client_is_connected(esp_websocket_client_handle_t client)

0 commit comments

Comments
 (0)