MySQL 8.0.39
Source Code Documentation
protocol.h
Go to the documentation of this file.
1/*
2Copyright (c) 2016, 2024, Oracle and/or its affiliates.
3
4This program is free software; you can redistribute it and/or modify
5it under the terms of the GNU General Public License, version 2.0,
6as published by the Free Software Foundation.
7
8This program is designed to work with certain software (including
9but not limited to OpenSSL) that is licensed under separate terms,
10as designated in a particular file or component or in included license
11documentation. The authors of MySQL hereby grant you an additional
12permission to link the program and your derivative works with the
13separately licensed software that they have either included with
14the program or referenced in the documentation.
15
16This program is distributed in the hope that it will be useful,
17but WITHOUT ANY WARRANTY; without even the implied warranty of
18MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19GNU General Public License for more details.
20
21You should have received a copy of the GNU General Public License
22along with this program; if not, write to the Free Software
23Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24*/
25#ifndef ROUTING_PROTOCOL_INCLUDED
26#define ROUTING_PROTOCOL_INCLUDED
27
28#include "base_protocol.h"
29
30#include <stdexcept>
31#include <string>
32
33class Protocol final {
34 public:
36
37 static inline Type get_default() { return Type::kClassicProtocol; }
38
39 /** @brief Returns type of the protocol by its name
40 */
41 static Type get_by_name(const std::string &name) {
43
44 if (name == "classic") {
45 /* already set */
46 } else if (name == "x") {
48 } else {
49 throw std::invalid_argument("Invalid protocol name: '" + name + "'");
50 }
51
52 return result;
53 }
54
55 /** @brief Returns default port for the selected protocol
56 */
57 static uint16_t get_default_port(Type type) {
58 uint16_t result{0};
59
60 switch (type) {
63 break;
66 break;
67 default:
68 throw std::invalid_argument("Invalid protocol: " +
69 std::to_string(static_cast<int>(type)));
70 }
71
72 return result;
73 }
74
75 private:
76 /** @brief default server ports for supported protocols */
77 static constexpr uint16_t kClassicProtocolDefaultPort{3306};
78 static constexpr uint16_t kXProtocolDefaultPort{33060};
79};
80
81#endif // ROUTING_PROTOCOL_INCLUDED
Type
supported protocols
Definition: base_protocol.h:32
Definition: protocol.h:33
static Type get_by_name(const std::string &name)
Returns type of the protocol by its name.
Definition: protocol.h:41
static Type get_default()
Definition: protocol.h:37
virtual enum enum_protocol_type type() const =0
static constexpr uint16_t kXProtocolDefaultPort
Definition: protocol.h:78
static constexpr uint16_t kClassicProtocolDefaultPort
default server ports for supported protocols
Definition: protocol.h:77
static uint16_t get_default_port(Type type)
Returns default port for the selected protocol.
Definition: protocol.h:57
static std::string to_string(const LEX_STRING &str)
Definition: lex_string.h:50
struct result result
Definition: result.h:34
case opt name
Definition: sslopt-case.h:33
Definition: result.h:30