mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-22 19:00:01 +08:00
Splitter: 全局限制内存使用量,防止内存溢出
This commit is contained in:
parent
0281cb6a11
commit
b13a0f5b79
@ -13,9 +13,16 @@
|
|||||||
#include "Util/util.h"
|
#include "Util/util.h"
|
||||||
using namespace toolkit;
|
using namespace toolkit;
|
||||||
|
|
||||||
|
//协议解析最大缓存1兆数据
|
||||||
|
static constexpr size_t kMaxCacheSize = 1 * 1024 * 1024;
|
||||||
|
|
||||||
namespace mediakit {
|
namespace mediakit {
|
||||||
|
|
||||||
void HttpRequestSplitter::input(const char *data,size_t len) {
|
void HttpRequestSplitter::input(const char *data,size_t len) {
|
||||||
|
if (remainDataSize() > kMaxCacheSize) {
|
||||||
|
//缓存太多数据无法处理则上抛异常
|
||||||
|
throw std::out_of_range("remain data size is too huge:" + to_string(remainDataSize()));
|
||||||
|
}
|
||||||
const char *ptr = data;
|
const char *ptr = data;
|
||||||
if(!_remain_data.empty()){
|
if(!_remain_data.empty()){
|
||||||
_remain_data.append(data,len);
|
_remain_data.append(data,len);
|
||||||
|
@ -71,11 +71,6 @@ const char *PSDecoder::onSearchPacketTail(const char *data, size_t len) {
|
|||||||
InfoL << "解析 ps 异常: bytes=" << len
|
InfoL << "解析 ps 异常: bytes=" << len
|
||||||
<< ", exception=" << ex.what()
|
<< ", exception=" << ex.what()
|
||||||
<< ", hex=" << hexdump(data, MIN(len, 32));
|
<< ", hex=" << hexdump(data, MIN(len, 32));
|
||||||
if (remainDataSize() > 256 * 1024) {
|
|
||||||
//缓存太多数据无法处理则上抛异常
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user