|
|
@@ -393,14 +393,12 @@ static esp_err_t send_datafile(httpd_req_t *req, bool send_full_file)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /* Find end of line */
|
|
|
- while (1)
|
|
|
+ /* Find end of line (a file without a newline, e.g. empty after a power cut, must not loop forever) */
|
|
|
+ int c;
|
|
|
+ do
|
|
|
{
|
|
|
- if (fgetc(fd) == '\n')
|
|
|
- {
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
+ c = fgetc(fd);
|
|
|
+ } while ((c != EOF) && (c != '\n'));
|
|
|
}
|
|
|
|
|
|
/* Retrieve the pointer to scratch buffer for temporary storage */
|
|
|
@@ -486,14 +484,12 @@ static esp_err_t send_logfile(httpd_req_t *req, bool send_full_file)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /* Find end of line */
|
|
|
- while (1)
|
|
|
+ /* Find end of line (a file without a newline, e.g. empty after a power cut, must not loop forever) */
|
|
|
+ int c;
|
|
|
+ do
|
|
|
{
|
|
|
- if (fgetc(fd) == '\n')
|
|
|
- {
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
+ c = fgetc(fd);
|
|
|
+ } while ((c != EOF) && (c != '\n'));
|
|
|
}
|
|
|
|
|
|
/* Retrieve the pointer to scratch buffer for temporary storage */
|
|
|
@@ -704,6 +700,7 @@ static esp_err_t upload_post_handler(httpd_req_t *req)
|
|
|
/* Content length of the request gives
|
|
|
* the size of the file being uploaded */
|
|
|
int remaining = req->content_len;
|
|
|
+ int timeouts = 0;
|
|
|
|
|
|
while (remaining > 0)
|
|
|
{
|
|
|
@@ -712,9 +709,10 @@ static esp_err_t upload_post_handler(httpd_req_t *req)
|
|
|
/* Receive the file part by part into a buffer */
|
|
|
if ((received = httpd_req_recv(req, buf, MIN(remaining, SERVER_FILER_SCRATCH_BUFSIZE))) <= 0)
|
|
|
{
|
|
|
- if (received == HTTPD_SOCK_ERR_TIMEOUT)
|
|
|
+ /* Retry if timeout occurred, but give up when the client is gone (no FIN/RST after a
|
|
|
+ * Wi-Fi drop): retrying forever blocks the only HTTP server task */
|
|
|
+ if ((received == HTTPD_SOCK_ERR_TIMEOUT) && (++timeouts < UPLOAD_MAX_RECV_TIMEOUTS))
|
|
|
{
|
|
|
- /* Retry if timeout occurred */
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
@@ -746,6 +744,7 @@ static esp_err_t upload_post_handler(httpd_req_t *req)
|
|
|
/* Keep track of remaining size of
|
|
|
* the file left to be uploaded */
|
|
|
remaining -= received;
|
|
|
+ timeouts = 0;
|
|
|
}
|
|
|
|
|
|
/* Close file upon upload completion */
|