-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathchannel.h
More file actions
72 lines (56 loc) · 1.79 KB
/
Copy pathchannel.h
File metadata and controls
72 lines (56 loc) · 1.79 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
#ifndef __YDX_CHANNEL_H__
#define __YDX_CHANNEL_H__
#include <boost/function.hpp>
#include <boost/noncopyable.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/weak_ptr.hpp>
namespace ydx
{
class EPollPoller;
class Channel : boost::noncopyable
{
public:
typedef boost::function<void()> EventCallback;
typedef boost::function<void()> ReadEventCallback;
Channel(EPollPoller* ep, int fd);
~Channel(){}
void handleEvent();
void setReadCallback(const ReadEventCallback& cb)
{ readCallback_ = cb; }
void setWriteCallback(const EventCallback& cb)
{ writeCallback_ = cb; }
void setCloseCallback(const EventCallback& cb)
{ closeCallback_ = cb; }
void setErrorCallback(const EventCallback& cb)
{ errorCallback_ = cb; }
void enableReading() { events_ |= kReadEvent; update(); }
void disableReading() { events_ &= ~kReadEvent; update(); }
void enableWriting() { events_ |= kWriteEvent; update(); }
void disableWriting() { events_ &= ~kWriteEvent; update(); }
void disableAll() { events_ = kNoneEvent; update(); }
bool isWriting() const { return events_ & kWriteEvent; }
int fd() const { return fd_; }
int index() { return index_; }
void set_index(int idx) { index_ = idx; }
int events() const { return events_; }
void set_revents(int revt) { revents_ = revt; } // used by pollers
bool isNoneEvent() const { return events_ == kNoneEvent; }
void remove();
void update();
private:
const int fd_;
int events_;
int revents_; // it's the received event types of epoll or poll
int index_; // used by Poller.
static const int kNoneEvent;
static const int kReadEvent;
static const int kWriteEvent;
EPollPoller* epoller_;
private:
ReadEventCallback readCallback_;
EventCallback writeCallback_;
EventCallback closeCallback_;
EventCallback errorCallback_;
};
}
#endif