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
/
SimpleTbusdConn.h
59 lines (46 loc) · 2.12 KB
/
SimpleTbusdConn.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
//
// Created by capitalg on 2018/8/20.
//
#ifndef TENCENT_INTERN_SIMPLETBUSDCONN_H
#define TENCENT_INTERN_SIMPLETBUSDCONN_H
#include <unordered_map>
#include <set>
#include <map>
#include <boost/asio.hpp>
#include "structs/TbusMsg.h"
#include "structs/SimpleChannelInfo.h"
#include "NetworkUtil.h"
#include "SimpleChannel.h"
/**
* SimpleTbusdConn需要改变tbus共享内存中对应通道的信息以及通道内容
* 因此需要知道
* 1.所有通道对应读写指针的地址,即通道->simplechannelInfo*的映射关系
* 2.每个通道对应的共享内存地址, 即通道->通道共享内存地址 的映射关系
*/
class SimpleTbusdConn : public std::enable_shared_from_this<SimpleTbusdConn> {
public:
SimpleTbusdConn(boost::asio::ip::tcp::socket socket,
std::map<std::pair<uint32_t, uint32_t>, std::unique_ptr<SimpleChannel>> &channels,
std::map<uint32_t, std::pair<uint32_t, uint32_t>> &process_id2endpoint,
std::map<uint32_t, std::shared_ptr<SimpleTbusdConn>> &local_conns,
std::map<std::pair<uint32_t, uint32_t>, std::shared_ptr<boost::asio::ip::tcp::socket>> &remote_endpoint2socket,
std::set<uint32_t> &local_proc_id);
void start();
void do_read_message_type();
void do_read_tbusmsg();
void do_read_local_proc_id();
boost::asio::ip::tcp::socket &get_socket() { return socket_; }
private:
boost::asio::ip::tcp::socket socket_;
TbusMsg tbus_msg;
uint32_t len, cur_read_len, message_type, buffer_proc_id;
std::map<std::pair<uint32_t, uint32_t>, std::unique_ptr<SimpleChannel>> &channels;
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::map<uint32_t, std::shared_ptr<SimpleTbusdConn>> &local_conns;
std::set<uint32_t> &local_proc_id;
inline bool _is_local(uint32_t proc_id) {
return local_proc_id.find(proc_id) != local_proc_id.end();
}
};
#endif //TENCENT_INTERN_SIMPLETBUSDCONN_H