Http客户端添加超时功能

This commit is contained in:
xiongziliang
2018-02-06 17:35:32 +08:00
parent c801de9965
commit ae1b62c78f
4 changed files with 33 additions and 10 deletions

View File

@@ -39,8 +39,9 @@ public:
HttpDownloader();
virtual ~HttpDownloader();
//开始下载文件,默认断点续传方式下载
void startDownload(const string &url,const string &filePath = "",bool bAppend = false);
void startDownload(const string &url,const onDownloadResult &cb){
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;
setOnResult(cb);
startDownload(url);
}
@@ -52,11 +53,14 @@ private:
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();
void onManager() override;
void closeFile();
FILE *_saveFile = nullptr;
string _filePath;
onDownloadResult _onResult;
uint32_t _timeOutSecond;
bool _bDownloadSuccess = false;
};