mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-26 04:31:37 +08:00
完善http超时管理
This commit is contained in:
parent
d9dea060d3
commit
c2b11e3868
@ -35,7 +35,7 @@ HttpClient::HttpClient(){
|
||||
}
|
||||
HttpClient::~HttpClient(){
|
||||
}
|
||||
void HttpClient::sendRequest(const string &strUrl){
|
||||
void HttpClient::sendRequest(const string &strUrl,float fTimeOutSec){
|
||||
auto protocol = FindField(strUrl.data(), NULL , "://");
|
||||
uint16_t defaultPort;
|
||||
bool isHttps;
|
||||
@ -84,7 +84,7 @@ void HttpClient::sendRequest(const string &strUrl){
|
||||
|
||||
if(!alive() || bChanged){
|
||||
//InfoL << "reconnet:" << _lastHost;
|
||||
startConnect(host, port);
|
||||
startConnect(host, port,fTimeOutSec);
|
||||
}else{
|
||||
SockException ex;
|
||||
onConnect(ex);
|
||||
|
@ -68,7 +68,7 @@ public:
|
||||
typedef std::shared_ptr<HttpClient> Ptr;
|
||||
HttpClient();
|
||||
virtual ~HttpClient();
|
||||
virtual void sendRequest(const string &url);
|
||||
virtual void sendRequest(const string &url,float fTimeOutSec);
|
||||
void clear(){
|
||||
_header.clear();
|
||||
_body.clear();
|
||||
|
@ -37,8 +37,8 @@ HttpClientImp::HttpClientImp() {
|
||||
HttpClientImp::~HttpClientImp() {
|
||||
}
|
||||
|
||||
void HttpClientImp::sendRequest(const string& url) {
|
||||
HttpClient::sendRequest(url);
|
||||
void HttpClientImp::sendRequest(const string& url,float fTimeOutSec) {
|
||||
HttpClient::sendRequest(url,fTimeOutSec);
|
||||
if(_isHttps){
|
||||
#ifndef ENABLE_OPENSSL
|
||||
shutdown();
|
||||
|
@ -41,7 +41,7 @@ public:
|
||||
typedef std::shared_ptr<HttpClientImp> Ptr;
|
||||
HttpClientImp();
|
||||
virtual ~HttpClientImp();
|
||||
virtual void sendRequest(const string &url) override;
|
||||
virtual void sendRequest(const string &url,float fTimeOutSec) override;
|
||||
|
||||
#if defined(__GNUC__) && (__GNUC__ < 5)
|
||||
void public_onRecvBytes(const char *data,int len){
|
||||
|
@ -41,7 +41,7 @@ HttpDownloader::~HttpDownloader() {
|
||||
closeFile();
|
||||
}
|
||||
|
||||
void HttpDownloader::startDownload(const string& url, const string& filePath,bool bAppend,uint32_t timeOutSecond) {
|
||||
void HttpDownloader::startDownload(const string& url, const string& filePath,bool bAppend,float timeOutSecond) {
|
||||
_filePath = filePath;
|
||||
_timeOutSecond = timeOutSecond;
|
||||
_downloadTicker.resetTime();
|
||||
@ -64,7 +64,7 @@ void HttpDownloader::startDownload(const string& url, const string& filePath,boo
|
||||
addHeader("Range", StrPrinter << "bytes=" << currentLen << "-" << endl);
|
||||
}
|
||||
setMethod("GET");
|
||||
sendRequest(url);
|
||||
sendRequest(url,timeOutSecond);
|
||||
}
|
||||
|
||||
void HttpDownloader::onResponseHeader(const string& status,const HttpHeader& headers) {
|
||||
|
@ -39,11 +39,10 @@ public:
|
||||
HttpDownloader();
|
||||
virtual ~HttpDownloader();
|
||||
//开始下载文件,默认断点续传方式下载
|
||||
void startDownload(const string &url,const string &filePath = "",bool bAppend = false,uint32_t timeOutSecond = 10 );
|
||||
void startDownload(const string &url,const onDownloadResult &cb,uint32_t timeOutSecond = 10){
|
||||
_timeOutSecond = timeOutSecond;
|
||||
void startDownload(const string &url,const string &filePath = "",bool bAppend = false, float timeOutSecond = 10 );
|
||||
void startDownload(const string &url,const onDownloadResult &cb,float timeOutSecond = 10){
|
||||
setOnResult(cb);
|
||||
startDownload(url);
|
||||
startDownload(url,"",false,timeOutSecond);
|
||||
}
|
||||
void setOnResult(const onDownloadResult &cb){
|
||||
_onResult = cb;
|
||||
|
@ -57,11 +57,11 @@ void HttpRequester::onDisconnect(const SockException &ex){
|
||||
}
|
||||
}
|
||||
|
||||
void HttpRequester::startRequester(const string &url,const HttpRequesterResult &onResult , uint32_t timeOutSecond){
|
||||
void HttpRequester::startRequester(const string &url,const HttpRequesterResult &onResult , float timeOutSecond){
|
||||
_onResult = onResult;
|
||||
_resTicker.resetTime();
|
||||
_timeOutSecond = timeOutSecond;
|
||||
sendRequest(url);
|
||||
sendRequest(url,timeOutSecond);
|
||||
}
|
||||
|
||||
void HttpRequester::onManager(){
|
||||
|
@ -40,7 +40,7 @@ public:
|
||||
HttpRequester();
|
||||
virtual ~HttpRequester();
|
||||
|
||||
void startRequester(const string &url,const HttpRequesterResult &onResult,uint32_t timeOutSecond = 10);
|
||||
void startRequester(const string &url,const HttpRequesterResult &onResult,float timeOutSecond = 10);
|
||||
private:
|
||||
void onResponseHeader(const string &status,const HttpHeader &headers) override;
|
||||
void onResponseBody(const char *buf,size_t size,size_t recvedSize,size_t totalSize) override;
|
||||
@ -50,7 +50,7 @@ private:
|
||||
string _strRecvBody;
|
||||
HttpRequesterResult _onResult;
|
||||
Ticker _resTicker;
|
||||
uint32_t _timeOutSecond;
|
||||
float _timeOutSecond;
|
||||
};
|
||||
|
||||
}//namespace Http
|
||||
|
Loading…
Reference in New Issue
Block a user