-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathTransport.h
55 lines (42 loc) · 1.02 KB
/
Transport.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
#ifndef NET_TRANSPORT_
#define NET_TRANSPORT_
#include <unordered_map>
#include <thread>
#include <mutex>
#include <atomic>
#include "Message.h"
#include "Response.h"
#include "SelectableQueue.h"
template <class T>
class Channel;
class Fdevents;
namespace redis {
class Link;
class Transport {
public:
Transport();
~Transport();
int Start(const std::string& ip, int port);
// TODO: 优化
Message Recv();
void Send(const Response& resp);
private:
struct Client {
int id;
Link* link;
};
static void main_func(Transport* xport);
std::thread _main_thread;
static void recv_func(Transport* xport, int index);
std::vector<std::thread> recv_threads;
std::vector<SelectableQueue<Client*>> accept_queues;
std::vector<SelectableQueue<Response>> send_queues;
int _id_incr;
Link* _serv_link;
Channel<Message>* _recv_channel;
std::atomic<bool> _close_flag;
std::mutex _mutex;
std::unordered_map<int, int> _ids;
};
}; // namespace redis
#endif