-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEventLoop.h
54 lines (45 loc) · 1.1 KB
/
EventLoop.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
45
46
47
48
49
50
51
52
53
54
#ifndef EVENTLOOP_H
#define EVENTLOOP_H
#include "Declear.h"
#include "IFChannelCallBack.h"
#include "Timestamp.h"
#include "IFRun.h"
#include <vector>
class EventLoop : public IFChannelCallBack
{
public:
class Runner
{
public:
Runner(IFRun *_pRun, void *_param):
pRun(_pRun),param(_param){}
void doRun()
{
pRun->run(param);
}
private:
IFRun *pRun;
void *param;
};
EventLoop();
~EventLoop();
void loop();
void update(Channel *_pChannel);
virtual void handleRead();
virtual void handleWrite();
void queueLoop(IFRun *pRun, void *param);
void wakeup();
void handlePendingRuns();
long runAt(Timestamp when, IFRun* pRun);
long runAfter(double delay, IFRun* pRun);
long runEvery(double interval, IFRun* pRun);
void cancelTimer(long timerId);
private:
Epoll *pPoller;
int ieventfd;
Channel *pWakeupChannel;
std::vector<Runner> vecRun;
TimerQueue *pTimerQueue;
int createEventfd();
};
#endif