-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathchannel.cpp
More file actions
71 lines (54 loc) · 1.03 KB
/
Copy pathchannel.cpp
File metadata and controls
71 lines (54 loc) · 1.03 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
#include "channel.h"
#include <sys/epoll.h>
#include "stdio.h"
#include "epoller.h"
using namespace ydx;
const int Channel::kNoneEvent = 0;
const int Channel::kReadEvent = EPOLLIN | EPOLLPRI;
const int Channel::kWriteEvent = EPOLLOUT;
Channel::Channel(EPollPoller* ep, int fd)
: fd_(fd),
events_(0),
revents_(0),
index_(-1), //kNew
epoller_(ep)
{
}
void Channel::update()
{
epoller_->updateChannel(this);
}
void Channel::remove()
{
epoller_->removeChannel(this);
}
void Channel::handleEvent()
{
if ((revents_ & EPOLLHUP) && !(revents_ & EPOLLIN))
{
if (closeCallback_) closeCallback_();
}
//if (revents_ & EPOLLNVAL)
//{
// printf("Channel::handle_event() POLLNVAL\n");
//}
if (revents_ & (EPOLLERR /* | EPOLLNVAL*/))
{
if (errorCallback_)
{
errorCallback_();
}
//if (closeCallback_)
//{
// closeCallback_();
//}
}
if (revents_ & (EPOLLIN | EPOLLPRI | EPOLLRDHUP))
{
if (readCallback_) readCallback_();
}
if (revents_ & EPOLLOUT)
{
if (writeCallback_) writeCallback_();
}
}