From c0ba2eb7b4f91611b202e877ea24f4476dec621c Mon Sep 17 00:00:00 2001 From: Dmitry Igrishin Date: Sun, 9 May 2021 16:06:50 +0300 Subject: [PATCH] Fix 4Gb limit streamed HTTP on Raspberry Pi 32bit (#1253) Commits f2198ccfac140798ee066c5a3c5235b396473205 and 4fcfe49bcce574c0aca7ab6409f81a725bf8f88c are fixed 2Gb limit, but introduced 4Gb limit on Rasperry Pi 32 bit. This is because the max value of type `size_t` is `4294967295` on this system. Furthermore, the Standard Library use `std::uintmax_t` as a type of value returned by `std::filesystem::file_size`. --- src/HttpResponse.h | 8 ++++---- src/HttpResponseData.h | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/HttpResponse.h b/src/HttpResponse.h index 3638d85..861fac5 100644 --- a/src/HttpResponse.h +++ b/src/HttpResponse.h @@ -93,7 +93,7 @@ private: /* Returns true on success, indicating that it might be feasible to write more data. * Will start timeout if stream reaches totalSize or write failure. */ - bool internalEnd(std::string_view data, size_t totalSize, bool optional, bool allowContentLength = true, bool closeConnection = false) { + bool internalEnd(std::string_view data, uintmax_t totalSize, bool optional, bool allowContentLength = true, bool closeConnection = false) { /* Write status if not already done */ writeStatus(HTTP_200_OK); @@ -375,7 +375,7 @@ public: /* Try and end the response. Returns [true, true] on success. * Starts a timeout in some cases. Returns [ok, hasResponded] */ - std::pair tryEnd(std::string_view data, size_t totalSize = 0) { + std::pair tryEnd(std::string_view data, uintmax_t totalSize = 0) { return {internalEnd(data, totalSize, true), hasResponded()}; } @@ -413,7 +413,7 @@ public: } /* Get the current byte write offset for this Http response */ - size_t getWriteOffset() { + uintmax_t getWriteOffset() { HttpResponseData *httpResponseData = getHttpResponseData(); return httpResponseData->offset; @@ -448,7 +448,7 @@ public: } /* Attach handler for writable HTTP response */ - HttpResponse *onWritable(MoveOnlyFunction &&handler) { + HttpResponse *onWritable(MoveOnlyFunction &&handler) { HttpResponseData *httpResponseData = getHttpResponseData(); httpResponseData->onWritable = std::move(handler); diff --git a/src/HttpResponseData.h b/src/HttpResponseData.h index d3483f5..ca17dc6 100644 --- a/src/HttpResponseData.h +++ b/src/HttpResponseData.h @@ -43,11 +43,11 @@ private: }; /* Per socket event handlers */ - MoveOnlyFunction onWritable; + MoveOnlyFunction onWritable; MoveOnlyFunction onAborted; MoveOnlyFunction inStream; // onData /* Outgoing offset */ - size_t offset = 0; + uintmax_t offset = 0; /* Current state (content-length sent, status sent, write called, etc */ int state = 0;