-
Notifications
You must be signed in to change notification settings - Fork 17
/
base_loop.h
55 lines (51 loc) · 1.75 KB
/
base_loop.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
/*======================================================
> File Name: base_loop.h
> Author: MiaoShuai
> E-mail:
> Other :
> Created Time: 2015年12月20日 星期日 11时16分01秒
=======================================================*/
#ifndef BASE_LOOP_H_
#define BASE_LOOP_H_
#include "callback.h"
#include "event_loop_thread_pool.h"
#include <memory>
#include <string>
namespace netlib
{
class BaseLoop
{
public:
BaseLoop(std::string ip,int port,int loopNumber); //构造传参确定开多少个loop
~BaseLoop();
int createListenFd(void); //创建监听套接字
void start(void); //开始监听
void connectionHandle(int connfd); //连接回调可以在此之中调用
void setConnectionCallback(connectionCallback cb)
{
connectionCallback_ = cb;
}
void setMessageCallback(messageCallback cb)
{
messageCallback_ = cb;
}
void setCloseCallback(closeCallback cb)
{
closeCallback_ = cb;
}
void setWriteCompleteCallback(writeCompleteCallback cb)
{
writeCompleteCallback_ = cb;
}
private:
std::string ip_; //监听ip
int port_; //监听端口
int listenFd_; //监听套接字
std::shared_ptr<LoopThreadPool> loopThreadPoolPtr_; //线程池对象指针
messageCallback messageCallback_;
closeCallback closeCallback_;
connectionCallback connectionCallback_;
writeCompleteCallback writeCompleteCallback_;
};
}
#endif