mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-23 03:10:04 +08:00
完善http文件获取相关代码
This commit is contained in:
parent
81199fabd4
commit
304c898a3a
@ -140,6 +140,7 @@ HttpFileBody::HttpFileBody(const string &file_path, bool use_mmap) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if (!_map_addr && _read_to != -1) {
|
if (!_map_addr && _read_to != -1) {
|
||||||
|
//mmap失败(且不是由于文件不存在导致的)或未执行mmap时,才进入fread逻辑分支
|
||||||
_fp.reset(fopen(file_path.data(), "rb"), [](FILE *fp) {
|
_fp.reset(fopen(file_path.data(), "rb"), [](FILE *fp) {
|
||||||
if (fp) {
|
if (fp) {
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
@ -150,9 +151,13 @@ HttpFileBody::HttpFileBody(const string &file_path, bool use_mmap) {
|
|||||||
_read_to = -1;
|
_read_to = -1;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (!_read_to) {
|
||||||
|
//_read_to等于0时,说明还未尝试获取文件大小
|
||||||
|
//加上该判断逻辑,在mmap失败时,可以省去一次该操作
|
||||||
_read_to = File::fileSize(_fp.get());
|
_read_to = File::fileSize(_fp.get());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void HttpFileBody::setRange(uint64_t offset, uint64_t max_size) {
|
void HttpFileBody::setRange(uint64_t offset, uint64_t max_size) {
|
||||||
CHECK((int64_t)offset <= _read_to && (int64_t)(max_size + offset) <= _read_to);
|
CHECK((int64_t)offset <= _read_to && (int64_t)(max_size + offset) <= _read_to);
|
||||||
|
Loading…
Reference in New Issue
Block a user