From 960309e615830f15fbfd75241c3d7944186a93d3 Mon Sep 17 00:00:00 2001 From: An Tao Date: Sun, 9 Aug 2020 19:20:51 +0800 Subject: [PATCH] Resolve an issue when sending big files (>=2gB) on Windows (#529) --- lib/src/HttpRequestImpl.cc | 3 +-- lib/src/HttpResponseImpl.cc | 10 ++++++---- lib/src/StaticFileRouter.cc | 1 + trantor | 2 +- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/src/HttpRequestImpl.cc b/lib/src/HttpRequestImpl.cc index c38d514e..ed67dbea 100644 --- a/lib/src/HttpRequestImpl.cc +++ b/lib/src/HttpRequestImpl.cc @@ -317,8 +317,7 @@ void HttpRequestImpl::appendToBuffer(trantor::MsgBuffer *output) const auto len = snprintf(buf, sizeof(buf), "Content-Length: %lu\r\n", - static_cast(content.length() + - content_.length())); + content.length() + content_.length()); output->append(buf, len); if (contentTypeString_.empty()) { diff --git a/lib/src/HttpResponseImpl.cc b/lib/src/HttpResponseImpl.cc index fc37eb83..ecebdec3 100644 --- a/lib/src/HttpResponseImpl.cc +++ b/lib/src/HttpResponseImpl.cc @@ -22,7 +22,9 @@ #include #include #include - +#ifdef _WIN32 +#define stat _stati64 +#endif using namespace trantor; using namespace drogon; @@ -271,7 +273,7 @@ void HttpResponseImpl::makeHeaderString(trantor::MsgBuffer &buffer) len = snprintf(buffer.beginWrite(), buffer.writableBytes(), "Content-Length: %lu\r\n", - static_cast(bodyLength)); + bodyLength); } else { @@ -283,8 +285,8 @@ void HttpResponseImpl::makeHeaderString(trantor::MsgBuffer &buffer) } len = snprintf(buffer.beginWrite(), buffer.writableBytes(), - "Content-Length: %lu\r\n", - static_cast(filestat.st_size)); + "Content-Length: %lld\r\n", + filestat.st_size); } buffer.hasWritten(len); if (headers_.find("Connection") == headers_.end()) diff --git a/lib/src/StaticFileRouter.cc b/lib/src/StaticFileRouter.cc index 0598bee5..a7f06004 100644 --- a/lib/src/StaticFileRouter.cc +++ b/lib/src/StaticFileRouter.cc @@ -23,6 +23,7 @@ #ifndef _WIN32 #include #else +#define stat _stati64 #define S_ISREG(m) (((m)&0170000) == (0100000)) #define S_ISDIR(m) (((m)&0170000) == (0040000)) #endif diff --git a/trantor b/trantor index 13c659a7..6ed38a0a 160000 --- a/trantor +++ b/trantor @@ -1 +1 @@ -Subproject commit 13c659a7e0ae2ae2e96f50f726d77c483b861dd8 +Subproject commit 6ed38a0a1e9baef9bf68e7952962d8f9425fa749