forked from Tencent/phxsql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathio_channel.h
More file actions
98 lines (66 loc) · 2.75 KB
/
io_channel.h
File metadata and controls
98 lines (66 loc) · 2.75 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*
Tencent is pleased to support the open source community by making PhxSQL available.
Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.
Licensed under the GNU General Public License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
https://opensource.org/licenses/GPL-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/
#pragma once
#include "phxsqlproxyconfig.h"
#include "group_status_cache.h"
namespace phxsqlproxy {
class IOChannel {
public:
IOChannel(PHXSqlProxyConfig * config,
WorkerConfig_t * worker_config,
GroupStatusCache * group_status_cache);
virtual ~IOChannel();
void SetReqUniqID(uint64_t req_uniq_id);
void Clear();
public:
int TransMsg(int client_fd, int sqlsvr_fd);
private:
int WriteToDest(int dest_fd, const char * buf, int write_size);
int TransMsgDirect(int source_fd, int dest_fd, struct pollfd[], int nfds);
int FakeClientIPInAuthBuf(char * buf, size_t buf_len); // forward compatibility
void GetDBNameFromAuthBuf(const char * buf, int buf_size);
void GetDBNameFromReqBuf(const char * buf, int buf_size);
virtual bool CanExecute(const char * buf, int size) = 0;
// monitor func
private:
void ByteFromConnectDestSvr(uint32_t byte_size);
void ByteFromMysqlClient(uint32_t byte_size);
protected:
uint64_t req_uniq_id_;
PHXSqlProxyConfig * config_;
WorkerConfig_t * worker_config_;
GroupStatusCache * group_status_cache_;
int client_fd_;
int sqlsvr_fd_;
std::string connect_dest_;
int connect_port_;
bool is_authed_;
std::string db_name_;
int last_read_fd_;
uint64_t last_received_request_timestamp_;
std::string client_ip_; // for FakeClientIPInAuthBuf, forward compatibility
};
class MasterIOChannel : public IOChannel {
public:
MasterIOChannel(PHXSqlProxyConfig * config,
WorkerConfig_t * worker_config,
GroupStatusCache * group_status_cache);
~MasterIOChannel() override;
private:
bool CanExecute(const char * buf, int size) override;
};
class SlaveIOChannel : public IOChannel {
public:
SlaveIOChannel(PHXSqlProxyConfig * config,
WorkerConfig_t * worker_config,
GroupStatusCache * group_status_cache);
~SlaveIOChannel() override;
private:
bool CanExecute(const char * buf, int size) override;
};
}