Skip to content

Commit

Permalink
Close #272: Optimise Web-UI loading speed (#273)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheSomeMan authored Dec 6, 2023
1 parent aa11e6e commit d43ca6a
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions src/http_server_accept_and_handle_conn.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,9 @@ http_server_netconn_write(
* then netconn_write_partly will ignore p_conn->send_timeout and will wait much longer,
* which will trigger task watchdog for http_server.
*/
size_t offset = 0;
const TickType_t tick_start = xTaskGetTickCount();
const int32_t send_timeout_ticks = (0 != p_conn->send_timeout) ? (int32_t)pdMS_TO_TICKS(p_conn->send_timeout) : 0;
size_t offset = 0;
do
{
size_t bytes_written = 0;
Expand All @@ -208,31 +210,25 @@ http_server_netconn_write(
(printf_uint_t)(buf_len - offset));
return false;
}
vTaskDelay(pdMS_TO_TICKS(20));
vTaskDelay(pdMS_TO_TICKS(10));
}
LOG_DBG(
"netconn_write_partly: offset=%u, bytes_written=%u",
(printf_uint_t)offset,
(printf_uint_t)bytes_written);
offset += bytes_written;
int32_t send_timeout = p_conn->send_timeout;
bool flag_success = false;
while ((!flag_success) && (send_timeout > 0))
if (0 != send_timeout_ticks)
{
const int32_t tmp_timeout = (send_timeout > 1000) ? 1000 : send_timeout;
flag_success = http_server_sema_send_wait_timeout(tmp_timeout);
LOG_DBG("Feed watchdog");
const esp_err_t err_wdt = esp_task_wdt_reset();
if (ESP_OK != err_wdt)
if ((xTaskGetTickCount() - tick_start) > send_timeout_ticks)
{
LOG_ERR_ESP(err_wdt, "%s failed", "esp_task_wdt_reset");
LOG_ERR("netconn_write_partly failed: send timeout (%d ms)", (printf_int_t)p_conn->send_timeout);
return false;
}
send_timeout -= tmp_timeout;
}
if (!flag_success)
const esp_err_t err_wdt = esp_task_wdt_reset();
if (ESP_OK != err_wdt)
{
LOG_ERR("netconn_write_partly failed: send timeout (%d ms)", (printf_int_t)p_conn->send_timeout);
return false;
LOG_ERR_ESP(err_wdt, "%s failed", "esp_task_wdt_reset");
}
} while (offset != buf_len);
return true;
Expand Down

0 comments on commit d43ca6a

Please sign in to comment.