MySQL 8.0.40
Source Code Documentation
processor.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2022, 2024, Oracle and/or its affiliates.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License, version 2.0,
6 as published by the Free Software Foundation.
7
8 This program is designed to work with certain software (including
9 but not limited to OpenSSL) that is licensed under separate terms,
10 as designated in a particular file or component or in included license
11 documentation. The authors of MySQL hereby grant you an additional
12 permission to link the program and your derivative works with the
13 separately licensed software that they have either included with
14 the program or referenced in the documentation.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24*/
25
26#ifndef ROUTING_CLASSIC_PROCESSOR_INCLUDED
27#define ROUTING_CLASSIC_PROCESSOR_INCLUDED
28
30#include "tracer.h"
31
34
35/**
36 * base class of all the processors.
37 *
38 * Processor
39 *
40 * - have their own internal state
41 * - expose a process() function which will be called until
42 * it returns Result::Done
43 *
44 * Processors are stacked.
45 *
46 * The methods:
47 *
48 * - push_processor()
49 * - pop_processor()
50 *
51 * allow to add and remove elements for the stack.
52 *
53 * The top-most processor's process() function is called.
54 */
56 public:
57 enum class Result {
58 Again, // will invoke the process() of the top-most-processor
59 RecvFromClient, // wait for recv from client and invoke ...
60 SendToClient, // wait for send-to-client and invoke ...
61 RecvFromServer, // wait for recv from server and invoke ...
62 RecvFromBoth, // wait for recv from client and server and invoke ..
63 SendToServer, // wait for send-to-server and invoke ...
65
66 Suspend, // wait for explicit resume
67 Done, // pop this processor and invoke the top-most-processor's process()
68
69 Void,
70 };
71
73
74 virtual ~BasicProcessor() = default;
75
77
79
81
82 private:
84};
85
86/**
87 * a processor base class with helper functions.
88 */
89class Processor : public BasicProcessor {
90 public:
92
93 protected:
95 std::error_code ec);
96
98 std::error_code ec);
99
101 std::error_code ec);
102
104 std::error_code ec);
105
107 std::error_code ec);
108
110 std::error_code ec);
111
112 /**
113 * discard to current message.
114 *
115 * @pre ensure_full_frame() must true.
116 */
118 Channel *src_channel, ClassicProtocolState *src_protocol);
119
120 /**
121 * log a message with error-code as error.
122 */
123 static void log_fatal_error_code(const char *msg, std::error_code ec);
124
125 // see MysqlClassicConnection::trace()
126 [[deprecated(
127 "use 'if (auto &tr = tracer()) { tr.trace(...); } instead")]] void
129
130 Tracer &tracer();
131};
132
133#endif
base class of all the processors.
Definition: processor.h:55
MysqlRoutingClassicConnectionBase * conn_
Definition: processor.h:83
virtual ~BasicProcessor()=default
MysqlRoutingClassicConnectionBase * connection()
Definition: processor.h:78
Result
Definition: processor.h:57
const MysqlRoutingClassicConnectionBase * connection() const
Definition: processor.h:76
BasicProcessor(MysqlRoutingClassicConnectionBase *conn)
Definition: processor.h:72
virtual stdx::expected< Result, std::error_code > process()=0
SSL aware socket buffers.
Definition: channel.h:64
protocol state of a classic protocol connection.
Definition: classic_connection_base.h:52
Definition: classic_connection_base.h:221
a processor base class with helper functions.
Definition: processor.h:89
stdx::expected< void, std::error_code > discard_current_msg(Channel *src_channel, ClassicProtocolState *src_protocol)
discard to current message.
Definition: processor.cc:94
static void log_fatal_error_code(const char *msg, std::error_code ec)
log a message with error-code as error.
Definition: processor.cc:134
stdx::expected< Result, std::error_code > send_server_failed(std::error_code ec)
Definition: processor.cc:37
stdx::expected< Result, std::error_code > recv_client_failed(std::error_code ec)
Definition: processor.cc:66
stdx::expected< Result, std::error_code > client_socket_failed(std::error_code ec)
Definition: processor.cc:86
void trace(Tracer::Event e)
Definition: processor.cc:139
stdx::expected< Result, std::error_code > recv_server_failed(std::error_code ec)
Definition: processor.cc:46
stdx::expected< Result, std::error_code > send_client_failed(std::error_code ec)
Definition: processor.cc:57
stdx::expected< Result, std::error_code > server_socket_failed(std::error_code ec)
Definition: processor.cc:77
Tracer & tracer()
Definition: processor.cc:143
Definition: tracer.h:61
traces the timestamps of events in a stderr log.
Definition: tracer.h:49
Definition: expected.h:944