-
Notifications
You must be signed in to change notification settings - Fork 10
/
channel.cpp
92 lines (75 loc) · 1.54 KB
/
channel.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
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
#include "channel.h"
Channel::Channel(int fd) : m_fd(fd), m_events(0), m_minHeapIndex(-1)
{
}
void Channel::SetReadCallback(CallbackType readCallback)
{
m_readCallback = readCallback;
}
void Channel::SetWriteCallback(CallbackType writeCallback)
{
m_writeCallback = writeCallback;
}
void Channel::SetErrorCallback(CallbackType errorCallback)
{
m_errorCallback = errorCallback;
}
void Channel::SetEvents(int events)
{
m_events = events;
}
int Channel::GetFd()
{
return m_fd;
}
int Channel::GetEvents()
{
return m_events;
}
SimpleBuffer & Channel::GetInBuffer()
{
return m_inBuffer;
}
SimpleBuffer & Channel::GetOutBuffer()
{
return m_outBuffer;
}
HttpMessage & Channel::GetHttpMessage()
{
return m_httpmessage;
}
const struct timeval & Channel::GetLastActiveTime()
{
return m_stLastActiveTime;
}
void Channel::SetLastActiveTime(const struct timeval & stTimeval)
{
m_stLastActiveTime = stTimeval;
}
int Channel::GetMinHeapIndex()
{
return m_minHeapIndex;
}
void Channel::SetMinHeapIndex(int minHeapIndex)
{
m_minHeapIndex = minHeapIndex;
}
void Channel::HandleEvent(EventLoop & eventLoop, std::shared_ptr<Channel> ptChannel, int revents)
{
if (revents & (EPOLLHUP | EPOLLERR))
{
if (m_errorCallback) m_errorCallback(eventLoop, ptChannel);
ERRLOG("%s %s %d, Handle event %d error", __FILE__, __func__, __LINE__, m_fd);
}
else
{
if (revents & (EPOLLIN | EPOLLRDHUP))
{
if (m_readCallback) m_readCallback(eventLoop, ptChannel);
}
if (revents & EPOLLOUT)
{
if (m_writeCallback) m_writeCallback(eventLoop, ptChannel);
}
}
}