-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAcceptor.h
More file actions
43 lines (31 loc) · 842 Bytes
/
Copy pathAcceptor.h
File metadata and controls
43 lines (31 loc) · 842 Bytes
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
#ifndef ACCEPTOR_H
#define ACCEPTOR_H
#include"noncopyable.h"
#include"Socket.h"
#include"Channel.h"
class EventLoop;
class InetAddr;
class Acceptor:noncopyable
{
public:
using NewConnectionCallback = std::function<void(int sockfd,const InetAddr&)>;
bool listening()const{return listening_;}
void listen();
void setNewConnectionCallback(const NewConnectionCallback& cb){
newConnectionCallback_ = cb;
}
Acceptor(EventLoop* loop,const InetAddr& listenAddr,bool reuseport);
~Acceptor();
private:
void handleRead();
/* data */
int idleFd_;
bool listening_;
Channel acceptChannel_;
Socket acceptSock_;
//acceptor使用的是mainloop baseloop_
EventLoop* loop_;
//当有新连接时调用的回调函数
NewConnectionCallback newConnectionCallback_;
};
#endif