updated slow sample

This commit is contained in:
Mathieu Carbou
2024-12-10 21:13:45 +01:00
parent 3866d0b6a0
commit 25742e1958

View File

@@ -503,18 +503,20 @@ void setup() {
request->send(response); request->send(response);
}); });
// time curl -N -v -X GET http://192.168.4.1/slow.html --output - // time curl -N -v -G -d 'd=3000' -d 'l=10000' http://192.168.4.1/slow.html --output -
server.on("/slow.html", HTTP_GET, [](AsyncWebServerRequest* request) { server.on("/slow.html", HTTP_GET, [](AsyncWebServerRequest* request) {
request->client()->setRxTimeout(2000); uint32_t d = request->getParam("d")->value().toInt();
AsyncWebServerResponse* response = request->beginChunkedResponse("text/html", [](uint8_t* buffer, size_t maxLen, size_t index) -> size_t { uint32_t l = request->getParam("l")->value().toInt();
Serial.printf("%u\n", index); Serial.printf("d = %" PRIu32 ", l = %" PRIu32 "\n", d, l);
AsyncWebServerResponse* response = request->beginChunkedResponse("text/html", [d, l](uint8_t* buffer, size_t maxLen, size_t index) -> size_t {
Serial.printf("%" PRIu32 "\n", index);
// finished ? // finished ?
if (index >= 160000) if (index >= l)
return 0; return 0;
// slow down the task by 2 seconds // slow down the task by 2 seconds
// to simulate some heavy processing, like SD card reading // to simulate some heavy processing, like SD card reading
delay(100); delay(d);
memset(buffer, characters[charactersIndex], 256); memset(buffer, characters[charactersIndex], 256);
charactersIndex = (charactersIndex + 1) % sizeof(characters); charactersIndex = (charactersIndex + 1) % sizeof(characters);