mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2026-06-29 06:12:22 +08:00
全面整理代码,去除编译警告
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* Copyright (c) 2020 The ZLMediaKit project authors. All Rights Reserved.
|
||||
*
|
||||
* This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit).
|
||||
* This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
|
||||
*
|
||||
* Use of this source code is governed by MIT license that can be found in the
|
||||
* LICENSE file in the root of the source tree. All contributing project authors
|
||||
@@ -129,7 +129,7 @@ int HlsParser::getTargetDur() const {
|
||||
return _target_dur;
|
||||
}
|
||||
|
||||
int HlsParser::getSequence() const {
|
||||
int64_t HlsParser::getSequence() const {
|
||||
return _sequence;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* Copyright (c) 2020 The ZLMediaKit project authors. All Rights Reserved.
|
||||
*
|
||||
* This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit).
|
||||
* This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
|
||||
*
|
||||
* Use of this source code is governed by MIT license that can be found in the
|
||||
* LICENSE file in the root of the source tree. All contributing project authors
|
||||
@@ -68,7 +68,7 @@ public:
|
||||
/**
|
||||
* #EXT-X-MEDIA-SEQUENCE字段值,该m3u8序号
|
||||
*/
|
||||
int getSequence() const;
|
||||
int64_t getSequence() const;
|
||||
|
||||
/**
|
||||
* 内部是否含有子m3u8
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* Copyright (c) 2020 The ZLMediaKit project authors. All Rights Reserved.
|
||||
*
|
||||
* This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit).
|
||||
* This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
|
||||
*
|
||||
* Use of this source code is governed by MIT license that can be found in the
|
||||
* LICENSE file in the root of the source tree. All contributing project authors
|
||||
@@ -12,7 +12,7 @@
|
||||
namespace mediakit {
|
||||
|
||||
HlsPlayer::HlsPlayer(const EventPoller::Ptr &poller){
|
||||
_segment.setOnSegment([this](const char *data, uint64_t len) { onPacket(data, len); });
|
||||
_segment.setOnSegment([this](const char *data, size_t len) { onPacket(data, len); });
|
||||
setPoller(poller ? poller : EventPollerPool::Instance().getPoller());
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ void HlsPlayer::play_l(){
|
||||
teardown_l(SockException(Err_shutdown, "所有hls url都尝试播放失败!"));
|
||||
return;
|
||||
}
|
||||
float playTimeOutSec = (*this)[Client::kTimeoutMS].as<int>() / 1000.0;
|
||||
float playTimeOutSec = (*this)[Client::kTimeoutMS].as<int>() / 1000.0f;
|
||||
setMethod("GET");
|
||||
if(!(*this)[kNetAdapter].empty()) {
|
||||
setNetAdapter((*this)[kNetAdapter]);
|
||||
@@ -83,7 +83,7 @@ void HlsPlayer::playNextTs(bool force){
|
||||
strongSelf->playNextTs(true);
|
||||
} else {
|
||||
//下一个切片慢点播放
|
||||
strongSelf->_timer_ts.reset(new Timer(delay / 1000.0, [weakSelf, delay]() {
|
||||
strongSelf->_timer_ts.reset(new Timer(delay / 1000.0f, [weakSelf, delay]() {
|
||||
auto strongSelf = weakSelf.lock();
|
||||
if (!strongSelf) {
|
||||
return false;
|
||||
@@ -94,7 +94,7 @@ void HlsPlayer::playNextTs(bool force){
|
||||
}
|
||||
});
|
||||
|
||||
_http_ts_player->setOnPacket([weakSelf](const char *data, uint64_t len) {
|
||||
_http_ts_player->setOnPacket([weakSelf](const char *data, size_t len) {
|
||||
auto strongSelf = weakSelf.lock();
|
||||
if (!strongSelf) {
|
||||
return;
|
||||
@@ -153,7 +153,7 @@ void HlsPlayer::onParsed(bool is_m3u8_inner,int64_t sequence,const map<int,ts_se
|
||||
}
|
||||
}
|
||||
|
||||
int64_t HlsPlayer::onResponseHeader(const string &status, const HttpClient::HttpHeader &headers) {
|
||||
size_t HlsPlayer::onResponseHeader(const string &status, const HttpClient::HttpHeader &headers) {
|
||||
if (status != "200" && status != "206") {
|
||||
//失败
|
||||
teardown_l(SockException(Err_shutdown, StrPrinter << "bad http status code:" + status));
|
||||
@@ -164,7 +164,7 @@ int64_t HlsPlayer::onResponseHeader(const string &status, const HttpClient::Http
|
||||
return -1;
|
||||
}
|
||||
|
||||
void HlsPlayer::onResponseBody(const char *buf, int64_t size, int64_t recvedSize, int64_t totalSize) {
|
||||
void HlsPlayer::onResponseBody(const char *buf, size_t size, size_t recvedSize, size_t totalSize) {
|
||||
if (recvedSize == size) {
|
||||
//刚开始
|
||||
_m3u8.clear();
|
||||
@@ -186,9 +186,9 @@ void HlsPlayer::onResponseCompleted() {
|
||||
|
||||
float HlsPlayer::delaySecond(){
|
||||
if (HlsParser::isM3u8() && HlsParser::getTargetDur() > 0) {
|
||||
return HlsParser::getTargetDur();
|
||||
return (float)HlsParser::getTargetDur();
|
||||
}
|
||||
return 1;
|
||||
return 1.0f;
|
||||
}
|
||||
|
||||
void HlsPlayer::onDisconnect(const SockException &ex) {
|
||||
@@ -232,7 +232,7 @@ void HlsPlayer::playDelay(){
|
||||
}, getPoller()));
|
||||
}
|
||||
|
||||
void HlsPlayer::onPacket_l(const char *data, uint64_t len){
|
||||
void HlsPlayer::onPacket_l(const char *data, size_t len){
|
||||
_segment.input(data,len);
|
||||
}
|
||||
|
||||
@@ -246,7 +246,7 @@ void HlsPlayerImp::setOnPacket(const TSSegment::onSegment &cb){
|
||||
_on_ts = cb;
|
||||
}
|
||||
|
||||
void HlsPlayerImp::onPacket(const char *data,uint64_t len) {
|
||||
void HlsPlayerImp::onPacket(const char *data,size_t len) {
|
||||
if (_on_ts) {
|
||||
_on_ts(data, len);
|
||||
}
|
||||
@@ -276,7 +276,7 @@ void HlsPlayerImp::onPlayResult(const SockException &ex) {
|
||||
|
||||
weak_ptr<HlsPlayerImp> weakSelf = dynamic_pointer_cast<HlsPlayerImp>(shared_from_this());
|
||||
//每50毫秒执行一次
|
||||
_timer = std::make_shared<Timer>(0.05, [weakSelf]() {
|
||||
_timer = std::make_shared<Timer>(0.05f, [weakSelf]() {
|
||||
auto strongSelf = weakSelf.lock();
|
||||
if (!strongSelf) {
|
||||
return false;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* Copyright (c) 2020 The ZLMediaKit project authors. All Rights Reserved.
|
||||
*
|
||||
* This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit).
|
||||
* This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
|
||||
*
|
||||
* Use of this source code is governed by MIT license that can be found in the
|
||||
* LICENSE file in the root of the source tree. All contributing project authors
|
||||
@@ -46,7 +46,7 @@ protected:
|
||||
* @param data ts数据负载
|
||||
* @param len ts包长度
|
||||
*/
|
||||
virtual void onPacket(const char *data, uint64_t len) = 0;
|
||||
virtual void onPacket(const char *data, size_t len) = 0;
|
||||
|
||||
private:
|
||||
/**
|
||||
@@ -63,7 +63,7 @@ private:
|
||||
* @return 返回后续content的长度;-1:后续数据全是content;>=0:固定长度content
|
||||
* 需要指出的是,在http头中带有Content-Length字段时,该返回值无效
|
||||
*/
|
||||
int64_t onResponseHeader(const string &status,const HttpHeader &headers) override;
|
||||
size_t onResponseHeader(const string &status,const HttpHeader &headers) override;
|
||||
/**
|
||||
* 收到http conten数据
|
||||
* @param buf 数据指针
|
||||
@@ -71,7 +71,7 @@ private:
|
||||
* @param recvedSize 已收数据大小(包含本次数据大小),当其等于totalSize时将触发onResponseCompleted回调
|
||||
* @param totalSize 总数据大小
|
||||
*/
|
||||
void onResponseBody(const char *buf,int64_t size,int64_t recvedSize,int64_t totalSize) override;
|
||||
void onResponseBody(const char *buf,size_t size,size_t recvedSize,size_t totalSize) override;
|
||||
|
||||
/**
|
||||
* 接收http回复完毕,
|
||||
@@ -98,7 +98,7 @@ private:
|
||||
void playNextTs(bool force = false);
|
||||
void teardown_l(const SockException &ex);
|
||||
void play_l();
|
||||
void onPacket_l(const char *data, uint64_t len);
|
||||
void onPacket_l(const char *data, size_t len);
|
||||
|
||||
private:
|
||||
struct UrlComp {
|
||||
@@ -131,7 +131,7 @@ public:
|
||||
void setOnPacket(const TSSegment::onSegment &cb);
|
||||
|
||||
private:
|
||||
void onPacket(const char *data, uint64_t len) override;
|
||||
void onPacket(const char *data, size_t len) override;
|
||||
void onAllTrackReady() override;
|
||||
void onPlayResult(const SockException &ex) override;
|
||||
vector<Track::Ptr> getTracks(bool trackReady = true) const override;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
|
||||
*
|
||||
* This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit).
|
||||
* This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
|
||||
*
|
||||
* Use of this source code is governed by MIT license that can be found in the
|
||||
* LICENSE file in the root of the source tree. All contributing project authors
|
||||
@@ -26,11 +26,12 @@ namespace mediakit {
|
||||
HttpStringBody::HttpStringBody(const string &str){
|
||||
_str = str;
|
||||
}
|
||||
uint64_t HttpStringBody::remainSize() {
|
||||
|
||||
size_t HttpStringBody::remainSize() {
|
||||
return _str.size() - _offset;
|
||||
}
|
||||
|
||||
Buffer::Ptr HttpStringBody::readData(uint32_t size) {
|
||||
Buffer::Ptr HttpStringBody::readData(size_t size) {
|
||||
size = MIN(remainSize(),size);
|
||||
if(!size){
|
||||
//没有剩余字节了
|
||||
@@ -55,11 +56,19 @@ HttpFileBody::HttpFileBody(const string &filePath){
|
||||
}
|
||||
}
|
||||
|
||||
HttpFileBody::HttpFileBody(const std::shared_ptr<FILE> &fp, uint64_t offset, uint64_t max_size) {
|
||||
HttpFileBody::HttpFileBody(const std::shared_ptr<FILE> &fp, size_t offset, size_t max_size) {
|
||||
init(fp,offset,max_size);
|
||||
}
|
||||
|
||||
void HttpFileBody::init(const std::shared_ptr<FILE> &fp,uint64_t offset,uint64_t max_size){
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#define fseek64 _fseeki64
|
||||
#define ftell64 _ftelli64
|
||||
#else
|
||||
#define fseek64 fseek
|
||||
#define ftell64 ftell
|
||||
#endif
|
||||
|
||||
void HttpFileBody::init(const std::shared_ptr<FILE> &fp,size_t offset, size_t max_size){
|
||||
_fp = fp;
|
||||
_max_size = max_size;
|
||||
#ifdef ENABLE_MMAP
|
||||
@@ -85,7 +94,7 @@ void HttpFileBody::init(const std::shared_ptr<FILE> &fp,uint64_t offset,uint64_t
|
||||
#endif
|
||||
if(!_map_addr && offset && fp.get()){
|
||||
//未映射,那么fseek设置偏移量
|
||||
fseek(fp.get(), offset, SEEK_SET);
|
||||
fseek64(fp.get(), offset, SEEK_SET);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,30 +102,30 @@ void HttpFileBody::init(const std::shared_ptr<FILE> &fp,uint64_t offset,uint64_t
|
||||
class BufferMmap : public Buffer{
|
||||
public:
|
||||
typedef std::shared_ptr<BufferMmap> Ptr;
|
||||
BufferMmap(const std::shared_ptr<char> &map_addr,uint64_t offset,int size){
|
||||
BufferMmap(const std::shared_ptr<char> &map_addr, size_t offset, size_t size) {
|
||||
_map_addr = map_addr;
|
||||
_data = map_addr.get() + offset;
|
||||
_size = size;
|
||||
};
|
||||
virtual ~BufferMmap(){};
|
||||
}
|
||||
~BufferMmap() override{};
|
||||
//返回数据长度
|
||||
char *data() const override {
|
||||
return _data;
|
||||
}
|
||||
uint32_t size() const override{
|
||||
size_t size() const override{
|
||||
return _size;
|
||||
}
|
||||
private:
|
||||
std::shared_ptr<char> _map_addr;
|
||||
char *_data;
|
||||
uint32_t _size;
|
||||
size_t _size;
|
||||
};
|
||||
|
||||
uint64_t HttpFileBody::remainSize() {
|
||||
size_t HttpFileBody::remainSize() {
|
||||
return _max_size - _offset;
|
||||
}
|
||||
|
||||
Buffer::Ptr HttpFileBody::readData(uint32_t size) {
|
||||
Buffer::Ptr HttpFileBody::readData(size_t size) {
|
||||
size = MIN(remainSize(),size);
|
||||
if(!size){
|
||||
//没有剩余字节了
|
||||
@@ -124,7 +133,7 @@ Buffer::Ptr HttpFileBody::readData(uint32_t size) {
|
||||
}
|
||||
if(!_map_addr){
|
||||
//fread模式
|
||||
int iRead;
|
||||
size_t iRead;
|
||||
auto ret = _pool.obtain();
|
||||
ret->setCapacity(size + 1);
|
||||
do{
|
||||
@@ -171,11 +180,11 @@ HttpMultiFormBody::HttpMultiFormBody(const HttpArgs &args,const string &filePath
|
||||
_totalSize = _bodyPrefix.size() + _bodySuffix.size() + _fileBody->remainSize();
|
||||
}
|
||||
|
||||
uint64_t HttpMultiFormBody::remainSize() {
|
||||
size_t HttpMultiFormBody::remainSize() {
|
||||
return _totalSize - _offset;
|
||||
}
|
||||
|
||||
Buffer::Ptr HttpMultiFormBody::readData(uint32_t size){
|
||||
Buffer::Ptr HttpMultiFormBody::readData(size_t size){
|
||||
if(_bodyPrefix.size()){
|
||||
auto ret = std::make_shared<BufferString>(_bodyPrefix);
|
||||
_offset += _bodyPrefix.size();
|
||||
@@ -212,11 +221,11 @@ string HttpMultiFormBody::multiFormBodySuffix(const string &boundary){
|
||||
return body;
|
||||
}
|
||||
|
||||
uint64_t HttpMultiFormBody::fileSize(FILE *fp) {
|
||||
auto current = ftell(fp);
|
||||
fseek(fp,0L,SEEK_END); /* 定位到文件末尾 */
|
||||
auto end = ftell(fp); /* 得到文件大小 */
|
||||
fseek(fp,current,SEEK_SET);
|
||||
size_t HttpMultiFormBody::fileSize(FILE *fp) {
|
||||
auto current = ftell64(fp);
|
||||
fseek64(fp, 0L, SEEK_END); /* 定位到文件末尾 */
|
||||
auto end = ftell64(fp); /* 得到文件大小 */
|
||||
fseek64(fp, current, SEEK_SET);
|
||||
return end - current;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
|
||||
*
|
||||
* This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit).
|
||||
* This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
|
||||
*
|
||||
* Use of this source code is governed by MIT license that can be found in the
|
||||
* LICENSE file in the root of the source tree. All contributing project authors
|
||||
@@ -33,52 +33,33 @@ namespace mediakit {
|
||||
class HttpBody : public std::enable_shared_from_this<HttpBody>{
|
||||
public:
|
||||
typedef std::shared_ptr<HttpBody> Ptr;
|
||||
HttpBody(){
|
||||
// _async_read_thread = WorkThreadPool::Instance().getPoller();
|
||||
}
|
||||
HttpBody(){}
|
||||
|
||||
virtual ~HttpBody(){}
|
||||
|
||||
/**
|
||||
* 剩余数据大小,如果返回>=INT64_MAX, 那么就不设置content-length
|
||||
* 剩余数据大小,如果返回-1, 那么就不设置content-length
|
||||
*/
|
||||
virtual uint64_t remainSize() { return 0;};
|
||||
virtual size_t remainSize() { return 0;};
|
||||
|
||||
/**
|
||||
* 读取一定字节数,返回大小可能小于size
|
||||
* @param size 请求大小
|
||||
* @return 字节对象,如果读完了,那么请返回nullptr
|
||||
*/
|
||||
virtual Buffer::Ptr readData(uint32_t size) { return nullptr;};
|
||||
virtual Buffer::Ptr readData(size_t size) { return nullptr;};
|
||||
|
||||
/**
|
||||
* 异步请求读取一定字节数,返回大小可能小于size
|
||||
* @param size 请求大小
|
||||
* @param cb 回调函数
|
||||
*/
|
||||
virtual void readDataAsync(uint32_t size,const function<void(const Buffer::Ptr &buf)> &cb){
|
||||
#if 0
|
||||
if(size >= remainSize()){
|
||||
//假如剩余数据很小,那么同步获取(为了优化性能)
|
||||
cb(readData(size));
|
||||
return;
|
||||
}
|
||||
//如果是大文件,那么后台读取
|
||||
weak_ptr<HttpBody> weakSelf = shared_from_this();
|
||||
_async_read_thread->async([cb,size,weakSelf](){
|
||||
auto strongSelf = weakSelf.lock();
|
||||
if(strongSelf){
|
||||
cb(strongSelf->readData(size));
|
||||
}
|
||||
});
|
||||
#else
|
||||
virtual void readDataAsync(size_t size,const function<void(const Buffer::Ptr &buf)> &cb){
|
||||
//由于unix和linux是通过mmap的方式读取文件,所以把读文件操作放在后台线程并不能提高性能
|
||||
//反而会由于频繁的线程切换导致性能降低以及延时增加,所以我们默认同步获取文件内容
|
||||
//(其实并没有读,拷贝文件数据时在内核态完成文件读)
|
||||
cb(readData(size));
|
||||
#endif
|
||||
}
|
||||
private:
|
||||
// EventPoller::Ptr _async_read_thread;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -89,11 +70,12 @@ public:
|
||||
typedef std::shared_ptr<HttpStringBody> Ptr;
|
||||
HttpStringBody(const string &str);
|
||||
virtual ~HttpStringBody(){}
|
||||
uint64_t remainSize() override ;
|
||||
Buffer::Ptr readData(uint32_t size) override ;
|
||||
size_t remainSize() override;
|
||||
Buffer::Ptr readData(size_t size) override ;
|
||||
|
||||
private:
|
||||
size_t _offset = 0;
|
||||
mutable string _str;
|
||||
uint64_t _offset = 0;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -109,18 +91,20 @@ public:
|
||||
* @param offset 相对文件头的偏移量
|
||||
* @param max_size 最大读取字节数,未判断是否大于文件真实大小
|
||||
*/
|
||||
HttpFileBody(const std::shared_ptr<FILE> &fp,uint64_t offset,uint64_t max_size);
|
||||
HttpFileBody(const std::shared_ptr<FILE> &fp,size_t offset,size_t max_size);
|
||||
HttpFileBody(const string &file_path);
|
||||
~HttpFileBody(){};
|
||||
|
||||
uint64_t remainSize() override ;
|
||||
Buffer::Ptr readData(uint32_t size) override;
|
||||
size_t remainSize() override ;
|
||||
Buffer::Ptr readData(size_t size) override;
|
||||
|
||||
private:
|
||||
void init(const std::shared_ptr<FILE> &fp,uint64_t offset,uint64_t max_size);
|
||||
void init(const std::shared_ptr<FILE> &fp,size_t offset,size_t max_size);
|
||||
|
||||
private:
|
||||
size_t _max_size;
|
||||
size_t _offset = 0;
|
||||
std::shared_ptr<FILE> _fp;
|
||||
uint64_t _max_size;
|
||||
uint64_t _offset = 0;
|
||||
std::shared_ptr<char> _map_addr;
|
||||
ResourcePool<BufferRaw> _pool;
|
||||
};
|
||||
@@ -142,18 +126,20 @@ public:
|
||||
*/
|
||||
HttpMultiFormBody(const HttpArgs &args,const string &filePath,const string &boundary = "0xKhTmLbOuNdArY");
|
||||
virtual ~HttpMultiFormBody(){}
|
||||
uint64_t remainSize() override ;
|
||||
Buffer::Ptr readData(uint32_t size) override;
|
||||
size_t remainSize() override ;
|
||||
Buffer::Ptr readData(size_t size) override;
|
||||
|
||||
public:
|
||||
static string multiFormBodyPrefix(const HttpArgs &args,const string &boundary,const string &fileName);
|
||||
static string multiFormBodySuffix(const string &boundary);
|
||||
static uint64_t fileSize(FILE *fp);
|
||||
static size_t fileSize(FILE *fp);
|
||||
static string multiFormContentType(const string &boundary);
|
||||
|
||||
private:
|
||||
size_t _offset = 0;
|
||||
size_t _totalSize;
|
||||
string _bodyPrefix;
|
||||
string _bodySuffix;
|
||||
uint64_t _offset = 0;
|
||||
uint64_t _totalSize;
|
||||
HttpFileBody::Ptr _fileBody;
|
||||
};
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
|
||||
*
|
||||
* This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit).
|
||||
* This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
|
||||
*
|
||||
* Use of this source code is governed by MIT license that can be found in the
|
||||
* LICENSE file in the root of the source tree. All contributing project authors
|
||||
@@ -13,7 +13,7 @@
|
||||
|
||||
namespace mediakit{
|
||||
|
||||
const char *HttpChunkedSplitter::onSearchPacketTail(const char *data, uint64_t len) {
|
||||
const char *HttpChunkedSplitter::onSearchPacketTail(const char *data, size_t len) {
|
||||
auto pos = strstr(data,"\r\n");
|
||||
if(!pos){
|
||||
return nullptr;
|
||||
@@ -21,11 +21,11 @@ const char *HttpChunkedSplitter::onSearchPacketTail(const char *data, uint64_t l
|
||||
return pos + 2;
|
||||
}
|
||||
|
||||
void HttpChunkedSplitter::onRecvContent(const char *data, uint64_t len) {
|
||||
void HttpChunkedSplitter::onRecvContent(const char *data, size_t len) {
|
||||
onRecvChunk(data,len - 2);
|
||||
}
|
||||
|
||||
int64_t HttpChunkedSplitter::onRecvHeader(const char *data, uint64_t len) {
|
||||
size_t HttpChunkedSplitter::onRecvHeader(const char *data, size_t len) {
|
||||
string str(data,len - 2);
|
||||
int ret;
|
||||
sscanf(str.data(),"%X",&ret);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
|
||||
*
|
||||
* This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit).
|
||||
* This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
|
||||
*
|
||||
* Use of this source code is governed by MIT license that can be found in the
|
||||
* LICENSE file in the root of the source tree. All contributing project authors
|
||||
@@ -21,22 +21,25 @@ public:
|
||||
/**
|
||||
* len == 0时代表结束
|
||||
*/
|
||||
typedef std::function<void (const char *data,uint64_t len)> onChunkData;
|
||||
typedef std::function<void (const char *data,size_t len)> onChunkData;
|
||||
|
||||
HttpChunkedSplitter(const onChunkData &cb){
|
||||
_onChunkData = cb;
|
||||
};
|
||||
~HttpChunkedSplitter() override {} ;
|
||||
|
||||
protected:
|
||||
int64_t onRecvHeader(const char *data,uint64_t len) override;
|
||||
void onRecvContent(const char *data,uint64_t len) override;
|
||||
const char *onSearchPacketTail(const char *data,uint64_t len) override;
|
||||
size_t onRecvHeader(const char *data,size_t len) override;
|
||||
void onRecvContent(const char *data,size_t len) override;
|
||||
const char *onSearchPacketTail(const char *data,size_t len) override;
|
||||
|
||||
protected:
|
||||
virtual void onRecvChunk(const char *data,uint64_t len){
|
||||
virtual void onRecvChunk(const char *data,size_t len){
|
||||
if(_onChunkData){
|
||||
_onChunkData(data,len);
|
||||
}
|
||||
};
|
||||
|
||||
private:
|
||||
onChunkData _onChunkData;
|
||||
};
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
|
||||
*
|
||||
* This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit).
|
||||
* This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
|
||||
*
|
||||
* Use of this source code is governed by MIT license that can be found in the
|
||||
* LICENSE file in the root of the source tree. All contributing project authors
|
||||
@@ -129,7 +129,7 @@ void HttpClient::onErr(const SockException &ex) {
|
||||
onDisconnect(ex);
|
||||
}
|
||||
|
||||
int64_t HttpClient::onRecvHeader(const char *data, uint64_t len) {
|
||||
size_t HttpClient::onRecvHeader(const char *data, size_t len) {
|
||||
_parser.Parse(data);
|
||||
if(_parser.Url() == "302" || _parser.Url() == "301"){
|
||||
auto newUrl = _parser["Location"];
|
||||
@@ -156,7 +156,7 @@ int64_t HttpClient::onRecvHeader(const char *data, uint64_t len) {
|
||||
if(_parser["Transfer-Encoding"] == "chunked"){
|
||||
//如果Transfer-Encoding字段等于chunked,则认为后续的content是不限制长度的
|
||||
_totalBodySize = -1;
|
||||
_chunkedSplitter = std::make_shared<HttpChunkedSplitter>([this](const char *data,uint64_t len){
|
||||
_chunkedSplitter = std::make_shared<HttpChunkedSplitter>([this](const char *data,size_t len){
|
||||
if(len > 0){
|
||||
auto recvedBodySize = _recvedBodySize + len;
|
||||
onResponseBody(data, len, recvedBodySize, INT64_MAX);
|
||||
@@ -181,7 +181,7 @@ int64_t HttpClient::onRecvHeader(const char *data, uint64_t len) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
void HttpClient::onRecvContent(const char *data, uint64_t len) {
|
||||
void HttpClient::onRecvContent(const char *data, size_t len) {
|
||||
if(_chunkedSplitter){
|
||||
_chunkedSplitter->input(data,len);
|
||||
return;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
|
||||
*
|
||||
* This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit).
|
||||
* This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
|
||||
*
|
||||
* Use of this source code is governed by MIT license that can be found in the
|
||||
* LICENSE file in the root of the source tree. All contributing project authors
|
||||
@@ -110,7 +110,7 @@ protected:
|
||||
* @return 返回后续content的长度;-1:后续数据全是content;>=0:固定长度content
|
||||
* 需要指出的是,在http头中带有Content-Length字段时,该返回值无效
|
||||
*/
|
||||
virtual int64_t onResponseHeader(const string &status,const HttpHeader &headers){
|
||||
virtual size_t onResponseHeader(const string &status,const HttpHeader &headers){
|
||||
DebugL << status;
|
||||
//无Content-Length字段时默认后面全是content
|
||||
return -1;
|
||||
@@ -123,7 +123,7 @@ protected:
|
||||
* @param recvedSize 已收数据大小(包含本次数据大小),当其等于totalSize时将触发onResponseCompleted回调
|
||||
* @param totalSize 总数据大小
|
||||
*/
|
||||
virtual void onResponseBody(const char *buf,int64_t size,int64_t recvedSize,int64_t totalSize){
|
||||
virtual void onResponseBody(const char *buf,size_t size,size_t recvedSize,size_t totalSize){
|
||||
DebugL << size << " " << recvedSize << " " << totalSize;
|
||||
};
|
||||
|
||||
@@ -149,19 +149,23 @@ protected:
|
||||
virtual bool onRedirectUrl(const string &url,bool temporary){ return true;};
|
||||
|
||||
//HttpRequestSplitter override
|
||||
int64_t onRecvHeader(const char *data,uint64_t len) override ;
|
||||
void onRecvContent(const char *data,uint64_t len) override;
|
||||
size_t onRecvHeader(const char *data,size_t len) override;
|
||||
void onRecvContent(const char *data,size_t len) override;
|
||||
|
||||
protected:
|
||||
virtual void onConnect(const SockException &ex) override;
|
||||
virtual void onRecv(const Buffer::Ptr &pBuf) override;
|
||||
virtual void onErr(const SockException &ex) override;
|
||||
virtual void onFlush() override;
|
||||
virtual void onManager() override;
|
||||
|
||||
private:
|
||||
void onResponseCompleted_l();
|
||||
void checkCookie(HttpHeader &headers );
|
||||
|
||||
protected:
|
||||
bool _isHttps;
|
||||
|
||||
private:
|
||||
string _url;
|
||||
HttpHeader _header;
|
||||
@@ -169,8 +173,8 @@ private:
|
||||
string _method;
|
||||
string _path;
|
||||
//recv
|
||||
int64_t _recvedBodySize;
|
||||
int64_t _totalBodySize;
|
||||
size_t _recvedBodySize;
|
||||
size_t _totalBodySize;
|
||||
Parser _parser;
|
||||
string _lastHost;
|
||||
Ticker _aliveTicker;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
|
||||
*
|
||||
* This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit).
|
||||
* This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
|
||||
*
|
||||
* Use of this source code is governed by MIT license that can be found in the
|
||||
* LICENSE file in the root of the source tree. All contributing project authors
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
|
||||
*
|
||||
* This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit).
|
||||
* This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
|
||||
*
|
||||
* Use of this source code is governed by MIT license that can be found in the
|
||||
* LICENSE file in the root of the source tree. All contributing project authors
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
|
||||
*
|
||||
* This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit).
|
||||
* This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
|
||||
*
|
||||
* Use of this source code is governed by MIT license that can be found in the
|
||||
* LICENSE file in the root of the source tree. All contributing project authors
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
|
||||
*
|
||||
* This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit).
|
||||
* This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
|
||||
*
|
||||
* Use of this source code is governed by MIT license that can be found in the
|
||||
* LICENSE file in the root of the source tree. All contributing project authors
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
|
||||
*
|
||||
* This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit).
|
||||
* This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
|
||||
*
|
||||
* Use of this source code is governed by MIT license that can be found in the
|
||||
* LICENSE file in the root of the source tree. All contributing project authors
|
||||
@@ -25,7 +25,7 @@ void HttpCookie::setPath(const string &path){
|
||||
void HttpCookie::setHost(const string &host){
|
||||
_host = host;
|
||||
}
|
||||
static uint32_t timeStrToInt(const string &date){
|
||||
static time_t timeStrToInt(const string &date){
|
||||
struct tm tt;
|
||||
strptime(date.data(),"%a, %b %d %Y %H:%M:%S %Z",&tt);
|
||||
return mktime(&tt);
|
||||
@@ -34,7 +34,6 @@ void HttpCookie::setExpires(const string &expires,const string &server_date){
|
||||
_expire = timeStrToInt(expires);
|
||||
if(!server_date.empty()){
|
||||
_expire = time(NULL) + (_expire - timeStrToInt(server_date));
|
||||
// DebugL << (timeStrToInt(expires) - timeStrToInt(server_date)) / 60;
|
||||
}
|
||||
}
|
||||
void HttpCookie::setKeyVal(const string &key,const string &val){
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
|
||||
*
|
||||
* This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit).
|
||||
* This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
|
||||
*
|
||||
* Use of this source code is governed by MIT license that can be found in the
|
||||
* LICENSE file in the root of the source tree. All contributing project authors
|
||||
@@ -42,9 +42,9 @@ public:
|
||||
private:
|
||||
string _host;
|
||||
string _path = "/";
|
||||
uint32_t _expire = 0;
|
||||
string _key;
|
||||
string _val;
|
||||
time_t _expire = 0;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
|
||||
*
|
||||
* This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit).
|
||||
* This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
|
||||
*
|
||||
* Use of this source code is governed by MIT license that can be found in the
|
||||
* LICENSE file in the root of the source tree. All contributing project authors
|
||||
@@ -75,7 +75,7 @@ INSTANCE_IMP(HttpCookieManager);
|
||||
|
||||
HttpCookieManager::HttpCookieManager() {
|
||||
//定时删除过期的cookie,防止内存膨胀
|
||||
_timer = std::make_shared<Timer>(10,[this](){
|
||||
_timer = std::make_shared<Timer>(10.0f,[this](){
|
||||
onManager();
|
||||
return true;
|
||||
}, nullptr);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
|
||||
*
|
||||
* This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit).
|
||||
* This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
|
||||
*
|
||||
* Use of this source code is governed by MIT license that can be found in the
|
||||
* LICENSE file in the root of the source tree. All contributing project authors
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
|
||||
*
|
||||
* This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit).
|
||||
* This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
|
||||
*
|
||||
* Use of this source code is governed by MIT license that can be found in the
|
||||
* LICENSE file in the root of the source tree. All contributing project authors
|
||||
@@ -47,7 +47,7 @@ void HttpDownloader::startDownload(const string& url, const string& filePath,boo
|
||||
sendRequest(url,timeOutSecond);
|
||||
}
|
||||
|
||||
int64_t HttpDownloader::onResponseHeader(const string& status,const HttpHeader& headers) {
|
||||
size_t HttpDownloader::onResponseHeader(const string& status,const HttpHeader& headers) {
|
||||
if(status != "200" && status != "206"){
|
||||
//失败
|
||||
shutdown(SockException(Err_shutdown,StrPrinter << "Http Status:" << status));
|
||||
@@ -56,7 +56,7 @@ int64_t HttpDownloader::onResponseHeader(const string& status,const HttpHeader&
|
||||
return -1;
|
||||
}
|
||||
|
||||
void HttpDownloader::onResponseBody(const char* buf, int64_t size, int64_t recvedSize, int64_t totalSize) {
|
||||
void HttpDownloader::onResponseBody(const char* buf, size_t size, size_t recvedSize, size_t totalSize) {
|
||||
if(_saveFile){
|
||||
fwrite(buf,size,1,_saveFile);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
|
||||
*
|
||||
* This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit).
|
||||
* This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
|
||||
*
|
||||
* Use of this source code is governed by MIT license that can be found in the
|
||||
* LICENSE file in the root of the source tree. All contributing project authors
|
||||
@@ -31,11 +31,12 @@ public:
|
||||
_onResult = cb;
|
||||
}
|
||||
private:
|
||||
int64_t onResponseHeader(const string &status,const HttpHeader &headers) override;
|
||||
void onResponseBody(const char *buf,int64_t size,int64_t recvedSize,int64_t totalSize) override;
|
||||
size_t onResponseHeader(const string &status, const HttpHeader &headers) override;
|
||||
void onResponseBody(const char *buf, size_t size, size_t recvedSize, size_t totalSize) override;
|
||||
void onResponseCompleted() override;
|
||||
void onDisconnect(const SockException &ex) override;
|
||||
void closeFile();
|
||||
|
||||
private:
|
||||
FILE *_saveFile = nullptr;
|
||||
string _filePath;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
|
||||
*
|
||||
* This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit).
|
||||
* This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
|
||||
*
|
||||
* Use of this source code is governed by MIT license that can be found in the
|
||||
* LICENSE file in the root of the source tree. All contributing project authors
|
||||
@@ -564,9 +564,9 @@ void HttpResponseInvokerImp::responseFile(const StrCaseMap &requestHeader,
|
||||
}
|
||||
|
||||
auto &strRange = const_cast<StrCaseMap &>(requestHeader)["Range"];
|
||||
int64_t iRangeStart = 0;
|
||||
int64_t iRangeEnd = 0;
|
||||
int64_t fileSize = HttpMultiFormBody::fileSize(fp.get());
|
||||
size_t iRangeStart = 0;
|
||||
size_t iRangeEnd = 0;
|
||||
size_t fileSize = HttpMultiFormBody::fileSize(fp.get());
|
||||
|
||||
int code;
|
||||
if (strRange.size() == 0) {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
|
||||
*
|
||||
* This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit).
|
||||
* This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
|
||||
*
|
||||
* Use of this source code is governed by MIT license that can be found in the
|
||||
* LICENSE file in the root of the source tree. All contributing project authors
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
|
||||
*
|
||||
* This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit).
|
||||
* This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
|
||||
*
|
||||
* Use of this source code is governed by MIT license that can be found in the
|
||||
* LICENSE file in the root of the source tree. All contributing project authors
|
||||
@@ -15,7 +15,7 @@ using namespace toolkit;
|
||||
|
||||
namespace mediakit {
|
||||
|
||||
void HttpRequestSplitter::input(const char *data,uint64_t len) {
|
||||
void HttpRequestSplitter::input(const char *data,size_t len) {
|
||||
const char *ptr = data;
|
||||
if(!_remain_data.empty()){
|
||||
_remain_data.append(data,len);
|
||||
@@ -44,7 +44,7 @@ void HttpRequestSplitter::input(const char *data,uint64_t len) {
|
||||
}
|
||||
//_content_len == 0,这是请求头
|
||||
const char *header_ptr = ptr;
|
||||
int64_t header_size = index - ptr;
|
||||
auto header_size = index - ptr;
|
||||
ptr = index;
|
||||
_remain_data_size = len - (ptr - data);
|
||||
_content_len = onRecvHeader(header_ptr, header_size);
|
||||
@@ -101,7 +101,7 @@ void HttpRequestSplitter::input(const char *data,uint64_t len) {
|
||||
_remain_data.clear();
|
||||
}
|
||||
|
||||
void HttpRequestSplitter::setContentLen(int64_t content_len) {
|
||||
void HttpRequestSplitter::setContentLen(size_t content_len) {
|
||||
_content_len = content_len;
|
||||
}
|
||||
|
||||
@@ -111,7 +111,7 @@ void HttpRequestSplitter::reset() {
|
||||
_remain_data.clear();
|
||||
}
|
||||
|
||||
const char *HttpRequestSplitter::onSearchPacketTail(const char *data,uint64_t len) {
|
||||
const char *HttpRequestSplitter::onSearchPacketTail(const char *data,size_t len) {
|
||||
auto pos = strstr(data,"\r\n\r\n");
|
||||
if(pos == nullptr){
|
||||
return nullptr;
|
||||
@@ -119,7 +119,7 @@ const char *HttpRequestSplitter::onSearchPacketTail(const char *data,uint64_t le
|
||||
return pos + 4;
|
||||
}
|
||||
|
||||
int64_t HttpRequestSplitter::remainDataSize() {
|
||||
size_t HttpRequestSplitter::remainDataSize() {
|
||||
return _remain_data_size;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
|
||||
*
|
||||
* This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit).
|
||||
* This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
|
||||
*
|
||||
* Use of this source code is governed by MIT license that can be found in the
|
||||
* LICENSE file in the root of the source tree. All contributing project authors
|
||||
@@ -28,7 +28,8 @@ public:
|
||||
* @param data 需要添加的数据
|
||||
* @param len 数据长度
|
||||
*/
|
||||
virtual void input(const char *data,uint64_t len);
|
||||
virtual void input(const char *data,size_t len);
|
||||
|
||||
protected:
|
||||
/**
|
||||
* 收到请求头
|
||||
@@ -40,7 +41,7 @@ protected:
|
||||
* 0 : 代表为后面数据还是请求头,
|
||||
* >0 : 代表后面数据为固定长度content,此时将缓存content并等到所有content接收完毕一次性通过onRecvContent函数回调出去
|
||||
*/
|
||||
virtual int64_t onRecvHeader(const char *data,uint64_t len) = 0;
|
||||
virtual size_t onRecvHeader(const char *data,size_t len) = 0;
|
||||
|
||||
/**
|
||||
* 收到content分片或全部数据
|
||||
@@ -48,7 +49,7 @@ protected:
|
||||
* @param data content分片或全部数据
|
||||
* @param len 数据长度
|
||||
*/
|
||||
virtual void onRecvContent(const char *data,uint64_t len) {};
|
||||
virtual void onRecvContent(const char *data,size_t len) {};
|
||||
|
||||
/**
|
||||
* 判断数据中是否有包尾
|
||||
@@ -56,12 +57,12 @@ protected:
|
||||
* @param len 数据长度
|
||||
* @return nullptr代表未找到包位,否则返回包尾指针
|
||||
*/
|
||||
virtual const char *onSearchPacketTail(const char *data, uint64_t len);
|
||||
virtual const char *onSearchPacketTail(const char *data, size_t len);
|
||||
|
||||
/**
|
||||
* 设置content len
|
||||
*/
|
||||
void setContentLen(int64_t content_len);
|
||||
void setContentLen(size_t content_len);
|
||||
|
||||
/**
|
||||
* 恢复初始设置
|
||||
@@ -71,11 +72,12 @@ protected:
|
||||
/**
|
||||
* 剩余数据大小
|
||||
*/
|
||||
int64_t remainDataSize();
|
||||
size_t remainDataSize();
|
||||
|
||||
private:
|
||||
size_t _content_len = 0;
|
||||
size_t _remain_data_size = 0;
|
||||
BufferLikeString _remain_data;
|
||||
int64_t _content_len = 0;
|
||||
int64_t _remain_data_size = 0;
|
||||
};
|
||||
|
||||
} /* namespace mediakit */
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
|
||||
*
|
||||
* This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit).
|
||||
* This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
|
||||
*
|
||||
* Use of this source code is governed by MIT license that can be found in the
|
||||
* LICENSE file in the root of the source tree. All contributing project authors
|
||||
@@ -19,13 +19,13 @@ HttpRequester::~HttpRequester(){
|
||||
|
||||
}
|
||||
|
||||
int64_t HttpRequester::onResponseHeader(const string &status,const HttpHeader &headers) {
|
||||
size_t HttpRequester::onResponseHeader(const string &status,const HttpHeader &headers) {
|
||||
_strRecvBody.clear();
|
||||
//无Content-Length字段时默认后面没有content
|
||||
return 0;
|
||||
}
|
||||
|
||||
void HttpRequester::onResponseBody(const char *buf,int64_t size,int64_t recvedSize,int64_t totalSize) {
|
||||
void HttpRequester::onResponseBody(const char *buf,size_t size,size_t recvedSize,size_t totalSize) {
|
||||
_strRecvBody.append(buf,size);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
|
||||
*
|
||||
* This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit).
|
||||
* This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
|
||||
*
|
||||
* Use of this source code is governed by MIT license that can be found in the
|
||||
* LICENSE file in the root of the source tree. All contributing project authors
|
||||
@@ -26,8 +26,8 @@ public:
|
||||
void startRequester(const string &url,const HttpRequesterResult &onResult,float timeOutSecond = 10);
|
||||
void clear() override ;
|
||||
private:
|
||||
int64_t onResponseHeader(const string &status,const HttpHeader &headers) override;
|
||||
void onResponseBody(const char *buf,int64_t size,int64_t recvedSize,int64_t totalSize) override;
|
||||
size_t onResponseHeader(const string &status,const HttpHeader &headers) override;
|
||||
void onResponseBody(const char *buf,size_t size,size_t recvedSize,size_t totalSize) override;
|
||||
void onResponseCompleted() override;
|
||||
void onDisconnect(const SockException &ex) override;
|
||||
private:
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
|
||||
*
|
||||
* This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit).
|
||||
* This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
|
||||
*
|
||||
* Use of this source code is governed by MIT license that can be found in the
|
||||
* LICENSE file in the root of the source tree. All contributing project authors
|
||||
@@ -31,15 +31,15 @@ HttpSession::~HttpSession() {
|
||||
TraceP(this);
|
||||
}
|
||||
|
||||
void HttpSession::Handle_Req_HEAD(int64_t &content_len){
|
||||
void HttpSession::Handle_Req_HEAD(size_t &content_len){
|
||||
//暂时全部返回200 OK,因为HTTP GET存在按需生成流的操作,所以不能按照HTTP GET的流程返回
|
||||
//如果直接返回404,那么又会导致按需生成流的逻辑失效,所以HTTP HEAD在静态文件或者已存在资源时才有效
|
||||
//对于按需生成流的直播场景并不适用
|
||||
sendResponse(200, true);
|
||||
}
|
||||
|
||||
int64_t HttpSession::onRecvHeader(const char *header,uint64_t len) {
|
||||
typedef void (HttpSession::*HttpCMDHandle)(int64_t &);
|
||||
size_t HttpSession::onRecvHeader(const char *header,size_t len) {
|
||||
typedef void (HttpSession::*HttpCMDHandle)(size_t &);
|
||||
static unordered_map<string, HttpCMDHandle> s_func_map;
|
||||
static onceToken token([]() {
|
||||
s_func_map.emplace("GET",&HttpSession::Handle_Req_GET);
|
||||
@@ -61,7 +61,7 @@ int64_t HttpSession::onRecvHeader(const char *header,uint64_t len) {
|
||||
_origin = _parser["Origin"];
|
||||
|
||||
//默认后面数据不是content而是header
|
||||
int64_t content_len = 0;
|
||||
size_t content_len = 0;
|
||||
auto &fun = it->second;
|
||||
try {
|
||||
(this->*fun)(content_len);
|
||||
@@ -75,7 +75,7 @@ int64_t HttpSession::onRecvHeader(const char *header,uint64_t len) {
|
||||
return content_len;
|
||||
}
|
||||
|
||||
void HttpSession::onRecvContent(const char *data,uint64_t len) {
|
||||
void HttpSession::onRecvContent(const char *data,size_t len) {
|
||||
if(_contentCallBack){
|
||||
if(!_contentCallBack(data,len)){
|
||||
_contentCallBack = nullptr;
|
||||
@@ -271,8 +271,8 @@ bool HttpSession::checkLiveStreamFMP4(const function<void()> &cb){
|
||||
//本对象已经销毁
|
||||
return;
|
||||
}
|
||||
int i = 0;
|
||||
int size = fmp4_list->size();
|
||||
size_t i = 0;
|
||||
auto size = fmp4_list->size();
|
||||
fmp4_list->for_each([&](const FMP4Packet::Ptr &ts) {
|
||||
strong_self->onWrite(ts, ++i == size);
|
||||
});
|
||||
@@ -311,8 +311,8 @@ bool HttpSession::checkLiveStreamTS(const function<void()> &cb){
|
||||
//本对象已经销毁
|
||||
return;
|
||||
}
|
||||
int i = 0;
|
||||
int size = ts_list->size();
|
||||
size_t i = 0;
|
||||
auto size = ts_list->size();
|
||||
ts_list->for_each([&](const TSPacket::Ptr &ts) {
|
||||
strong_self->onWrite(ts, ++i == size);
|
||||
});
|
||||
@@ -353,15 +353,15 @@ bool HttpSession::checkLiveStreamFlv(const function<void()> &cb){
|
||||
});
|
||||
}
|
||||
|
||||
void HttpSession::Handle_Req_GET(int64_t &content_len) {
|
||||
void HttpSession::Handle_Req_GET(size_t &content_len) {
|
||||
Handle_Req_GET_l(content_len, true);
|
||||
}
|
||||
|
||||
void HttpSession::Handle_Req_GET_l(int64_t &content_len, bool sendBody) {
|
||||
void HttpSession::Handle_Req_GET_l(size_t &content_len, bool sendBody) {
|
||||
//先看看是否为WebSocket请求
|
||||
if (checkWebSocket()) {
|
||||
content_len = -1;
|
||||
_contentCallBack = [this](const char *data, uint64_t len) {
|
||||
_contentCallBack = [this](const char *data, size_t len) {
|
||||
WebSocketSplitter::decode((uint8_t *) data, len);
|
||||
//_contentCallBack是可持续的,后面还要处理后续数据
|
||||
return true;
|
||||
@@ -506,7 +506,7 @@ void HttpSession::sendResponse(int code,
|
||||
GET_CONFIG(uint32_t,keepAliveSec,Http::kKeepAliveSecond);
|
||||
|
||||
//body默认为空
|
||||
int64_t size = 0;
|
||||
size_t size = 0;
|
||||
if (body && body->remainSize()) {
|
||||
//有body,获取body大小
|
||||
size = body->remainSize();
|
||||
@@ -515,7 +515,7 @@ void HttpSession::sendResponse(int code,
|
||||
if(no_content_length){
|
||||
//http-flv直播是Keep-Alive类型
|
||||
bClose = false;
|
||||
}else if(size >= INT64_MAX){
|
||||
}else if(size >= INT64_MAX || size < 0 ){
|
||||
//不固定长度的body,那么发送完body后应该关闭socket,以便浏览器做下载完毕的判断
|
||||
bClose = true;
|
||||
}
|
||||
@@ -642,10 +642,10 @@ bool HttpSession::emitHttpEvent(bool doInvoke){
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void HttpSession::Handle_Req_POST(int64_t &content_len) {
|
||||
GET_CONFIG(uint64_t,maxReqSize,Http::kMaxReqSize);
|
||||
void HttpSession::Handle_Req_POST(size_t &content_len) {
|
||||
GET_CONFIG(size_t,maxReqSize,Http::kMaxReqSize);
|
||||
|
||||
int64_t totalContentLen = _parser["Content-Length"].empty() ? -1 : atoll(_parser["Content-Length"].data());
|
||||
size_t totalContentLen = _parser["Content-Length"].empty() ? -1 : atoll(_parser["Content-Length"].data());
|
||||
|
||||
if(totalContentLen == 0){
|
||||
//content为空
|
||||
@@ -658,7 +658,7 @@ void HttpSession::Handle_Req_POST(int64_t &content_len) {
|
||||
//返回固定长度的content
|
||||
content_len = totalContentLen;
|
||||
auto parserCopy = _parser;
|
||||
_contentCallBack = [this,parserCopy](const char *data,uint64_t len){
|
||||
_contentCallBack = [this,parserCopy](const char *data,size_t len){
|
||||
//恢复http头
|
||||
_parser = parserCopy;
|
||||
//设置content
|
||||
@@ -674,10 +674,10 @@ void HttpSession::Handle_Req_POST(int64_t &content_len) {
|
||||
//返回不固定长度的content
|
||||
content_len = -1;
|
||||
auto parserCopy = _parser;
|
||||
std::shared_ptr<uint64_t> recvedContentLen = std::make_shared<uint64_t>(0);
|
||||
std::shared_ptr<size_t> recvedContentLen = std::make_shared<uint64_t>(0);
|
||||
bool bClose = !strcasecmp(_parser["Connection"].data(),"close");
|
||||
|
||||
_contentCallBack = [this,parserCopy,totalContentLen,recvedContentLen,bClose](const char *data,uint64_t len){
|
||||
_contentCallBack = [this,parserCopy,totalContentLen,recvedContentLen,bClose](const char *data,size_t len){
|
||||
*(recvedContentLen) += len;
|
||||
|
||||
onRecvUnlimitedContent(parserCopy,data,len,totalContentLen,*(recvedContentLen));
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
|
||||
*
|
||||
* This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit).
|
||||
* This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
|
||||
*
|
||||
* Use of this source code is governed by MIT license that can be found in the
|
||||
* LICENSE file in the root of the source tree. All contributing project authors
|
||||
@@ -57,8 +57,8 @@ protected:
|
||||
std::shared_ptr<FlvMuxer> getSharedPtr() override;
|
||||
|
||||
//HttpRequestSplitter override
|
||||
int64_t onRecvHeader(const char *data,uint64_t len) override;
|
||||
void onRecvContent(const char *data,uint64_t len) override;
|
||||
size_t onRecvHeader(const char *data,size_t len) override;
|
||||
void onRecvContent(const char *data,size_t len) override;
|
||||
|
||||
/**
|
||||
* 重载之用于处理不定长度的content
|
||||
@@ -71,9 +71,9 @@ protected:
|
||||
*/
|
||||
virtual void onRecvUnlimitedContent(const Parser &header,
|
||||
const char *data,
|
||||
uint64_t len,
|
||||
uint64_t totalSize,
|
||||
uint64_t recvedSize){
|
||||
size_t len,
|
||||
size_t totalSize,
|
||||
size_t recvedSize){
|
||||
shutdown(SockException(Err_shutdown,"http post content is too huge,default closed"));
|
||||
}
|
||||
|
||||
@@ -101,10 +101,10 @@ protected:
|
||||
void onWebSocketDecodeComplete(const WebSocketHeader &header_in) override;
|
||||
|
||||
private:
|
||||
void Handle_Req_GET(int64_t &content_len);
|
||||
void Handle_Req_GET_l(int64_t &content_len, bool sendBody);
|
||||
void Handle_Req_POST(int64_t &content_len);
|
||||
void Handle_Req_HEAD(int64_t &content_len);
|
||||
void Handle_Req_GET(size_t &content_len);
|
||||
void Handle_Req_GET_l(size_t &content_len, bool sendBody);
|
||||
void Handle_Req_POST(size_t &content_len);
|
||||
void Handle_Req_HEAD(size_t &content_len);
|
||||
|
||||
bool checkLiveStream(const string &schema, const string &url_suffix, const function<void(const MediaSource::Ptr &src)> &cb);
|
||||
|
||||
@@ -135,7 +135,7 @@ private:
|
||||
TSMediaSource::RingType::RingReader::Ptr _ts_reader;
|
||||
FMP4MediaSource::RingType::RingReader::Ptr _fmp4_reader;
|
||||
//处理content数据的callback
|
||||
function<bool (const char *data,uint64_t len) > _contentCallBack;
|
||||
function<bool (const char *data,size_t len) > _contentCallBack;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* Copyright (c) 2020 The ZLMediaKit project authors. All Rights Reserved.
|
||||
*
|
||||
* This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit).
|
||||
* This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
|
||||
*
|
||||
* Use of this source code is governed by MIT license that can be found in the
|
||||
* LICENSE file in the root of the source tree. All contributing project authors
|
||||
@@ -13,13 +13,13 @@ namespace mediakit {
|
||||
|
||||
HttpTSPlayer::HttpTSPlayer(const EventPoller::Ptr &poller, bool split_ts){
|
||||
_split_ts = split_ts;
|
||||
_segment.setOnSegment([this](const char *data, uint64_t len) { onPacket(data, len); });
|
||||
_segment.setOnSegment([this](const char *data, size_t len) { onPacket(data, len); });
|
||||
setPoller(poller ? poller : EventPollerPool::Instance().getPoller());
|
||||
}
|
||||
|
||||
HttpTSPlayer::~HttpTSPlayer() {}
|
||||
|
||||
int64_t HttpTSPlayer::onResponseHeader(const string &status, const HttpClient::HttpHeader &headers) {
|
||||
size_t HttpTSPlayer::onResponseHeader(const string &status, const HttpClient::HttpHeader &headers) {
|
||||
_status = status;
|
||||
if (status != "200" && status != "206") {
|
||||
//http状态码不符合预期
|
||||
@@ -35,7 +35,7 @@ int64_t HttpTSPlayer::onResponseHeader(const string &status, const HttpClient::H
|
||||
return -1;
|
||||
}
|
||||
|
||||
void HttpTSPlayer::onResponseBody(const char *buf, int64_t size, int64_t recvedSize, int64_t totalSize) {
|
||||
void HttpTSPlayer::onResponseBody(const char *buf, size_t size, size_t recvedSize, size_t totalSize) {
|
||||
if (_status != "200" && _status != "206") {
|
||||
return;
|
||||
}
|
||||
@@ -68,7 +68,7 @@ void HttpTSPlayer::onDisconnect(const SockException &ex) {
|
||||
}
|
||||
}
|
||||
|
||||
void HttpTSPlayer::onPacket(const char *data, uint64_t len) {
|
||||
void HttpTSPlayer::onPacket(const char *data, size_t len) {
|
||||
if (_on_segment) {
|
||||
_on_segment(data, len);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* Copyright (c) 2020 The ZLMediaKit project authors. All Rights Reserved.
|
||||
*
|
||||
* This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit).
|
||||
* This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
|
||||
*
|
||||
* Use of this source code is governed by MIT license that can be found in the
|
||||
* LICENSE file in the root of the source tree. All contributing project authors
|
||||
@@ -33,13 +33,13 @@ public:
|
||||
|
||||
protected:
|
||||
///HttpClient override///
|
||||
int64_t onResponseHeader(const string &status,const HttpHeader &headers) override;
|
||||
void onResponseBody(const char *buf,int64_t size,int64_t recvedSize,int64_t totalSize) override;
|
||||
size_t onResponseHeader(const string &status,const HttpHeader &headers) override;
|
||||
void onResponseBody(const char *buf,size_t size,size_t recvedSize,size_t totalSize) override;
|
||||
void onResponseCompleted() override;
|
||||
void onDisconnect(const SockException &ex) override ;
|
||||
|
||||
//收到ts包
|
||||
virtual void onPacket(const char *data, uint64_t len);
|
||||
virtual void onPacket(const char *data, size_t len);
|
||||
|
||||
private:
|
||||
//是否为mpegts负载
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
|
||||
*
|
||||
* This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit).
|
||||
* This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
|
||||
*
|
||||
* Use of this source code is governed by MIT license that can be found in the
|
||||
* LICENSE file in the root of the source tree. All contributing project authors
|
||||
@@ -32,7 +32,7 @@ class HttpWsClient;
|
||||
template <typename ClientType,WebSocketHeader::Type DataType>
|
||||
class ClientTypeImp : public ClientType {
|
||||
public:
|
||||
typedef function<int(const Buffer::Ptr &buf)> onBeforeSendCB;
|
||||
typedef function<size_t (const Buffer::Ptr &buf)> onBeforeSendCB;
|
||||
friend class HttpWsClient<ClientType,DataType>;
|
||||
|
||||
template<typename ...ArgsType>
|
||||
@@ -43,7 +43,7 @@ protected:
|
||||
/**
|
||||
* 发送前拦截并打包为websocket协议
|
||||
*/
|
||||
int send(Buffer::Ptr buf) override{
|
||||
size_t send(Buffer::Ptr buf) override{
|
||||
if(_beforeSendCB){
|
||||
return _beforeSendCB(buf);
|
||||
}
|
||||
@@ -120,7 +120,7 @@ protected:
|
||||
* @return 返回后续content的长度;-1:后续数据全是content;>=0:固定长度content
|
||||
* 需要指出的是,在http头中带有Content-Length字段时,该返回值无效
|
||||
*/
|
||||
int64_t onResponseHeader(const string &status,const HttpHeader &headers) override {
|
||||
size_t onResponseHeader(const string &status,const HttpHeader &headers) override {
|
||||
if(status == "101"){
|
||||
auto Sec_WebSocket_Accept = encodeBase64(SHA1::encode_bin(_Sec_WebSocket_Key + "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"));
|
||||
if(Sec_WebSocket_Accept == const_cast<HttpHeader &>(headers)["Sec-WebSocket-Accept"]){
|
||||
@@ -147,7 +147,7 @@ protected:
|
||||
/**
|
||||
* 接收websocket负载数据
|
||||
*/
|
||||
void onResponseBody(const char *buf,int64_t size,int64_t recvedSize,int64_t totalSize) override{
|
||||
void onResponseBody(const char *buf,size_t size,size_t recvedSize,size_t totalSize) override{
|
||||
if(_onRecv){
|
||||
//完成websocket握手后,拦截websocket数据并解析
|
||||
_onRecv(buf, size);
|
||||
@@ -220,7 +220,7 @@ protected:
|
||||
* @param len 负载数据长度
|
||||
* @param recved 已接收数据长度(包含本次数据长度),等于header._payload_len时则接受完毕
|
||||
*/
|
||||
void onWebSocketDecodePayload(const WebSocketHeader &header, const uint8_t *ptr, uint64_t len, uint64_t recved) override{
|
||||
void onWebSocketDecodePayload(const WebSocketHeader &header, const uint8_t *ptr, size_t len, size_t recved) override{
|
||||
_payload_section.append((char *)ptr,len);
|
||||
}
|
||||
|
||||
@@ -316,7 +316,7 @@ private:
|
||||
//触发连接成功事件
|
||||
_delegate.onConnect(ex);
|
||||
//拦截websocket数据接收
|
||||
_onRecv = [this](const char *data, int len){
|
||||
_onRecv = [this](const char *data, size_t len){
|
||||
//解析websocket数据包
|
||||
this->WebSocketSplitter::decode((uint8_t *)data, len);
|
||||
};
|
||||
@@ -337,7 +337,7 @@ private:
|
||||
|
||||
private:
|
||||
string _Sec_WebSocket_Key;
|
||||
function<void(const char *data, int len)> _onRecv;
|
||||
function<void(const char *data, size_t len)> _onRecv;
|
||||
ClientTypeImp<ClientType,DataType> &_delegate;
|
||||
string _payload_section;
|
||||
string _payload_cache;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
|
||||
*
|
||||
* This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit).
|
||||
* This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
|
||||
*
|
||||
* Use of this source code is governed by MIT license that can be found in the
|
||||
* LICENSE file in the root of the source tree. All contributing project authors
|
||||
@@ -19,7 +19,7 @@
|
||||
*/
|
||||
class SendInterceptor{
|
||||
public:
|
||||
typedef function<int(const Buffer::Ptr &buf)> onBeforeSendCB;
|
||||
typedef function<size_t (const Buffer::Ptr &buf)> onBeforeSendCB;
|
||||
SendInterceptor() = default;
|
||||
virtual ~SendInterceptor() = default;
|
||||
virtual void setOnBeforeSendCB(const onBeforeSendCB &cb) = 0;
|
||||
@@ -35,7 +35,7 @@ public:
|
||||
typedef std::shared_ptr<TcpSessionTypeImp> Ptr;
|
||||
|
||||
TcpSessionTypeImp(const Parser &header, const HttpSession &parent, const Socket::Ptr &pSock) :
|
||||
_identifier(parent.getIdentifier()), TcpSessionType(pSock) {}
|
||||
TcpSessionType(pSock), _identifier(parent.getIdentifier()) {}
|
||||
|
||||
~TcpSessionTypeImp() {}
|
||||
|
||||
@@ -53,7 +53,7 @@ protected:
|
||||
* @param buf 需要截取的数据
|
||||
* @return 数据字节数
|
||||
*/
|
||||
int send(Buffer::Ptr buf) override {
|
||||
size_t send(Buffer::Ptr buf) override {
|
||||
if (_beforeSendCB) {
|
||||
return _beforeSendCB(buf);
|
||||
}
|
||||
@@ -65,8 +65,8 @@ protected:
|
||||
}
|
||||
|
||||
private:
|
||||
onBeforeSendCB _beforeSendCB;
|
||||
string _identifier;
|
||||
onBeforeSendCB _beforeSendCB;
|
||||
};
|
||||
|
||||
template <typename TcpSessionType>
|
||||
@@ -157,7 +157,7 @@ protected:
|
||||
/**
|
||||
* 收到websocket数据包负载
|
||||
*/
|
||||
void onWebSocketDecodePayload(const WebSocketHeader &packet,const uint8_t *ptr,uint64_t len,uint64_t recved) override {
|
||||
void onWebSocketDecodePayload(const WebSocketHeader &packet,const uint8_t *ptr,size_t len,size_t recved) override {
|
||||
_payload_section.append((char *)ptr,len);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
|
||||
*
|
||||
* This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit).
|
||||
* This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
|
||||
*
|
||||
* Use of this source code is governed by MIT license that can be found in the
|
||||
* LICENSE file in the root of the source tree. All contributing project authors
|
||||
@@ -53,7 +53,7 @@ do{ \
|
||||
} \
|
||||
}while(0) \
|
||||
|
||||
void WebSocketSplitter::decode(uint8_t *data,uint64_t len) {
|
||||
void WebSocketSplitter::decode(uint8_t *data,size_t len) {
|
||||
uint8_t *ptr = data;
|
||||
if(!_got_header) {
|
||||
//还没有获取数据头
|
||||
@@ -107,9 +107,9 @@ begin_decode:
|
||||
|
||||
//进入后面逻辑代表已经获取到了webSocket协议头,
|
||||
|
||||
uint64_t remain = len - (ptr - data);
|
||||
auto remain = len - (ptr - data);
|
||||
if(remain > 0){
|
||||
uint64_t payload_slice_len = remain;
|
||||
auto payload_slice_len = remain;
|
||||
if(payload_slice_len + _payload_offset > _payload_len){
|
||||
payload_slice_len = _payload_len - _payload_offset;
|
||||
}
|
||||
@@ -138,7 +138,7 @@ begin_decode:
|
||||
_remain_data.clear();
|
||||
}
|
||||
|
||||
void WebSocketSplitter::onPayloadData(uint8_t *data, uint64_t len) {
|
||||
void WebSocketSplitter::onPayloadData(uint8_t *data, size_t len) {
|
||||
if(_mask_flag){
|
||||
for(int i = 0; i < len ; ++i,++data){
|
||||
*(data) ^= _mask[(i + _mask_offset) % 4];
|
||||
@@ -150,7 +150,7 @@ void WebSocketSplitter::onPayloadData(uint8_t *data, uint64_t len) {
|
||||
|
||||
void WebSocketSplitter::encode(const WebSocketHeader &header,const Buffer::Ptr &buffer) {
|
||||
string ret;
|
||||
uint64_t len = buffer ? buffer->size() : 0;
|
||||
auto len = buffer ? buffer->size() : 0;
|
||||
uint8_t byte = header._fin << 7 | ((header._reserved & 0x07) << 4) | (header._opcode & 0x0F) ;
|
||||
ret.push_back(byte);
|
||||
|
||||
@@ -164,7 +164,7 @@ void WebSocketSplitter::encode(const WebSocketHeader &header,const Buffer::Ptr &
|
||||
byte |= 126;
|
||||
ret.push_back(byte);
|
||||
|
||||
auto len_low = htons(len);
|
||||
uint16_t len_low = htons((uint16_t)len);
|
||||
ret.append((char *)&len_low,2);
|
||||
}else{
|
||||
byte |= 127;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
|
||||
*
|
||||
* This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit).
|
||||
* This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
|
||||
*
|
||||
* Use of this source code is governed by MIT license that can be found in the
|
||||
* LICENSE file in the root of the source tree. All contributing project authors
|
||||
@@ -60,7 +60,7 @@ public:
|
||||
uint8_t _reserved;
|
||||
Type _opcode;
|
||||
bool _mask_flag;
|
||||
uint64_t _payload_len;
|
||||
size_t _payload_len;
|
||||
vector<uint8_t > _mask;
|
||||
};
|
||||
|
||||
@@ -71,7 +71,7 @@ public:
|
||||
|
||||
template<typename ...ARGS>
|
||||
WebSocketBuffer(WebSocketHeader::Type headType, bool fin, ARGS &&...args)
|
||||
: _head_type(headType), _fin(fin), BufferString(std::forward<ARGS>(args)...) {}
|
||||
: BufferString(std::forward<ARGS>(args)...), _fin(fin), _head_type(headType){}
|
||||
|
||||
~WebSocketBuffer() override {}
|
||||
|
||||
@@ -80,8 +80,8 @@ public:
|
||||
bool isFinished() const { return _fin; };
|
||||
|
||||
private:
|
||||
WebSocketHeader::Type _head_type;
|
||||
bool _fin;
|
||||
WebSocketHeader::Type _head_type;
|
||||
};
|
||||
|
||||
class WebSocketSplitter : public WebSocketHeader{
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
|
||||
*
|
||||
* This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit).
|
||||
* This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
|
||||
*
|
||||
* Use of this source code is governed by MIT license that can be found in the
|
||||
* LICENSE file in the root of the source tree. All contributing project authors
|
||||
@@ -70,7 +70,7 @@ string strCoding::UrlEncode(const string &str) {
|
||||
string strCoding::UrlDecode(const string &str) {
|
||||
string output = "";
|
||||
char tmp[2];
|
||||
int i = 0, len = str.length();
|
||||
size_t i = 0, len = str.length();
|
||||
while (i < len) {
|
||||
if (str[i] == '%') {
|
||||
if(i > len - 3){
|
||||
@@ -138,10 +138,10 @@ string strCoding::GB2312ToUTF8(const string &str) {
|
||||
auto len = str.size();
|
||||
auto pText = str.data();
|
||||
char buf[4] = { 0 };
|
||||
int nLength = len * 3;
|
||||
auto nLength = len * 3;
|
||||
char* pOut = new char[nLength];
|
||||
memset(pOut, 0, nLength);
|
||||
int i = 0, j = 0;
|
||||
size_t i = 0, j = 0;
|
||||
while (i < len)
|
||||
{
|
||||
//如果是英文直接复制就可以
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
|
||||
*
|
||||
* This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit).
|
||||
* This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
|
||||
*
|
||||
* Use of this source code is governed by MIT license that can be found in the
|
||||
* LICENSE file in the root of the source tree. All contributing project authors
|
||||
|
||||
Reference in New Issue
Block a user