MySQL 8.0.29
Source Code Documentation
protocol.h
Go to the documentation of this file.
1/*
2Copyright (c) 2016, 2021, 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 also distributed 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 included with MySQL.
14
15This program is distributed in the hope that it will be useful,
16but WITHOUT ANY WARRANTY; without even the implied warranty of
17MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18GNU General Public License for more details.
19
20You should have received a copy of the GNU General Public License
21along with this program; if not, write to the Free Software
22Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23*/
24#ifndef ROUTING_PROTOCOL_INCLUDED
25#define ROUTING_PROTOCOL_INCLUDED
26
27#include "base_protocol.h"
28
29#include <stdexcept>
30#include <string>
31
32class Protocol final {
33 public:
35
36 static inline Type get_default() { return Type::kClassicProtocol; }
37
38 /** @brief Returns type of the protocol by its name
39 */
40 static Type get_by_name(const std::string &name) {
42
43 if (name == "classic") {
44 /* already set */
45 } else if (name == "x") {
47 } else {
48 throw std::invalid_argument("Invalid protocol name: '" + name + "'");
49 }
50
51 return result;
52 }
53
54 /** @brief Returns default port for the selected protocol
55 */
56 static uint16_t get_default_port(Type type) {
57 uint16_t result{0};
58
59 switch (type) {
62 break;
65 break;
66 default:
67 throw std::invalid_argument("Invalid protocol: " +
68 std::to_string(static_cast<int>(type)));
69 }
70
71 return result;
72 }
73
74 private:
75 /** @brief default server ports for supported protocols */
76 static constexpr uint16_t kClassicProtocolDefaultPort{3306};
77 static constexpr uint16_t kXProtocolDefaultPort{33060};
78};
79
80#endif // ROUTING_PROTOCOL_INCLUDED
Type
supported protocols
Definition: base_protocol.h:31
Definition: protocol.h:32
static Type get_by_name(const std::string &name)
Returns type of the protocol by its name.
Definition: protocol.h:40
static Type get_default()
Definition: protocol.h:36
virtual enum enum_protocol_type type() const =0
static constexpr uint16_t kXProtocolDefaultPort
Definition: protocol.h:77
static constexpr uint16_t kClassicProtocolDefaultPort
default server ports for supported protocols
Definition: protocol.h:76
static uint16_t get_default_port(Type type)
Returns default port for the selected protocol.
Definition: protocol.h:56
static std::string to_string(const LEX_STRING &str)
Definition: lex_string.h:49
struct result result
Definition: result.h:33
case opt name
Definition: sslopt-case.h:32
Definition: result.h:29