mirror of
https://github.com/espressif/esp-protocols.git
synced 2025-07-29 02:07:27 +02:00
feat(websocket): allow using external tcp transport handle
This commit is contained in:
@ -96,6 +96,7 @@ typedef struct {
|
|||||||
bool use_global_ca_store;
|
bool use_global_ca_store;
|
||||||
bool skip_cert_common_name_check;
|
bool skip_cert_common_name_check;
|
||||||
esp_err_t (*crt_bundle_attach)(void *conf);
|
esp_err_t (*crt_bundle_attach)(void *conf);
|
||||||
|
esp_transport_handle_t ext_transport;
|
||||||
} websocket_config_storage_t;
|
} websocket_config_storage_t;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
@ -677,6 +678,7 @@ esp_websocket_client_handle_t esp_websocket_client_init(const esp_websocket_clie
|
|||||||
client->config->client_key_len = config->client_key_len;
|
client->config->client_key_len = config->client_key_len;
|
||||||
client->config->skip_cert_common_name_check = config->skip_cert_common_name_check;
|
client->config->skip_cert_common_name_check = config->skip_cert_common_name_check;
|
||||||
client->config->crt_bundle_attach = config->crt_bundle_attach;
|
client->config->crt_bundle_attach = config->crt_bundle_attach;
|
||||||
|
client->config->ext_transport = config->ext_transport;
|
||||||
|
|
||||||
if (config->uri) {
|
if (config->uri) {
|
||||||
if (esp_websocket_client_set_uri(client, config->uri) != ESP_OK) {
|
if (esp_websocket_client_set_uri(client, config->uri) != ESP_OK) {
|
||||||
@ -1100,10 +1102,14 @@ esp_err_t esp_websocket_client_start(esp_websocket_client_handle_t client)
|
|||||||
ESP_LOGE(TAG, "The client has started");
|
ESP_LOGE(TAG, "The client has started");
|
||||||
return ESP_FAIL;
|
return ESP_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
client->transport = client->config->ext_transport;
|
||||||
|
if (!client->transport) {
|
||||||
if (esp_websocket_client_create_transport(client) != ESP_OK) {
|
if (esp_websocket_client_create_transport(client) != ESP_OK) {
|
||||||
ESP_LOGE(TAG, "Failed to create websocket transport");
|
ESP_LOGE(TAG, "Failed to create websocket transport");
|
||||||
return ESP_FAIL;
|
return ESP_FAIL;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (xTaskCreate(esp_websocket_client_task, client->config->task_name ? client->config->task_name : "websocket_task",
|
if (xTaskCreate(esp_websocket_client_task, client->config->task_name ? client->config->task_name : "websocket_task",
|
||||||
client->config->task_stack, client, client->config->task_prio, &client->task_handle) != pdTRUE) {
|
client->config->task_stack, client, client->config->task_prio, &client->task_handle) != pdTRUE) {
|
||||||
|
@ -127,6 +127,7 @@ typedef struct {
|
|||||||
int network_timeout_ms; /*!< Abort network operation if it is not completed after this value, in milliseconds (defaults to 10s) */
|
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 */
|
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 */
|
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;
|
} esp_websocket_client_config_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user