-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAcceptor.h
33 lines (27 loc) · 858 Bytes
/
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
#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)
{
new_connection_callback_ = cb;
}
bool listenning() const { return listenning_; }
void Listen();
private:
void HandleRead();
EventLoop *loop_; // Acceptor用的就是用户定义的那个baseLoop,也称作mainLoop
Socket accept_socket_; // 服务器本地 socket
Channel accept_channel_;
NewConnectionCallback new_connection_callback_;
bool listenning_;
};