From 2dfecbc8c4ae0b6484cbb1c2c021cb72afead9b0 Mon Sep 17 00:00:00 2001 From: Brendan O'Leary Date: Thu, 18 Dec 2025 22:21:18 -0500 Subject: [PATCH] wrap in namespace --- .../network/CrossPointWebServerActivity.cpp | 11 +++++++++-- .../network/server/CrossPointWebServer.cpp | 10 +++++++--- src/main.cpp | 17 +++++++++-------- 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/src/activities/network/CrossPointWebServerActivity.cpp b/src/activities/network/CrossPointWebServerActivity.cpp index 40c5a45..82f6329 100644 --- a/src/activities/network/CrossPointWebServerActivity.cpp +++ b/src/activities/network/CrossPointWebServerActivity.cpp @@ -160,7 +160,8 @@ void CrossPointWebServerActivity::loop() { break; case WebServerActivityState::SERVER_RUNNING: - // Handle web server requests + // Handle web server requests - call handleClient multiple times per loop + // to improve responsiveness and upload throughput if (webServer && webServer->isRunning()) { unsigned long timeSinceLastHandleClient = millis() - lastHandleClientTime; @@ -170,7 +171,13 @@ void CrossPointWebServerActivity::loop() { timeSinceLastHandleClient); } - webServer->handleClient(); + // Call handleClient multiple times to process pending requests faster + // This is critical for upload performance - HTTP file uploads send data + // in chunks and each handleClient() call processes incoming data + constexpr int HANDLE_CLIENT_ITERATIONS = 10; + for (int i = 0; i < HANDLE_CLIENT_ITERATIONS && webServer->isRunning(); i++) { + webServer->handleClient(); + } lastHandleClientTime = millis(); } diff --git a/src/activities/network/server/CrossPointWebServer.cpp b/src/activities/network/server/CrossPointWebServer.cpp index 2b35686..61a8813 100644 --- a/src/activities/network/server/CrossPointWebServer.cpp +++ b/src/activities/network/server/CrossPointWebServer.cpp @@ -10,13 +10,15 @@ #include "html/FilesPageHeaderHtml.generated.h" #include "html/HomePageHtml.generated.h" +namespace { + // Folders/files to hide from the web interface file browser // Note: Items starting with "." are automatically hidden -static const char* HIDDEN_ITEMS[] = {"System Volume Information", "XTCache"}; -static const size_t HIDDEN_ITEMS_COUNT = sizeof(HIDDEN_ITEMS) / sizeof(HIDDEN_ITEMS[0]); +const char* HIDDEN_ITEMS[] = {"System Volume Information", "XTCache"}; +const size_t HIDDEN_ITEMS_COUNT = sizeof(HIDDEN_ITEMS) / sizeof(HIDDEN_ITEMS[0]); // Helper function to escape HTML special characters to prevent XSS -static String escapeHtml(const String& input) { +String escapeHtml(const String& input) { String output; output.reserve(input.length() * 1.1); // Pre-allocate with some extra space @@ -46,6 +48,8 @@ static String escapeHtml(const String& input) { return output; } +} // namespace + // File listing page template - now using generated headers: // - HomePageHtml (from html/HomePage.html) // - FilesPageHeaderHtml (from html/FilesPageHeader.html) diff --git a/src/main.cpp b/src/main.cpp index 912ac2c..4e43be0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -208,14 +208,6 @@ void loop() { unsigned long loopStartTime = millis(); - // Reduce delay when webserver is running to allow faster handleClient() calls - // This is critical for upload performance and preventing TCP timeouts - if (webServerActivity && webServerActivity->isWebServerRunning()) { - delay(1); // Minimal delay to prevent tight loop - } else { - delay(10); // Normal delay when webserver not active - } - static unsigned long lastMemPrint = 0; if (Serial && millis() - lastMemPrint >= 10000) { Serial.printf("[%lu] [MEM] Free: %d bytes, Total: %d bytes, Min Free: %d bytes\n", millis(), ESP.getFreeHeap(), @@ -260,4 +252,13 @@ void loop() { } lastLoopTime = loopStartTime; + + // Add delay at the end of the loop to prevent tight spinning + // When webserver is running, use yield() instead of delay for faster response + // When webserver is not running, use longer delay to save power + if (webServerActivity && webServerActivity->isWebServerRunning()) { + yield(); // Give FreeRTOS a chance to run tasks, but return immediately + } else { + delay(10); // Normal delay when webserver not active + } }