forked from chenshuo/recipes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
s07-s06-Channel.cc.diff
63 lines (53 loc) · 1.38 KB
/
s07-s06-Channel.cc.diff
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
// excerpts from http://code.google.com/p/muduo/
//
// Use of this source code is governed by a BSD-style license
// that can be found in the License file.
//
// Author: Shuo Chen (chenshuo at chenshuo dot com)
#include "Channel.h"
#include "EventLoop.h"
#include "logging/Logging.h"
#include <sstream>
#include <poll.h>
using namespace muduo;
const int Channel::kNoneEvent = 0;
const int Channel::kReadEvent = POLLIN | POLLPRI;
const int Channel::kWriteEvent = POLLOUT;
Channel::Channel(EventLoop* loop, int fdArg)
: loop_(loop),
fd_(fdArg),
events_(0),
revents_(0),
index_(-1),
eventHandling_(false)
{
}
Channel::~Channel()
{
assert(!eventHandling_);
}
void Channel::update()
{
loop_->updateChannel(this);
}
!void Channel::handleEvent(Timestamp receiveTime)
{
eventHandling_ = true;
if (revents_ & POLLNVAL) {
LOG_WARN << "Channel::handle_event() POLLNVAL";
}
if ((revents_ & POLLHUP) && !(revents_ & POLLIN)) {
LOG_WARN << "Channel::handle_event() POLLHUP";
if (closeCallback_) closeCallback_();
}
if (revents_ & (POLLERR | POLLNVAL)) {
if (errorCallback_) errorCallback_();
}
if (revents_ & (POLLIN | POLLPRI | POLLRDHUP)) {
! if (readCallback_) readCallback_(receiveTime);
}
if (revents_ & POLLOUT) {
if (writeCallback_) writeCallback_();
}
eventHandling_ = false;
}