From 304c898a3a9ebf703ed26567db39a58d4d487184 Mon Sep 17 00:00:00 2001 From: ziyue <1213642868@qq.com> Date: Wed, 16 Feb 2022 16:58:13 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84http=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E7=9B=B8=E5=85=B3=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Http/HttpBody.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Http/HttpBody.cpp b/src/Http/HttpBody.cpp index 63e632eb..19e41e26 100644 --- a/src/Http/HttpBody.cpp +++ b/src/Http/HttpBody.cpp @@ -140,6 +140,7 @@ HttpFileBody::HttpFileBody(const string &file_path, bool use_mmap) { } #endif if (!_map_addr && _read_to != -1) { + //mmap失败(且不是由于文件不存在导致的)或未执行mmap时,才进入fread逻辑分支 _fp.reset(fopen(file_path.data(), "rb"), [](FILE *fp) { if (fp) { fclose(fp); @@ -150,7 +151,11 @@ HttpFileBody::HttpFileBody(const string &file_path, bool use_mmap) { _read_to = -1; return; } - _read_to = File::fileSize(_fp.get()); + if (!_read_to) { + //_read_to等于0时,说明还未尝试获取文件大小 + //加上该判断逻辑,在mmap失败时,可以省去一次该操作 + _read_to = File::fileSize(_fp.get()); + } } }