mirror of
https://github.com/xoseperez/espurna.git
synced 2026-03-23 00:27:06 +01:00
system: some refactoring
There's no need to move a temporary which is already an rvalue Clean-up some redundant attributes and function in settings. Make sure C types are proxied to fixed-sized ones, not the other way around. Clean-up webprint implementation - use typed duration for the backlog - don't duplicate members and types for config, just re-use the struct as-is - don't go over-the-top with const members, just proxy through a method
This commit is contained in:
@@ -64,17 +64,14 @@ namespace {
|
||||
#include "static/server.key.h"
|
||||
#endif // WEB_SSL_ENABLED
|
||||
|
||||
AsyncWebPrint::AsyncWebPrint(const AsyncWebPrintConfig& config, AsyncWebServerRequest* request) :
|
||||
mimeType(config.mimeType),
|
||||
backlogCountMax(config.backlogCountMax),
|
||||
backlogSizeMax(config.backlogSizeMax),
|
||||
backlogTimeout(config.backlogTimeout),
|
||||
AsyncWebPrint::AsyncWebPrint(AsyncWebPrintConfig config, AsyncWebServerRequest* request) :
|
||||
_config(config),
|
||||
_request(request),
|
||||
_state(State::None)
|
||||
{}
|
||||
|
||||
bool AsyncWebPrint::_addBuffer() {
|
||||
if ((_buffers.size() + 1) > backlogCountMax) {
|
||||
if ((_buffers.size() + 1) > _config.backlog.count) {
|
||||
if (!_exhaustBuffers()) {
|
||||
_state = State::Error;
|
||||
return false;
|
||||
@@ -83,7 +80,7 @@ bool AsyncWebPrint::_addBuffer() {
|
||||
|
||||
// Note: c++17, emplace returns created object reference
|
||||
// c++11, we need to use .back()
|
||||
_buffers.emplace_back(backlogSizeMax, 0);
|
||||
_buffers.emplace_back(_config.backlog.size, 0);
|
||||
_buffers.back().clear();
|
||||
|
||||
return true;
|
||||
@@ -103,7 +100,7 @@ bool AsyncWebPrint::_addBuffer() {
|
||||
void AsyncWebPrint::_prepareRequest() {
|
||||
_state = State::Sending;
|
||||
|
||||
auto *response = _request->beginChunkedResponse(mimeType, [this](uint8_t *buffer, size_t maxLen, size_t index) -> size_t {
|
||||
auto *response = _request->beginChunkedResponse(_config.mimeType, [this](uint8_t *buffer, size_t maxLen, size_t index) -> size_t {
|
||||
switch (_state) {
|
||||
case State::None:
|
||||
return RESPONSE_TRY_AGAIN;
|
||||
@@ -159,9 +156,13 @@ bool AsyncWebPrint::_exhaustBuffers() {
|
||||
_prepareRequest();
|
||||
}
|
||||
|
||||
const auto start = millis();
|
||||
constexpr espurna::duration::Seconds Timeout { 5 };
|
||||
|
||||
using TimeSource = espurna::time::CoreClock;
|
||||
const auto start = TimeSource::now();
|
||||
|
||||
do {
|
||||
if (millis() - start > 5000) {
|
||||
if (TimeSource::now() - start > Timeout) {
|
||||
_buffers.clear();
|
||||
break;
|
||||
}
|
||||
@@ -275,7 +276,6 @@ void _onGetConfig(AsyncWebServerRequest *request) {
|
||||
auto out = std::make_shared<String>();
|
||||
out->reserve(TCP_MSS);
|
||||
|
||||
|
||||
char buffer[256];
|
||||
int prefix_len = snprintf_P(buffer, sizeof(buffer),
|
||||
PSTR("{\n\"app\": \"%s\",\n\"version\": \"%s\",\n\"backup\": \"1\""),
|
||||
|
||||
Reference in New Issue
Block a user