Skip to content

Commit 906e447

Browse files
authored
Merge pull request #573 from huming2207/feature/ws-transport-handle
feat(websocket): allow using external TCP transport handle (IDFGH-12825)
2 parents 15ae280 + 83ea287 commit 906e447

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

components/esp_websocket_client/esp_websocket_client.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ typedef struct {
9797
bool skip_cert_common_name_check;
9898
const char *cert_common_name;
9999
esp_err_t (*crt_bundle_attach)(void *conf);
100+
esp_transport_handle_t ext_transport;
100101
} websocket_config_storage_t;
101102

102103
typedef enum {
@@ -695,6 +696,7 @@ esp_websocket_client_handle_t esp_websocket_client_init(const esp_websocket_clie
695696
client->config->skip_cert_common_name_check = config->skip_cert_common_name_check;
696697
client->config->cert_common_name = config->cert_common_name;
697698
client->config->crt_bundle_attach = config->crt_bundle_attach;
699+
client->config->ext_transport = config->ext_transport;
698700

699701
if (config->uri) {
700702
if (esp_websocket_client_set_uri(client, config->uri) != ESP_OK) {
@@ -1118,9 +1120,13 @@ esp_err_t esp_websocket_client_start(esp_websocket_client_handle_t client)
11181120
ESP_LOGE(TAG, "The client has started");
11191121
return ESP_FAIL;
11201122
}
1121-
if (esp_websocket_client_create_transport(client) != ESP_OK) {
1122-
ESP_LOGE(TAG, "Failed to create websocket transport");
1123-
return ESP_FAIL;
1123+
1124+
client->transport = client->config->ext_transport;
1125+
if (!client->transport) {
1126+
if (esp_websocket_client_create_transport(client) != ESP_OK) {
1127+
ESP_LOGE(TAG, "Failed to create websocket transport");
1128+
return ESP_FAIL;
1129+
}
11241130
}
11251131

11261132
if (xTaskCreate(esp_websocket_client_task, client->config->task_name ? client->config->task_name : "websocket_task",

components/esp_websocket_client/include/esp_websocket_client.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ typedef struct {
128128
int network_timeout_ms; /*!< Abort network operation if it is not completed after this value, in milliseconds (defaults to 10s) */
129129
size_t ping_interval_sec; /*!< Websocket ping interval, defaults to 10 seconds if not set */
130130
struct ifreq *if_name; /*!< The name of interface for data to go through. Use the default interface without setting */
131+
esp_transport_handle_t ext_transport; /*!< External WebSocket tcp_transport handle to the client; or if null, the client will create its own transport handle. */
131132
} esp_websocket_client_config_t;
132133

133134
/**

0 commit comments

Comments
 (0)