forked from mariadb-corporation/MaxScale
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprotocol.hh
126 lines (114 loc) · 3.47 KB
/
protocol.hh
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/*
* Copyright (c) 2018 MariaDB Corporation Ab
* Copyright (c) 2023 MariaDB plc, Finnish Branch
*
* Use of this software is governed by the Business Source License included
* in the LICENSE.TXT file and at www.mariadb.com/bsl11.
*
* Change Date: 2025-09-12
*
* On the date above, in accordance with the Business Source License, use
* of this software will be governed by version 2 or later of the General
* Public License.
*/
#pragma once
/**
* @file protocol.hh
*
* The protocol module interface definition.
*/
#include <maxscale/ccdefs.hh>
#include <maxscale/config2.hh>
#include <maxscale/dcbhandler.hh>
#include <maxscale/target.hh>
class DCB;
class SERVER;
class GWBUF;
class Listener;
class MXS_SESSION;
namespace maxscale
{
class ProtocolModule;
class ClientConnection;
class BackendConnection;
/**
* Base protocol class. Implemented by both client and backend protocols
*/
class ProtocolConnection : public DCBHandler
{
public:
virtual ~ProtocolConnection() = default;
/**
* Write data to a network socket
*
* @param buffer Buffer to write
* @return 1 on success, 0 on error
*/
virtual int32_t write(GWBUF* buffer) = 0;
virtual bool write(GWBUF&& buffer) = 0;
/**
* Print connection diagnostics to json.
*
* @return JSON representation of the connection
*/
virtual json_t* diagnostics() const = 0;
virtual void set_dcb(DCB* dcb) = 0;
/**
* Can the connection be moved to another thread.
*
* @return True if connection can be moved
*/
virtual bool is_movable() const
{
return true;
}
/**
* Is the connection idle.
*
* This method is called when the associated session is about to be modified. If the connection is
* logically idle, meaning no queries are ongoing and no results are expected, the session will be
* modified. If the connection is not idle, the modification is postponed until the connection is idle.
*
* Note that for the client protocol, this will always return true inside the routeQuery and clientReply
* functions. This happens as the client protocol stops being idle the moment the routeQuery is called and
* becomes idle only after all results have been read.
*
* TODO: This should be changed so that the session is idle for the duration of routeQuery and only goes
* non-idle when the routeQuery successfully returns. This is currently must done this way as some
* modules call clientReply directly from routeQuery.
*
* @return True if the connection is idle.
*/
virtual bool is_idle() const
{
return true;
}
/**
* Size of internal buffers.
*
* @return The size of internal buffers in bytes.
*/
virtual size_t sizeof_buffers() const = 0;
};
}
/**
* Protocol module API
*/
struct MXS_PROTOCOL_API
{
/**
* Creates a new protocol module instance.
*
* @param name The name of the listener for which this protocol is created
* @param listener The listener for which the protocol module is created.
*
* @return New protocol module instance
*/
mxs::ProtocolModule* (* create_protocol_module)(const std::string& name, Listener* listener);
};
/**
* The MXS_PROTOCOL version data. The following should be updated whenever
* the MXS_PROTOCOL structure is changed. See the rules defined in modinfo.h
* that define how these numbers should change.
*/
#define MXS_PROTOCOL_VERSION {4, 0, 0}