Skip to content

Commit 002fe16

Browse files
feat(websocket): affinity configuration
1 parent 9e0bcd4 commit 002fe16

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

components/esp_websocket_client/esp_websocket_client.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ static const char *TAG = "websocket_client";
2929
#define WEBSOCKET_SSL_DEFAULT_PORT (443)
3030
#define WEBSOCKET_BUFFER_SIZE_BYTE (1024)
3131
#define WEBSOCKET_RECONNECT_TIMEOUT_MS (10*1000)
32+
#define WEBSOCKET_TASK_CORE_ID (tskNO_AFFINITY)
3233
#define WEBSOCKET_TASK_PRIORITY (5)
3334
#define WEBSOCKET_TASK_STACK (4*1024)
3435
#define WEBSOCKET_NETWORK_TIMEOUT_MS (10*1000)
@@ -79,6 +80,7 @@ const static int REQUESTED_STOP_BIT = BIT2; // Indicates that a client stop
7980
ESP_EVENT_DEFINE_BASE(WEBSOCKET_EVENTS);
8081

8182
typedef struct {
83+
BaseType_t task_core_id;
8284
const char *task_name;
8385
int task_stack;
8486
int task_prio;
@@ -320,6 +322,13 @@ static char *http_auth_basic(const char *username, const char *password)
320322
static esp_err_t esp_websocket_client_set_config(esp_websocket_client_handle_t client, const esp_websocket_client_config_t *config)
321323
{
322324
websocket_config_storage_t *cfg = client->config;
325+
326+
if (config->task_core_id_set) {
327+
cfg->task_core_id = config->task_core_id;
328+
} else {
329+
cfg->task_core_id = WEBSOCKET_TASK_CORE_ID;
330+
}
331+
323332
cfg->task_prio = config->task_prio;
324333
if (cfg->task_prio <= 0) {
325334
cfg->task_prio = WEBSOCKET_TASK_PRIORITY;
@@ -1283,7 +1292,7 @@ esp_err_t esp_websocket_client_start(esp_websocket_client_handle_t client)
12831292
}
12841293

12851294
if (xTaskCreate(esp_websocket_client_task, client->config->task_name ? client->config->task_name : "websocket_task",
1286-
client->config->task_stack, client, client->config->task_prio, &client->task_handle) != pdTRUE) {
1295+
client->config->task_stack, client, client->config->task_prio, &client->task_handle, client->config->task_core_id) != pdTRUE) {
12871296
ESP_LOGE(TAG, "Error create websocket task");
12881297
return ESP_FAIL;
12891298
}

components/esp_websocket_client/include/esp_websocket_client.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ typedef struct {
115115
bool disable_auto_reconnect; /*!< Disable the automatic reconnect function when disconnected */
116116
bool enable_close_reconnect; /*!< Enable reconnect after server close */
117117
void *user_context; /*!< HTTP user data context */
118+
bool task_core_id_set; /*!< Websocket task core-id chosen */
119+
int task_core_id; /*!< Websocket task core-id (optional)*/
118120
int task_prio; /*!< Websocket task priority */
119121
const char *task_name; /*!< Websocket task name */
120122
int task_stack; /*!< Websocket task stack */

0 commit comments

Comments
 (0)