This repository has been archived by the owner on May 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSimpleTbusd.h
70 lines (56 loc) · 2.18 KB
/
SimpleTbusd.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
//
// Created by capitalg on 2018/8/20.
//
#ifndef TENCENT_INTERN_SIMPLETBUSD_H
#define TENCENT_INTERN_SIMPLETBUSD_H
#include <map>
#include <set>
#include <boost/asio.hpp>
#include <boost/interprocess/shared_memory_object.hpp>
#include <boost/interprocess/mapped_region.hpp>
#include "structs/SimpleChannelInfo.h"
#include "structs/SimpleTbusInfo.h"
#include "SimpleTbusdConn.h"
#include "SimpleChannel.h"
/**
* 单线程tbusd
*/
class SimpleTbusd {
public:
/**
*
* @param io_context
* @param accept_endpoint tbusd监听地址
* @param channel_addrs_p 通道的共享内存地址
* @param channel_infos_p 通道信息
* @param process_id2endpoint 路由信息
*/
SimpleTbusd(boost::asio::io_context &io_context,
const boost::asio::ip::tcp::endpoint &accept_endpoint,
const std::string &tbus_shm_name,
std::map<uint32_t, std::pair<uint32_t, uint32_t>> process_id2endpoint);
private:
void do_accept();
void read_tbus_info(const std::string &tbus_shm_name);
/*
* members
*/
boost::asio::ip::tcp::acceptor acceptor_;
// 通道信息 通道<processA,processB> -> channel
std::unique_ptr<std::map<std::pair<uint32_t, uint32_t>, std::unique_ptr<SimpleChannel>>> channels_ptr;
// 路由信息
std::map<uint32_t, std::pair<uint32_t, uint32_t>> process_id2endpoint;
std::map<std::pair<uint32_t, uint32_t>, std::shared_ptr<boost::asio::ip::tcp::socket>> remote_endpoint2socket;
std::set<uint32_t> local_proc_ids;
/*****************所有连接*********************/
// std::vector<std::shared_ptr<SimpleTbusdConn>> conns; // todo 是不是没有必要保存所有连接
// 本地连接到tbusd的连接 process_id -> conn
std::map<uint32_t, std::shared_ptr<SimpleTbusdConn>> local_conns;
// 连接到其它tbusd的连接 ip -> conn
std::unique_ptr<std::map<uint32_t, std::unique_ptr<SimpleTbusdConn>>> other_tbus_conns;
// tbus共享内存信息
std::unique_ptr<boost::interprocess::shared_memory_object> shm_obj_ptr;
std::unique_ptr<boost::interprocess::mapped_region> region_ptr;
SimpleTbusInfo *tbus_info;
};
#endif //TENCENT_INTERN_SIMPLETBUSD_H