From c2b11e3868257d6fbfe5f9931016b94c9e063e67 Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Wed, 28 Feb 2018 17:30:12 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84http=E8=B6=85=E6=97=B6?= =?UTF-8?q?=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Http/HttpClient.cpp | 4 ++-- src/Http/HttpClient.h | 2 +- src/Http/HttpClientImp.cpp | 4 ++-- src/Http/HttpClientImp.h | 2 +- src/Http/HttpDownloader.cpp | 4 ++-- src/Http/HttpDownloader.h | 7 +++---- src/Http/HttpRequester.cpp | 4 ++-- src/Http/HttpRequester.h | 4 ++-- 8 files changed, 15 insertions(+), 16 deletions(-) diff --git a/src/Http/HttpClient.cpp b/src/Http/HttpClient.cpp index 8c9e657e..36c39dc8 100644 --- a/src/Http/HttpClient.cpp +++ b/src/Http/HttpClient.cpp @@ -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); diff --git a/src/Http/HttpClient.h b/src/Http/HttpClient.h index 15ca40c5..02cef34c 100644 --- a/src/Http/HttpClient.h +++ b/src/Http/HttpClient.h @@ -68,7 +68,7 @@ public: typedef std::shared_ptr Ptr; HttpClient(); virtual ~HttpClient(); - virtual void sendRequest(const string &url); + virtual void sendRequest(const string &url,float fTimeOutSec); void clear(){ _header.clear(); _body.clear(); diff --git a/src/Http/HttpClientImp.cpp b/src/Http/HttpClientImp.cpp index 28d65510..f2cda890 100644 --- a/src/Http/HttpClientImp.cpp +++ b/src/Http/HttpClientImp.cpp @@ -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(); diff --git a/src/Http/HttpClientImp.h b/src/Http/HttpClientImp.h index fa8cfe46..654a6496 100644 --- a/src/Http/HttpClientImp.h +++ b/src/Http/HttpClientImp.h @@ -41,7 +41,7 @@ public: typedef std::shared_ptr 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){ diff --git a/src/Http/HttpDownloader.cpp b/src/Http/HttpDownloader.cpp index 5b464312..50e706ce 100644 --- a/src/Http/HttpDownloader.cpp +++ b/src/Http/HttpDownloader.cpp @@ -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) { diff --git a/src/Http/HttpDownloader.h b/src/Http/HttpDownloader.h index cc2b7c80..0f23695d 100644 --- a/src/Http/HttpDownloader.h +++ b/src/Http/HttpDownloader.h @@ -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; diff --git a/src/Http/HttpRequester.cpp b/src/Http/HttpRequester.cpp index b628f4f5..de3fb019 100644 --- a/src/Http/HttpRequester.cpp +++ b/src/Http/HttpRequester.cpp @@ -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(){ diff --git a/src/Http/HttpRequester.h b/src/Http/HttpRequester.h index 2dc287e3..55ae60b8 100644 --- a/src/Http/HttpRequester.h +++ b/src/Http/HttpRequester.h @@ -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