wrap in namespace

This commit is contained in:
Brendan O'Leary 2025-12-18 22:21:18 -05:00
parent 34dbbc5503
commit 2dfecbc8c4
3 changed files with 25 additions and 13 deletions

View File

@ -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);
}
// 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();
}

View File

@ -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)

View File

@ -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
}
}