mirror of
https://github.com/esphome/esphome.git
synced 2026-03-23 18:59:02 +08:00
[web_server_idf] Inline send() methods to reduce httpd stack depth
Move both AsyncWebServerRequest::send() overloads to the header as ESPHOME_ALWAYS_INLINE. These are trivial wrappers around httpd_resp_send() that add an unnecessary stack frame on the httpd worker task. The httpd task has a limited stack (default + 256 bytes), and the web_server request handling chain is already 16+ frames deep. Each eliminated frame gives more headroom for the lwip send path underneath. Fixes stack overflow reported in #14991.
This commit is contained in:
@@ -262,19 +262,6 @@ StringRef AsyncWebServerRequest::url_to(std::span<char, URL_BUF_SIZE> buffer) co
|
||||
return StringRef(buffer.data(), decoded_len);
|
||||
}
|
||||
|
||||
void AsyncWebServerRequest::send(AsyncWebServerResponse *response) {
|
||||
httpd_resp_send(*this, response->get_content_data(), response->get_content_size());
|
||||
}
|
||||
|
||||
void AsyncWebServerRequest::send(int code, const char *content_type, const char *content) {
|
||||
this->init_response_(nullptr, code, content_type);
|
||||
if (content) {
|
||||
httpd_resp_send(*this, content, HTTPD_RESP_USE_STRLEN);
|
||||
} else {
|
||||
httpd_resp_send(*this, nullptr, 0);
|
||||
}
|
||||
}
|
||||
|
||||
void AsyncWebServerRequest::redirect(const std::string &url) {
|
||||
httpd_resp_set_status(*this, "302 Found");
|
||||
httpd_resp_set_hdr(*this, "Location", url.c_str());
|
||||
|
||||
@@ -134,8 +134,17 @@ class AsyncWebServerRequest {
|
||||
|
||||
void redirect(const std::string &url);
|
||||
|
||||
void send(AsyncWebServerResponse *response);
|
||||
void send(int code, const char *content_type = nullptr, const char *content = nullptr);
|
||||
inline void ESPHOME_ALWAYS_INLINE send(AsyncWebServerResponse *response) {
|
||||
httpd_resp_send(*this, response->get_content_data(), response->get_content_size());
|
||||
}
|
||||
inline void ESPHOME_ALWAYS_INLINE send(int code, const char *content_type = nullptr, const char *content = nullptr) {
|
||||
this->init_response_(nullptr, code, content_type);
|
||||
if (content) {
|
||||
httpd_resp_send(*this, content, HTTPD_RESP_USE_STRLEN);
|
||||
} else {
|
||||
httpd_resp_send(*this, nullptr, 0);
|
||||
}
|
||||
}
|
||||
// NOLINTNEXTLINE(readability-identifier-naming)
|
||||
AsyncWebServerResponse *beginResponse(int code, const char *content_type) {
|
||||
auto *res = new AsyncWebServerResponseEmpty(this); // NOLINT(cppcoreguidelines-owning-memory)
|
||||
|
||||
Reference in New Issue
Block a user