forked from espressif/esp-idf
fix(examples): simple http_server example build for Linux target
Static task creation on Linux target had issues with insufficient stack memory allocation. Type of `StackType_t` is `unsigned long` and hence it must be considered during stack memory allocation. Fix ensures proper working of simple HTTP server example.
This commit is contained in:
@@ -1,13 +1,6 @@
|
|||||||
set(priv_req mbedtls)
|
set(priv_req mbedtls lwip esp_timer)
|
||||||
set(priv_inc_dir "src/util")
|
set(priv_inc_dir "src/util" "src/port/esp32")
|
||||||
set(requires http_parser esp_event)
|
set(requires http_parser esp_event)
|
||||||
if(NOT ${IDF_TARGET} STREQUAL "linux")
|
|
||||||
list(APPEND priv_req lwip esp_timer)
|
|
||||||
list(APPEND priv_inc_dir "src/port/esp32")
|
|
||||||
else()
|
|
||||||
list(APPEND priv_inc_dir "src/port/linux")
|
|
||||||
list(APPEND priv_req pthread)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
idf_component_register(SRCS "src/httpd_main.c"
|
idf_component_register(SRCS "src/httpd_main.c"
|
||||||
"src/httpd_parse.c"
|
"src/httpd_parse.c"
|
||||||
|
@@ -1,55 +0,0 @@
|
|||||||
/*
|
|
||||||
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
|
||||||
*/
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <pthread.h>
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define OS_SUCCESS ESP_OK
|
|
||||||
#define OS_FAIL ESP_FAIL
|
|
||||||
|
|
||||||
typedef TaskHandle_t othread_t;
|
|
||||||
|
|
||||||
static inline int httpd_os_thread_create(othread_t *thread,
|
|
||||||
const char *name, uint16_t stacksize, int prio,
|
|
||||||
void (*thread_routine)(void *arg), void *arg,
|
|
||||||
BaseType_t core_id, uint32_t caps)
|
|
||||||
{
|
|
||||||
pthread_attr_t thread_attr;
|
|
||||||
pthread_attr_init(&thread_attr);
|
|
||||||
pthread_attr_setstacksize(&thread_attr, stacksize);
|
|
||||||
int ret = pthread_create((pthread_t *)thread, &thread_attr, (void*)thread_routine, arg);
|
|
||||||
if (ret == 0) {
|
|
||||||
return OS_SUCCESS;
|
|
||||||
}
|
|
||||||
return OS_FAIL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Only self delete is supported */
|
|
||||||
static inline void httpd_os_thread_delete(void)
|
|
||||||
{
|
|
||||||
int x;
|
|
||||||
pthread_exit((void *)&x);
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void httpd_os_thread_sleep(int msecs)
|
|
||||||
{
|
|
||||||
usleep(msecs * 1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline othread_t httpd_os_thread_handle(void)
|
|
||||||
{
|
|
||||||
return (othread_t)pthread_self();
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
@@ -47,7 +47,7 @@
|
|||||||
|
|
||||||
/* Allocate memory for the task's stack using the provided memory caps
|
/* Allocate memory for the task's stack using the provided memory caps
|
||||||
* */
|
* */
|
||||||
pxStack = heap_caps_malloc( usStackDepth, ( uint32_t ) uxMemoryCaps );
|
pxStack = heap_caps_malloc( ( ( size_t ) usStackDepth ) * sizeof( StackType_t ), ( uint32_t ) uxMemoryCaps );
|
||||||
|
|
||||||
if( ( pxTaskBuffer == NULL ) || ( pxStack == NULL ) )
|
if( ( pxTaskBuffer == NULL ) || ( pxStack == NULL ) )
|
||||||
{
|
{
|
||||||
|
@@ -73,6 +73,16 @@ examples/protocols/http_server/restful_server:
|
|||||||
depends_filepatterns:
|
depends_filepatterns:
|
||||||
- components/esp_http_server/**/*
|
- components/esp_http_server/**/*
|
||||||
|
|
||||||
|
examples/protocols/http_server/simple:
|
||||||
|
<<: *default_dependencies
|
||||||
|
enable:
|
||||||
|
- if: INCLUDE_DEFAULT == 1 or IDF_TARGET == "linux"
|
||||||
|
disable_test:
|
||||||
|
- if: IDF_TARGET not in ["esp32", "esp32c3", "esp32s3"]
|
||||||
|
reason: only test on these targets
|
||||||
|
depends_filepatterns:
|
||||||
|
- components/esp_http_server/**/*
|
||||||
|
|
||||||
examples/protocols/http_server/ws_echo_server:
|
examples/protocols/http_server/ws_echo_server:
|
||||||
<<: *default_dependencies
|
<<: *default_dependencies
|
||||||
disable_test:
|
disable_test:
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-C5 | ESP32-C6 | ESP32-C61 | ESP32-H2 | ESP32-P4 | ESP32-S2 | ESP32-S3 |
|
| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-C5 | ESP32-C6 | ESP32-C61 | ESP32-H2 | ESP32-P4 | ESP32-S2 | ESP32-S3 | Linux |
|
||||||
| ----------------- | ----- | -------- | -------- | -------- | -------- | --------- | -------- | -------- | -------- | -------- |
|
| ----------------- | ----- | -------- | -------- | -------- | -------- | --------- | -------- | -------- | -------- | -------- | ----- |
|
||||||
|
|
||||||
# Simple HTTPD Server Example
|
# Simple HTTPD Server Example
|
||||||
|
|
||||||
|
@@ -1,9 +1,12 @@
|
|||||||
set(requires esp-tls nvs_flash esp_netif esp_http_server esp_wifi esp_eth)
|
set(requires esp-tls nvs_flash esp_netif esp_http_server)
|
||||||
idf_build_get_property(target IDF_TARGET)
|
idf_build_get_property(target IDF_TARGET)
|
||||||
|
|
||||||
if(${target} STREQUAL "linux")
|
if(${target} STREQUAL "linux")
|
||||||
list(APPEND requires esp_stubs protocol_examples_common)
|
list(APPEND requires esp_stubs protocol_examples_common)
|
||||||
|
else()
|
||||||
|
list(APPEND requires esp_wifi esp_eth)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
idf_component_register(SRCS "main.c"
|
idf_component_register(SRCS "main.c"
|
||||||
INCLUDE_DIRS "."
|
INCLUDE_DIRS "."
|
||||||
PRIV_REQUIRES ${requires})
|
PRIV_REQUIRES ${requires})
|
||||||
|
@@ -407,7 +407,7 @@ static esp_err_t sse_handler(httpd_req_t *req)
|
|||||||
gettimeofday(&tv, NULL); // Get the current time
|
gettimeofday(&tv, NULL); // Get the current time
|
||||||
int64_t time_since_boot = tv.tv_sec; // Time since boot in seconds
|
int64_t time_since_boot = tv.tv_sec; // Time since boot in seconds
|
||||||
esp_err_t err;
|
esp_err_t err;
|
||||||
int len = snprintf(sse_data, sizeof(sse_data), "data: Time since boot: %lld seconds\n\n", time_since_boot);
|
int len = snprintf(sse_data, sizeof(sse_data), "data: Time since boot: %" PRIi64 " seconds\n\n", time_since_boot);
|
||||||
if ((err = httpd_resp_send_chunk(req, sse_data, len)) != ESP_OK) {
|
if ((err = httpd_resp_send_chunk(req, sse_data, len)) != ESP_OK) {
|
||||||
ESP_LOGE(TAG, "Failed to send sse data (returned %02X)", err);
|
ESP_LOGE(TAG, "Failed to send sse data (returned %02X)", err);
|
||||||
break;
|
break;
|
||||||
|
Reference in New Issue
Block a user