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

@@ -57,10 +57,19 @@ void HttpRequester::onDisconnect(const SockException &ex){
}
}
void HttpRequester::startRequester(const string &url,const HttpRequesterResult &onResult){
void HttpRequester::startRequester(const string &url,const HttpRequesterResult &onResult , uint32_t timeOutSecond){
_onResult = onResult;
_resTicker.resetTime();
_timeOutSecond = timeOutSecond;
sendRequest(url);
}
void HttpRequester::onManager(){
if(_onResult && _resTicker.elapsedTime() > _timeOutSecond * 1000){
//超时
onDisconnect(SockException(Err_timeout,"wait http response timeout"));
shutdown();
}
}