mirror of
https://github.com/daveallie/crosspoint-reader.git
synced 2026-02-04 06:37:38 +03:00
use std::vector
This commit is contained in:
parent
44ea8b7b6a
commit
bb96e31381
@ -467,7 +467,7 @@ static bool flushUploadBuffer(CrossPointWebServer::UploadState& state) {
|
|||||||
if (state.bufferPos > 0 && state.file) {
|
if (state.bufferPos > 0 && state.file) {
|
||||||
esp_task_wdt_reset(); // Reset watchdog before potentially slow SD write
|
esp_task_wdt_reset(); // Reset watchdog before potentially slow SD write
|
||||||
const unsigned long writeStart = millis();
|
const unsigned long writeStart = millis();
|
||||||
const size_t written = state.file.write(state.buffer, state.bufferPos);
|
const size_t written = state.file.write(state.buffer.data(), state.bufferPos);
|
||||||
totalWriteTime += millis() - writeStart;
|
totalWriteTime += millis() - writeStart;
|
||||||
writeCount++;
|
writeCount++;
|
||||||
esp_task_wdt_reset(); // Reset watchdog after SD write
|
esp_task_wdt_reset(); // Reset watchdog after SD write
|
||||||
@ -565,7 +565,7 @@ void CrossPointWebServer::handleUpload(UploadState& state) const {
|
|||||||
const size_t space = UploadState::UPLOAD_BUFFER_SIZE - state.bufferPos;
|
const size_t space = UploadState::UPLOAD_BUFFER_SIZE - state.bufferPos;
|
||||||
const size_t toCopy = (remaining < space) ? remaining : space;
|
const size_t toCopy = (remaining < space) ? remaining : space;
|
||||||
|
|
||||||
memcpy(state.buffer + state.bufferPos, data, toCopy);
|
memcpy(state.buffer.data() + state.bufferPos, data, toCopy);
|
||||||
state.bufferPos += toCopy;
|
state.bufferPos += toCopy;
|
||||||
data += toCopy;
|
data += toCopy;
|
||||||
remaining -= toCopy;
|
remaining -= toCopy;
|
||||||
|
|||||||
@ -42,11 +42,10 @@ class CrossPointWebServer {
|
|||||||
// 4KB is a good balance: large enough to reduce syscall overhead, small enough
|
// 4KB is a good balance: large enough to reduce syscall overhead, small enough
|
||||||
// to keep individual write times short and avoid watchdog issues
|
// to keep individual write times short and avoid watchdog issues
|
||||||
static constexpr size_t UPLOAD_BUFFER_SIZE = 4096; // 4KB buffer
|
static constexpr size_t UPLOAD_BUFFER_SIZE = 4096; // 4KB buffer
|
||||||
uint8_t* buffer = nullptr;
|
std::vector<uint8_t> buffer;
|
||||||
size_t bufferPos = 0;
|
size_t bufferPos = 0;
|
||||||
|
|
||||||
UploadState() : buffer(new uint8_t[UPLOAD_BUFFER_SIZE]) {}
|
UploadState() { buffer.resize(UPLOAD_BUFFER_SIZE); }
|
||||||
~UploadState() { delete[] buffer; }
|
|
||||||
} upload;
|
} upload;
|
||||||
|
|
||||||
CrossPointWebServer();
|
CrossPointWebServer();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user