Skip to content

Commit

Permalink
Merge pull request #573 from huming2207/feature/ws-transport-handle
Browse files Browse the repository at this point in the history
feat(websocket): allow using external TCP transport handle (IDFGH-12825)
  • Loading branch information
gabsuren authored Jul 12, 2024
2 parents 15ae280 + 83ea287 commit 906e447
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
12 changes: 9 additions & 3 deletions components/esp_websocket_client/esp_websocket_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ typedef struct {
bool skip_cert_common_name_check;
const char *cert_common_name;
esp_err_t (*crt_bundle_attach)(void *conf);
esp_transport_handle_t ext_transport;
} websocket_config_storage_t;

typedef enum {
Expand Down Expand Up @@ -695,6 +696,7 @@ esp_websocket_client_handle_t esp_websocket_client_init(const esp_websocket_clie
client->config->skip_cert_common_name_check = config->skip_cert_common_name_check;
client->config->cert_common_name = config->cert_common_name;
client->config->crt_bundle_attach = config->crt_bundle_attach;
client->config->ext_transport = config->ext_transport;

if (config->uri) {
if (esp_websocket_client_set_uri(client, config->uri) != ESP_OK) {
Expand Down Expand Up @@ -1118,9 +1120,13 @@ esp_err_t esp_websocket_client_start(esp_websocket_client_handle_t client)
ESP_LOGE(TAG, "The client has started");
return ESP_FAIL;
}
if (esp_websocket_client_create_transport(client) != ESP_OK) {
ESP_LOGE(TAG, "Failed to create websocket transport");
return ESP_FAIL;

client->transport = client->config->ext_transport;
if (!client->transport) {
if (esp_websocket_client_create_transport(client) != ESP_OK) {
ESP_LOGE(TAG, "Failed to create websocket transport");
return ESP_FAIL;
}
}

if (xTaskCreate(esp_websocket_client_task, client->config->task_name ? client->config->task_name : "websocket_task",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ typedef struct {
int network_timeout_ms; /*!< Abort network operation if it is not completed after this value, in milliseconds (defaults to 10s) */
size_t ping_interval_sec; /*!< Websocket ping interval, defaults to 10 seconds if not set */
struct ifreq *if_name; /*!< The name of interface for data to go through. Use the default interface without setting */
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. */
} esp_websocket_client_config_t;

/**
Expand Down

0 comments on commit 906e447

Please sign in to comment.