-
Notifications
You must be signed in to change notification settings - Fork 0
/
Acceptor.h
35 lines (27 loc) · 1.07 KB
/
Acceptor.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
#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();
// 这个callback的作用是公平地选择一个subEventLoop,把接受连接的连接分发给他
void setNewConnectionCallback(const NewConnectionCallback& cb) {
newConnectionCallback_ = cb;
}
void listen();
bool listenning() const { return listenning_; }
private:
void handleRead();
EventLoop* loop_; // 这个listenfd(acceptSocket_ or acceptChannel_) 由哪个EventLoop负责循环监听以及处理相应事件
// 其实就是main eventloop
Socket acceptSocket_; // 监听套接字的文件描述符->listenfd
Channel acceptChannel_; // 是个Channel,就是封装了lisenfd(acceptSocket_),以及事件
NewConnectionCallback newConnectionCallback_;
bool listenning_;
};