MySQL 8.3.0
Source Code Documentation
connection_acceptor.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2013, 2023, 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 also distributed 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 included with MySQL.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23*/
24
25#ifndef CONNECTION_ACCEPTOR_INCLUDED
26#define CONNECTION_ACCEPTOR_INCLUDED
27
28#include "sql/conn_handler/channel_info.h" // Channel_info
29#include "sql/conn_handler/connection_handler_manager.h" // Connection_handler_manager
30
31/**
32 This class presents a generic interface to initialize and run
33 a connection event loop for different types of listeners and
34 a callback functor to call on the connection event from the
35 listener that listens for connection. Listener type should
36 be a class providing methods setup_listener, listen_for_
37 connection_event and close_listener. The Connection event
38 callback functor object would on receiving connection event
39 from the client to process the connection.
40*/
41template <typename Listener>
43 Listener *m_listener;
44
45 public:
46 Connection_acceptor(Listener *listener) : m_listener(listener) {}
47
49
50 /**
51 Initialize a connection acceptor.
52
53 @retval return true if initialization failed, else false.
54 */
55 bool init_connection_acceptor() { return m_listener->setup_listener(); }
56
57 /**
58 Connection acceptor loop to accept connections from clients.
59 */
64 Channel_info *channel_info = m_listener->listen_for_connection_event();
65 if (channel_info != nullptr) mgr->process_new_connection(channel_info);
66 }
67 }
68
69 /**
70 Spawn admin connection handler to accept admin connections from clients if
71 create-admin-listener-thread is specified by user on commandline.
72
73 @return true unable to spawn admin connection handler thread else false.
74 */
76 return m_listener->check_and_spawn_admin_connection_handler_thread();
77 }
78
79 /**
80 Close the listener.
81 */
82 void close_listener() { m_listener->close_listener(); }
83};
84#endif // CONNECTION_ACCEPTOR_INCLUDED
This abstract base class represents connection channel information about a new connection.
Definition: channel_info.h:46
This class presents a generic interface to initialize and run a connection event loop for different t...
Definition: connection_acceptor.h:42
Listener * m_listener
Definition: connection_acceptor.h:43
void close_listener()
Close the listener.
Definition: connection_acceptor.h:82
void connection_event_loop()
Connection acceptor loop to accept connections from clients.
Definition: connection_acceptor.h:60
Connection_acceptor(Listener *listener)
Definition: connection_acceptor.h:46
bool check_and_spawn_admin_connection_handler_thread() const
Spawn admin connection handler to accept admin connections from clients if create-admin-listener-thre...
Definition: connection_acceptor.h:75
~Connection_acceptor()
Definition: connection_acceptor.h:48
bool init_connection_acceptor()
Initialize a connection acceptor.
Definition: connection_acceptor.h:55
This is a singleton class that provides various connection management related functionalities,...
Definition: connection_handler_manager.h:57
void process_new_connection(Channel_info *channel_info)
Process a new incoming connection.
Definition: connection_handler_manager.cc:251
static Connection_handler_manager * get_instance()
Singleton method to return an instance of this class.
Definition: connection_handler_manager.h:137
bool connection_events_loop_aborted()
Definition: mysqld.h:750