-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathlistener.h
More file actions
52 lines (45 loc) · 1.03 KB
/
listener.h
File metadata and controls
52 lines (45 loc) · 1.03 KB
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
#ifndef LISTENER_H_
#define LISTENER_H_
#include "./dns/dns_resolve.h"
#include "util/network.h"
#include "mutex.h"
#include <unistd.h>
namespace tinyco {
class Listener {
public:
Listener();
virtual ~Listener();
virtual int Listen(const network::IP &ip, uint16_t port) = 0;
virtual Mutex *GetMtx() { return mtx_; }
int GetSocketFd() const { return listenfd_; }
void Destroy() {
if (listenfd_ >= 0) close(listenfd_);
}
network::IP GetIP() const { return ip_; }
uint16_t GetPort() const { return port_; }
std::string GetProto() const { return proto_; }
protected:
int listenfd_;
network::IP ip_;
uint16_t port_;
Mutex *mtx_;
std::string proto_;
};
class TcpListener : public Listener {
public:
TcpListener() {
proto_ = "tcp";
mtx_ = new AtomicMtx();
}
virtual int Listen(const network::IP &ip, uint16_t port);
};
class UdpListener : public Listener {
public:
UdpListener() {
proto_ = "tcp";
mtx_ = new AtomicMtx();
}
virtual int Listen(const network::IP &ip, uint16_t port);
};
}
#endif