-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathAcceptor.h
56 lines (45 loc) · 1.27 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
//
// Created by yangning on 17-11-28.
//
// Descriprion : acceptor 用来接受连接,当有连接到来时,调用NewConnetcionCallBack来通知tcpserer.
// 是tcpserver的内部类.
// 起初设计的时时候没有把acceptor和tcpserver分开,在tcpserver中做了acceptor的事情,那样类的分工不明确.
//
// Copyright (c) yangning All rights reserved.
//
#ifndef BASE_NET_LIB_ACCEPTOR_H
#define BASE_NET_LIB_ACCEPTOR_H
#include "socket/tcp_socket.h"
#include "include/common.h"
#include "channel.h"
#include <functional>
#include <iostream>
namespace net {
class EventLoop;
using NewConnetcionCallBack=std::function<void(int, const IpAddress&)>;
class Acceptor {
public:
Acceptor(unsigned listenPort, EventLoop* loop);
void listen();
void setNewConnetcionCallBack(const NewConnetcionCallBack& cb)
{
newConnetcioncb_ = cb;
}
void handleRead();
bool listening() const
{
return listening_;
}
~Acceptor()
{
}
private:
EventLoop* ownEventLoop_;
TcpSocket listenSock_;
unsigned listenPort_;
bool listening_;
Channel listenChannel_;
NewConnetcionCallBack newConnetcioncb_;
};
}
#endif //BASE_NET_LIB_ACCEPTOR_H