MySQL 8.4.2
Source Code Documentation
server.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2021, 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 ROUTER_SRC_HTTP_SRC_HTTP_SERVER_SERVER_H_
27#define ROUTER_SRC_HTTP_SRC_HTTP_SERVER_SERVER_H_
28
29#include <list>
30#include <memory>
31#include <mutex> // NOLINT(build/c++11)
32#include <vector>
33
36
39#include "http/base/method.h"
40#include "http/server/bind.h"
43#include "tls/tls_stream.h"
44
45class IoThread;
46
47namespace http {
48namespace server {
49
56using ConnectionStatusCallbacksRaw = ConnectionRaw::ConnectionStatusCallbacks;
57using ConnectionStatusCallbacksTls = ConnectionTls::ConnectionStatusCallbacks;
58
61 public:
66 using IoThreads = std::list<IoThread>;
67 using IoIterator = IoThreads::iterator;
68
69 public:
70 Server(TlsServerContext *tls_context, IoThreads *threads, Bind *bind_raw,
71 Bind *bind_ssl);
72
73 void set_allowed_methods(const Methods &methods);
74 void set_request_handler(RequestHandlerInterface *handler);
75
76 void start();
77 void stop();
78
79 private: // Ssl connections handling
80 void on_new_ssl_connection(socket socket);
81 void on_connection_close(ConnectionTls *connection) override;
82 void on_connection_io_error(ConnectionTls *connection,
83 const std::error_code &ec) override;
84
85 private: // Raw connections handling
86 void on_new_connection(socket socket);
87 void on_connection_close(ConnectionRaw *connection) override;
89 const std::error_code &ec) override;
90
91 private:
92 enum class State { kInitializing, kRunning, kStopping, kStopped };
93
94 size_t disconnect_all();
95
96 void start_accepting();
97 socket socket_move_to_io_thread(socket socket);
98 IoThread *return_next_thread();
100 std::list<IoThread> *threads_;
105 RequestHandlerInterface *handler_ = nullptr;
106
108 std::vector<std::shared_ptr<ServerConnectionRaw>> connections_;
109 std::vector<std::shared_ptr<ServerConnectionTls>> connections_ssl_;
110 WaitableVariable<State> sync_state_{State::kInitializing};
111};
112
113} // namespace server
114} // namespace http
115
116#endif // ROUTER_SRC_HTTP_SRC_HTTP_SERVER_SERVER_H_
Definition: io_thread.h:39
TLS Context for the server side.
Definition: tls_server_context.h:51
Definition: wait_variable.h:34
The handler class is the interface for dynamically loadable storage engines.
Definition: handler.h:4573
Definition: bind.h:41
Definition: request_handler_interface.h:34
Definition: connection.h:41
Definition: server.h:60
base::method::Bitset Methods
Definition: server.h:65
net::impl::socket::native_handle_type native_handle_type
Definition: server.h:62
IoIterator current_thread_
Definition: server.h:101
base::method::Bitset allowed_methods_
Definition: server.h:104
Bind * bind_ssl_
Definition: server.h:103
void on_connection_close(ConnectionRaw *connection) override
TlsServerContext * tls_context_
Definition: server.h:99
std::list< IoThread > IoThreads
Definition: server.h:66
State
Definition: server.h:92
std::mutex mutex_connection_
Definition: server.h:107
std::vector< std::shared_ptr< ServerConnectionTls > > connections_ssl_
Definition: server.h:109
void on_connection_io_error(ConnectionRaw *connection, const std::error_code &ec) override
Bind * bind_raw_
Definition: server.h:102
std::list< IoThread > * threads_
Definition: server.h:100
std::vector< std::shared_ptr< ServerConnectionRaw > > connections_
Definition: server.h:108
IoThreads::iterator IoIterator
Definition: server.h:67
Definition: socket.h:1090
Definition: io_context.h:61
basic_stream_socket< tcp > socket
Definition: internet.h:1159
Definition: tls_stream.h:45
static void start(mysql_harness::PluginFuncEnv *env)
Definition: http_auth_backend_plugin.cc:180
#define HTTP_SERVER_LIB_EXPORT
Definition: http_server_lib_export.h:15
std::bitset< Pos::_LAST+1 > Bitset
Definition: method.h:57
ConnectionRaw::ConnectionStatusCallbacks ConnectionStatusCallbacksRaw
Definition: server.h:56
ConnectionTls::ConnectionStatusCallbacks ConnectionStatusCallbacksTls
Definition: server.h:57
Definition: connection.h:56
stdx::expected< native_handle_type, error_type > socket(int family, int sock_type, int protocol)
Definition: socket.h:63
int native_handle_type
Definition: socket_constants.h:51
Definition: server_struct.h:39