-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHandler.cpp
More file actions
78 lines (67 loc) · 1.35 KB
/
Handler.cpp
File metadata and controls
78 lines (67 loc) · 1.35 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
#include "Handler.h"
#include <poll.h>
#include <sys/epoll.h>
#include "EventLoop.h"
const int Handler::kNoneEvent = 0;
const int Handler::kReadEvent = EPOLLIN | EPOLLPRI;
const int Handler::kWriteEvent = EPOLLOUT;
Handler::Handler(EventLoop* loop, int fd)
: m_pLoop(loop),
m_fd(fd),
m_events(0),
m_revents(0),
m_state(-1),
m_btied(false),
m_bEventHandling(false)
{
}
Handler::~Handler()
{
assert(!m_bEventHandling);
}
void Handler::m_updateHandler()
{
m_pLoop->updateHandler(this);
}
void Handler::removeHandler()
{
assert(isNoneEvent());
m_pLoop->removeHandler(this);
}
void Handler::handleEvent()
{
boost::shared_ptr<void> guard;
if(m_btied)
{
guard = m_tie.lock();
if(guard)
{
m_handleEvent();
}
}
else
{
m_handleEvent();
}
}
void Handler::m_handleEvent()
{
m_bEventHandling = true;
if((m_revents & EPOLLHUP) && !(m_revents & EPOLLIN))
{
if(m_closeCallback) m_closeCallback();
}
if(m_revents & (EPOLLERR | POLLNVAL))
{
if(m_errorCallback) m_errorCallback();
}
if(m_revents & (EPOLLIN | POLLPRI | EPOLLRDHUP))
{
if(m_readCallback) m_readCallback();
}
if(m_revents & EPOLLOUT)
{
if(m_writeCallback) m_writeCallback();
}
m_bEventHandling = false;
}