代码拉取完成,页面将自动刷新
#include "Timer.h"
#include "HTTPData.h"
Timer::Timer(std::shared_ptr<HTTPData> requestData, int timeout)
: deleted_(false), httpdata_(requestData)
{
struct timeval now;
gettimeofday(&now, NULL);
expiredTime_ = timeConvert(now) + timeout;
}
Timer::~Timer()
{
if (httpdata_)
httpdata_->closeConn(); //超时后,析构时关闭连接
}
/*
Timer::Timer(Timer &timer)
: httpdata_(timer.httpdata_), expiredTime_(0)
{
}
void Timer::update(int timeout)
{
struct timeval now;
gettimeofday(&now, NULL);
expiredTime_ = timeConvert(now) + timeout;
}
*/
bool Timer::isUnexpired()
{
struct timeval now;
gettimeofday(&now, NULL);
size_t temp = timeConvert(now);
if (temp < expiredTime_)
return true;
else
{
this->setDeleted();
return false;
}
}
void Timer::resetHTTPSP()
{
httpdata_.reset(); //shared_ptr重置
this->setDeleted();
}
TimerManager::TimerManager() {}
TimerManager::~TimerManager() {}
void TimerManager::addTimer(std::shared_ptr<HTTPData> httpdata_, int timeout)
{
TimerSP newTimer(new Timer(httpdata_, timeout));
timerQueue.push(newTimer);
httpdata_->setTimer(newTimer);
}
void TimerManager::handleExpiredEvent()
{
while (!timerQueue.empty())
{
TimerSP topTimer = timerQueue.top();
if (topTimer->isDeleted())
timerQueue.pop();
else if (topTimer->isUnexpired() == false)
timerQueue.pop(); //pop后,pop出来的Timer的shared_ptr引用减为0,该Timer析构
else
break;
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。