mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2026-06-15 20:45:57 +08:00
AI automatically translates all comments in the code into English (#3917)
This commit is contained in:
@@ -44,7 +44,8 @@ int64_t HttpStringBody::remainSize() {
|
||||
Buffer::Ptr HttpStringBody::readData(size_t size) {
|
||||
size = MIN((size_t)remainSize(), size);
|
||||
if (!size) {
|
||||
//没有剩余字节了
|
||||
// 没有剩余字节了 [AUTO-TRANSLATED:7bbaa343]
|
||||
// No remaining bytes
|
||||
return nullptr;
|
||||
}
|
||||
auto ret = std::make_shared<BufferString>(_str, _offset, size);
|
||||
@@ -72,7 +73,8 @@ static void mmap_close(HANDLE _hfile, HANDLE _hmapping, void *_addr) {
|
||||
}
|
||||
#endif
|
||||
|
||||
//删除mmap记录
|
||||
// 删除mmap记录 [AUTO-TRANSLATED:c956201d]
|
||||
// Delete mmap record
|
||||
static void delSharedMmap(const string &file_path, char *ptr) {
|
||||
lock_guard<mutex> lck(s_mtx);
|
||||
auto it = s_shared_mmap.find(file_path);
|
||||
@@ -88,21 +90,24 @@ static std::shared_ptr<char> getSharedMmap(const string &file_path, int64_t &fil
|
||||
if (it != s_shared_mmap.end()) {
|
||||
auto ret = std::get<2>(it->second).lock();
|
||||
if (ret) {
|
||||
//命中mmap缓存
|
||||
// 命中mmap缓存 [AUTO-TRANSLATED:95131a66]
|
||||
// Hit mmap cache
|
||||
file_size = std::get<1>(it->second);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//打开文件
|
||||
// 打开文件 [AUTO-TRANSLATED:55bfe68a]
|
||||
// Open file
|
||||
std::shared_ptr<FILE> fp(fopen(file_path.data(), "rb"), [](FILE *fp) {
|
||||
if (fp) {
|
||||
fclose(fp);
|
||||
}
|
||||
});
|
||||
if (!fp) {
|
||||
//文件不存在
|
||||
// 文件不存在 [AUTO-TRANSLATED:ed160bcf]
|
||||
// File does not exist
|
||||
file_size = -1;
|
||||
return nullptr;
|
||||
}
|
||||
@@ -111,7 +116,8 @@ static std::shared_ptr<char> getSharedMmap(const string &file_path, int64_t &fil
|
||||
#if defined(_WIN32)
|
||||
auto fd = _fileno(fp.get());
|
||||
#else
|
||||
//获取文件大小
|
||||
// 获取文件大小 [AUTO-TRANSLATED:82974eea]
|
||||
// Get file size
|
||||
file_size = File::fileSize(fp.get());
|
||||
auto fd = fileno(fp.get());
|
||||
#endif
|
||||
@@ -171,7 +177,8 @@ static std::shared_ptr<char> getSharedMmap(const string &file_path, int64_t &fil
|
||||
|
||||
#if 0
|
||||
if (file_size < 10 * 1024 * 1024 && file_path.rfind(".ts") != string::npos) {
|
||||
//如果是小ts文件,那么尝试先加载到内存
|
||||
// 如果是小ts文件,那么尝试先加载到内存 [AUTO-TRANSLATED:0d96c5cd]
|
||||
// If it is a small ts file, try to load it into memory first
|
||||
auto buf = BufferRaw::create();
|
||||
buf->assign(ret.get(), file_size);
|
||||
ret.reset(buf->data(), [buf, file_path](char *ptr) {
|
||||
@@ -192,20 +199,24 @@ HttpFileBody::HttpFileBody(const string &file_path, bool use_mmap) {
|
||||
}
|
||||
|
||||
if (!_map_addr && _read_to != -1) {
|
||||
//mmap失败(且不是由于文件不存在导致的)或未执行mmap时,才进入fread逻辑分支
|
||||
// mmap失败(且不是由于文件不存在导致的)或未执行mmap时,才进入fread逻辑分支 [AUTO-TRANSLATED:8c7efed5]
|
||||
// Only enter the fread logic branch when mmap fails (and is not due to file not existing) or when mmap is not executed
|
||||
_fp.reset(fopen(file_path.data(), "rb"), [](FILE *fp) {
|
||||
if (fp) {
|
||||
fclose(fp);
|
||||
}
|
||||
});
|
||||
if (!_fp) {
|
||||
//文件不存在
|
||||
// 文件不存在 [AUTO-TRANSLATED:ed160bcf]
|
||||
// File does not exist
|
||||
_read_to = -1;
|
||||
return;
|
||||
}
|
||||
if (!_read_to) {
|
||||
//_read_to等于0时,说明还未尝试获取文件大小
|
||||
//加上该判断逻辑,在mmap失败时,可以省去一次该操作
|
||||
// _read_to等于0时,说明还未尝试获取文件大小 [AUTO-TRANSLATED:4e3ef6ca]
|
||||
// When _read_to equals 0, it means that the file size has not been attempted to be obtained yet
|
||||
// 加上该判断逻辑,在mmap失败时,可以省去一次该操作 [AUTO-TRANSLATED:b9b585de]
|
||||
// Adding this judgment logic can save one operation when mmap fails
|
||||
_read_to = File::fileSize(_fp.get());
|
||||
}
|
||||
}
|
||||
@@ -241,7 +252,8 @@ public:
|
||||
_data = map_addr.get() + offset;
|
||||
_size = size;
|
||||
}
|
||||
//返回数据长度
|
||||
// 返回数据长度 [AUTO-TRANSLATED:955f731c]
|
||||
// Return data length
|
||||
char *data() const override { return _data; }
|
||||
size_t size() const override { return _size; }
|
||||
|
||||
@@ -258,11 +270,13 @@ int64_t HttpFileBody::remainSize() {
|
||||
Buffer::Ptr HttpFileBody::readData(size_t size) {
|
||||
size = (size_t)(MIN(remainSize(), (int64_t)size));
|
||||
if (!size) {
|
||||
//没有剩余字节了
|
||||
// 没有剩余字节了 [AUTO-TRANSLATED:7bbaa343]
|
||||
// No remaining bytes
|
||||
return nullptr;
|
||||
}
|
||||
if (!_map_addr) {
|
||||
// fread模式
|
||||
// fread模式 [AUTO-TRANSLATED:c4dee2a3]
|
||||
// fread mode
|
||||
ssize_t iRead;
|
||||
auto ret = _pool.obtain2();
|
||||
ret->setCapacity(size + 1);
|
||||
@@ -271,18 +285,21 @@ Buffer::Ptr HttpFileBody::readData(size_t size) {
|
||||
} while (-1 == iRead && UV_EINTR == get_uv_error(false));
|
||||
|
||||
if (iRead > 0) {
|
||||
//读到数据了
|
||||
// 读到数据了 [AUTO-TRANSLATED:7e5ada62]
|
||||
// Data is read
|
||||
ret->setSize(iRead);
|
||||
_file_offset += iRead;
|
||||
return std::move(ret);
|
||||
}
|
||||
//读取文件异常,文件真实长度小于声明长度
|
||||
// 读取文件异常,文件真实长度小于声明长度 [AUTO-TRANSLATED:89d09f9b]
|
||||
// File reading exception, the actual length of the file is less than the declared length
|
||||
_file_offset = _read_to;
|
||||
WarnL << "read file err:" << get_uv_errmsg();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// mmap模式
|
||||
// mmap模式 [AUTO-TRANSLATED:b8d616f1]
|
||||
// mmap mode
|
||||
auto ret = std::make_shared<BufferMmap>(_map_addr, _file_offset, size);
|
||||
_file_offset += size;
|
||||
return ret;
|
||||
@@ -321,7 +338,8 @@ Buffer::Ptr HttpMultiFormBody::readData(size_t size) {
|
||||
if (_fileBody->remainSize()) {
|
||||
auto ret = _fileBody->readData(size);
|
||||
if (!ret) {
|
||||
//读取文件出现异常,提前中断
|
||||
// 读取文件出现异常,提前中断 [AUTO-TRANSLATED:5b8052d9]
|
||||
// An exception occurred while reading the file, and the process was interrupted prematurely
|
||||
_offset = _totalSize;
|
||||
} else {
|
||||
_offset += ret->size();
|
||||
|
||||
Reference in New Issue
Block a user