|
@@ -6,8 +6,6 @@
|
|
|
#include <sys/unistd.h>
|
|
#include <sys/unistd.h>
|
|
|
#include <sys/stat.h>
|
|
#include <sys/stat.h>
|
|
|
#include <dirent.h>
|
|
#include <dirent.h>
|
|
|
-#include <memory>
|
|
|
|
|
-#include <new>
|
|
|
|
|
#include "esp_err.h"
|
|
#include "esp_err.h"
|
|
|
#include "esp_log.h"
|
|
#include "esp_log.h"
|
|
|
#include "esp_http_server.h"
|
|
#include "esp_http_server.h"
|
|
@@ -23,6 +21,7 @@ static const char *TAG = "SERVER HELP";
|
|
|
|
|
|
|
|
string SUFFIX_ZW = "_tmp";
|
|
string SUFFIX_ZW = "_tmp";
|
|
|
|
|
|
|
|
|
|
+char scratch[SERVER_HELPER_SCRATCH_BUFSIZE];
|
|
|
|
|
|
|
|
bool endsWith(std::string const &str, std::string const &suffix)
|
|
bool endsWith(std::string const &str, std::string const &suffix)
|
|
|
{
|
|
{
|
|
@@ -129,19 +128,8 @@ esp_err_t send_file(httpd_req_t *req, std::string filename)
|
|
|
set_content_type_from_file(req, filename.c_str());
|
|
set_content_type_from_file(req, filename.c_str());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // Each async transfer owns its buffer; a process-global scratch array would
|
|
|
|
|
- // race if another file response is ever served from a different task.
|
|
|
|
|
- std::unique_ptr<char[]> chunkBuffer(
|
|
|
|
|
- new (std::nothrow) char[SERVER_HELPER_SCRATCH_BUFSIZE]);
|
|
|
|
|
- if (!chunkBuffer)
|
|
|
|
|
- {
|
|
|
|
|
- fclose(fd);
|
|
|
|
|
- httpd_resp_send_err(req, HTTPD_500_INTERNAL_SERVER_ERROR, "Not enough memory for file response");
|
|
|
|
|
- logSlowTransfer("buffer allocation failed");
|
|
|
|
|
- return ESP_ERR_NO_MEM;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- char *chunk = chunkBuffer.get();
|
|
|
|
|
|
|
+ /* Retrieve the pointer to scratch buffer for temporary storage */
|
|
|
|
|
+ char *chunk = scratch;
|
|
|
size_t chunksize;
|
|
size_t chunksize;
|
|
|
|
|
|
|
|
do
|
|
do
|