-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTask.cpp
48 lines (39 loc) · 941 Bytes
/
Task.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//
// Created by parallels on 2020/1/19.
//
#include "Task.h"
#include "HttpData.h"
//每个HttpData代表一个连接,持有一个Task,Task有事件和需要调用的回调函数等必要信息
Task::Task(EventLoop *loop, int fd) : loop_(loop), epoll_(loop->epoll_), fd_(fd), isMainLoop_(false), events(0), revents(0) {}
Task::~Task() {
if(DEBUG) {
printf("task free\n");
fflush(stdout);
}
}
void Task::eventHandle() {
if(isMainLoop()) {
connHandle_();
//usleep(100);
}
else if (revents & (EPOLLIN)) {
readHandle_();
}
else if (revents & (EPOLLOUT)) {
//writeHandle_();
}
revents = 0;
rfd_ = 0;
fflush(stdout);
//关闭连接
/*
if(getHolder())
if(getHolder()->isClose()) {
getHolder()->quit();
epoll_->removeEpoll(this);
}
*/
}
void Task::clearHolder() {
holder_ = NULL;
}