-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChannel.cpp
More file actions
112 lines (73 loc) · 1.63 KB
/
Channel.cpp
File metadata and controls
112 lines (73 loc) · 1.63 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#include "Channel.h"
#include <sys/epoll.h>
Channel::Channel(EventLoop* loop, int fd):
m_loop(loop), m_fd(fd) { }
Channel::~Channel() {}
int Channel::fd() const {
return m_fd;
}
uint32_t Channel::events() const {
return m_events;
}
uint32_t Channel::revents() const {
return m_revents;
}
bool Channel::inpoll() const {
return m_inepoll;
}
void Channel::setinepoll(bool inepoll) {
m_inepoll = inepoll;
}
void Channel::setrevents(uint32_t ev) {
m_revents = ev;
}
void Channel::enablereading() {
m_events |= EPOLLIN;
m_loop->updatechannel(this);
}
void Channel::disablereading() {
m_events &= ~EPOLLIN;
m_loop->updatechannel(this);
}
void Channel::enablewriting() {
m_events |= EPOLLOUT;
m_loop->updatechannel(this);
}
void Channel::disablewriting() {
m_events &= ~EPOLLOUT;
m_loop->updatechannel(this);
}
void Channel::disableall() {
m_events = 0;
m_loop->updatechannel(this);
}
void Channel::setreadcallback(std::function<void()> fn) {
m_readcallback = fn;
}
void Channel::setwritecallback(std::function<void()> fn) {
m_closecallback = fn;
}
void Channel::setclosecallback(std::function<void()> fn) {
m_closecallback = fn;
}
void Channel::seterrorcallback(std::function<void()> fn) {
m_errorcallback = fn;
}
void Channel::handleevent() {
if (m_revents & EPOLLRDHUP) {
m_closecallback();
} else if (m_revents & (EPOLLIN|EPOLLPRI)) {
m_readcallback();
} else if (m_revents & EPOLLOUT) {
m_writecallback();
} else {
m_errorcallback();
}
}
void Channel::useet() {
m_events |= EPOLLET;
}
void Channel::remove() {
disableall();
m_loop->removechannel(this);
}