-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChannel.h
44 lines (40 loc) · 1023 Bytes
/
Channel.h
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
#ifndef CHANNEL_H_
#define CHANNEL_H_
#include <boost/function.hpp>
#include <sys/epoll.h>
class EventLoop;
class Channel
{
public:
typedef boost::function<void()> Callback;
Channel(EventLoop*,int );
~Channel();
void setReadCallback(Callback cb){readcb_ = cb;}
void setWriteCallback(Callback cb) {writecb_ = cb;}
void setCloseCallback(Callback cb){closecb_ = cb;}
void enableRead();
void enableWrite();
void set_revents(int);
//oid handleRead(){readcb_();}
void handleEvent();
int events(){return events_;}
int fd(){return fd_;}
int index(){return idx_;}
void handClose(){closecb_();}
void disableAll(){events_ &= 0;update();}
void disableWriting(){events_ &= ~EPOLLOUT;}
void remove();
bool isReading(){return events_ && EPOLLIN;}
bool isWriting(){return events_&& EPOLLOUT;}
private:
void update();
EventLoop* loop_;
int fd_;
Callback readcb_;
Callback writecb_;
Callback closecb_;
int idx_;
int events_;
int revents_;
};
#endif