forked from L1w-Y/muduo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAcceptor.h
More file actions
29 lines (26 loc) · 804 Bytes
/
Copy pathAcceptor.h
File metadata and controls
29 lines (26 loc) · 804 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
#pragma once
#include"noncopyable.h"
#include"Socket.h"
#include"Channel.h"
#include<functional>
class Eventloop;
class InetAddress;
class Acceptor : noncopyable
{
public:
using NewConnectionCallback = std::function<void (int sockfd, const InetAddress&)>;
Acceptor(EventLoop *loop,const InetAddress& listenAddr,bool reuseport);
~Acceptor();
void setNewConnectionCallback(const NewConnectionCallback &cb){
newConnectionCallback_ = std::move(cb);
}
bool listenning()const{return listenning_;}
void listen();
private:
void handleRead();
EventLoop *loop_; //使用的是用户定义的baseloop(mainloop),用来接收tcp新连接
Socket acceptSocket_;
Channel acceptChannel_;
NewConnectionCallback newConnectionCallback_;
bool listenning_;
};