-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathAcceptor.h
More file actions
32 lines (23 loc) · 805 Bytes
/
Acceptor.h
File metadata and controls
32 lines (23 loc) · 805 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
#pragma once
#include "Channel.h"
#include "Socket.h"
#include "noncopyable.h"
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_ = cb; }
bool listening() const { return listening_; }
void listen();
private:
void handleRead();
EventLoop *loop_;
Socket acceptSocket_;
Channel acceptChannel_;
// 将 accept 到的 connfd 绑定到 channel 上并注册事件,由上层 TcpServer 设置回调
NewConnectionCallback newConnectionCallback_;
bool listening_;
};