Skip to content

Commit

Permalink
🪲 fix utils.m_timer_lst bug
Browse files Browse the repository at this point in the history
  • Loading branch information
qinguoyi committed Jun 7, 2020
1 parent f5639a3 commit 2bcc96e
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 15 deletions.
3 changes: 1 addition & 2 deletions timer/lst_timer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,8 @@ void sort_timer_lst::add_timer(util_timer *timer, util_timer *lst_head)
}
}

void Utils::init(sort_timer_lst timer_lst, int timeslot)
void Utils::init(int timeslot)
{
m_timer_lst = timer_lst;
m_TIMESLOT = timeslot;
}

Expand Down
2 changes: 1 addition & 1 deletion timer/lst_timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class Utils
Utils() {}
~Utils() {}

void init(sort_timer_lst timer_lst, int timeslot);
void init(int timeslot);

//对文件描述符设置非阻塞
int setnonblocking(int fd);
Expand Down
27 changes: 16 additions & 11 deletions webserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,24 +45,29 @@ void WebServer::init(int port, string user, string passWord, string databaseName
m_actormodel = actor_model;
}

void WebServer::trig_mode(){
void WebServer::trig_mode()
{
//LT + LT
if(0 == m_TRIGMode){
if (0 == m_TRIGMode)
{
m_LISTENTrigmode = 0;
m_CONNTrigmode = 0;
}
//LT + ET
else if(1 == m_TRIGMode){
else if (1 == m_TRIGMode)
{
m_LISTENTrigmode = 0;
m_CONNTrigmode = 1;
}
//ET + LT
else if(2 == m_TRIGMode){
else if (2 == m_TRIGMode)
{
m_LISTENTrigmode = 1;
m_CONNTrigmode = 0;
}
//ET + ET
else if(3 == m_TRIGMode){
else if (3 == m_TRIGMode)
{
m_LISTENTrigmode = 1;
m_CONNTrigmode = 1;
}
Expand Down Expand Up @@ -135,7 +140,7 @@ void WebServer::eventListen()
Utils::u_pipefd = m_pipefd;
Utils::u_epollfd = m_epollfd;

utils.init(timer_lst, TIMESLOT);
utils.init(TIMESLOT);

//epoll创建内核事件表
epoll_event events[MAX_EVENT_NUMBER];
Expand Down Expand Up @@ -171,7 +176,7 @@ void WebServer::timer(int connfd, struct sockaddr_in client_address)
time_t cur = time(NULL);
timer->expire = cur + 3 * TIMESLOT;
users_timer[connfd].timer = timer;
timer_lst.add_timer(timer);
utils.m_timer_lst.add_timer(timer);
}

//若有数据传输,则将定时器往后延迟3个单位
Expand All @@ -180,7 +185,7 @@ void WebServer::adjust_timer(util_timer *timer)
{
time_t cur = time(NULL);
timer->expire = cur + 3 * TIMESLOT;
timer_lst.adjust_timer(timer);
utils.m_timer_lst.adjust_timer(timer);

LOG_INFO("%s", "adjust timer once");
}
Expand All @@ -190,7 +195,7 @@ void WebServer::deal_timer(util_timer *timer, int sockfd)
timer->cb_func(&users_timer[sockfd]);
if (timer)
{
timer_lst.del_timer(timer);
utils.m_timer_lst.del_timer(timer);
}

LOG_INFO("close fd %d", users_timer[sockfd].sockfd);
Expand Down Expand Up @@ -240,7 +245,7 @@ bool WebServer::dealclinetdata()
return true;
}

bool WebServer::dealwithsignal(bool& timeout, bool& stop_server)
bool WebServer::dealwithsignal(bool &timeout, bool &stop_server)
{
int ret = 0;
int sig;
Expand Down Expand Up @@ -409,7 +414,7 @@ void WebServer::eventLoop()
{
bool flag = dealwithsignal(timeout, stop_server);
if (false == flag)
continue;
LOG_ERROR("%s", "dealclientdata failure");
}
//处理客户连接上接收到的数据
else if (events[i].events & EPOLLIN)
Expand Down
1 change: 0 additions & 1 deletion webserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ class WebServer
int m_CONNTrigmode;

//定时器相关
sort_timer_lst timer_lst;
client_data *users_timer;
Utils utils;
};
Expand Down

0 comments on commit 2bcc96e

Please sign in to comment.