From 0b9d2f3afd9882745abe5b88f60302471c461a8b Mon Sep 17 00:00:00 2001 From: Angelo Cipriani Date: Tue, 24 Dec 2024 09:42:17 +0100 Subject: [PATCH 1/4] Exposes core_id in the configuration of an HttpServer --- src/http/server.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/http/server.rs b/src/http/server.rs index bdd02d18e6a..82b9e8914df 100644 --- a/src/http/server.rs +++ b/src/http/server.rs @@ -79,6 +79,7 @@ pub struct Configuration { pub http_port: u16, pub ctrl_port: u16, pub https_port: u16, + pub core_id: i32, pub max_sessions: usize, pub session_timeout: Duration, pub stack_size: usize, @@ -99,6 +100,7 @@ impl Default for Configuration { http_port: 80, ctrl_port: 32768, https_port: 443, + core_id: i32::MAX, max_sessions: 16, session_timeout: Duration::from_secs(20 * 60), #[cfg(not(esp_idf_esp_https_server_enable))] @@ -137,7 +139,7 @@ impl From<&Configuration> for Newtype { ))] task_caps: (MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT), stack_size: conf.stack_size, - core_id: i32::MAX, + core_id: conf.core_id, server_port: conf.http_port, ctrl_port: conf.ctrl_port, max_open_sockets: conf.max_open_sockets as _, From 6a2cb30a5fe6dde0d28c410a9e3575f7e40080bb Mon Sep 17 00:00:00 2001 From: Angelo Cipriani Date: Thu, 2 Jan 2025 19:46:39 +0100 Subject: [PATCH 2/4] Update the http server to use the Core type instead of an int --- src/http/server.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/http/server.rs b/src/http/server.rs index 1324d6eb4e2..c2b41bb1d1d 100644 --- a/src/http/server.rs +++ b/src/http/server.rs @@ -58,6 +58,8 @@ use embedded_svc::http::headers::content_type; use embedded_svc::http::*; use embedded_svc::io::{ErrorType, Read, Write}; +use esp_idf_hal::cpu::Core; + use crate::sys::*; use uncased::{Uncased, UncasedStr}; @@ -83,7 +85,7 @@ pub struct Configuration { pub http_port: u16, pub ctrl_port: u16, pub https_port: u16, - pub core_id: i32, + pub core: Option, pub max_sessions: usize, pub session_timeout: Duration, pub stack_size: usize, @@ -104,7 +106,7 @@ impl Default for Configuration { http_port: 80, ctrl_port: 32768, https_port: 443, - core_id: i32::MAX, + core: None, max_sessions: 16, session_timeout: Duration::from_secs(20 * 60), #[cfg(not(esp_idf_esp_https_server_enable))] @@ -143,7 +145,7 @@ impl From<&Configuration> for Newtype { ))] task_caps: (MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT), stack_size: conf.stack_size, - core_id: conf.core_id, + core: conf.core.map(|core| core.into()).unwrap_or(i32::MAX), server_port: conf.http_port, ctrl_port: conf.ctrl_port, max_open_sockets: conf.max_open_sockets as _, From 168b32b5c9d4bdb2813c6f954910b336cd1f63f7 Mon Sep 17 00:00:00 2001 From: Angelo Cipriani Date: Thu, 2 Jan 2025 19:48:10 +0100 Subject: [PATCH 3/4] Fix name of variable --- src/http/server.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/http/server.rs b/src/http/server.rs index c2b41bb1d1d..541db091a44 100644 --- a/src/http/server.rs +++ b/src/http/server.rs @@ -145,7 +145,7 @@ impl From<&Configuration> for Newtype { ))] task_caps: (MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT), stack_size: conf.stack_size, - core: conf.core.map(|core| core.into()).unwrap_or(i32::MAX), + core_id: conf.core.map(|core| core.into()).unwrap_or(i32::MAX), server_port: conf.http_port, ctrl_port: conf.ctrl_port, max_open_sockets: conf.max_open_sockets as _, From 1d65e8f0231157ba99c1d4f1d69f640f1c82347e Mon Sep 17 00:00:00 2001 From: Angelo Cipriani Date: Thu, 2 Jan 2025 19:58:58 +0100 Subject: [PATCH 4/4] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 672e2a26897..eea7ca27c73 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Change default eth key (#502) - ESP IDF Partitions API (#511) - Expose src_addr and dst_addr in espnow recv cb (#525) +- Add `core` field to `http::server::Configuration` to control which CPU core runs the HTTP server task ### Added - Compatibility with ESP-IDF v5.3.X