MySQL 9.1.0
Source Code Documentation
connection_acceptor.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2013, 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, version 2.0, 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 CONNECTION_ACCEPTOR_INCLUDED
27#define CONNECTION_ACCEPTOR_INCLUDED
28
29#include "sql/conn_handler/channel_info.h" // Channel_info
30#include "sql/conn_handler/connection_handler_manager.h" // Connection_handler_manager
31
32/**
33 This class presents a generic interface to initialize and run
34 a connection event loop for different types of listeners and
35 a callback functor to call on the connection event from the
36 listener that listens for connection. Listener type should
37 be a class providing methods setup_listener, listen_for_
38 connection_event and close_listener. The Connection event
39 callback functor object would on receiving connection event
40 from the client to process the connection.
41*/
42template <typename Listener>
44 Listener *m_listener;
45
46 public:
47 Connection_acceptor(Listener *listener) : m_listener(listener) {}
48
50
51 /**
52 Initialize a connection acceptor.
53
54 @retval return true if initialization failed, else false.
55 */
56 bool init_connection_acceptor() { return m_listener->setup_listener(); }
57
58 /**
59 Connection acceptor loop to accept connections from clients.
60 */
65 Channel_info *channel_info = m_listener->listen_for_connection_event();
66 if (channel_info != nullptr) mgr->process_new_connection(channel_info);
67 }
68 }
69
70 /**
71 Spawn admin connection handler to accept admin connections from clients if
72 create-admin-listener-thread is specified by user on commandline.
73
74 @return true unable to spawn admin connection handler thread else false.
75 */
77 return m_listener->check_and_spawn_admin_connection_handler_thread();
78 }
79
80 /**
81 Close the listener.
82 */
83 void close_listener() { m_listener->close_listener(); }
84};
85#endif // CONNECTION_ACCEPTOR_INCLUDED
This abstract base class represents connection channel information about a new connection.
Definition: channel_info.h:47
This class presents a generic interface to initialize and run a connection event loop for different t...
Definition: connection_acceptor.h:43
Listener * m_listener
Definition: connection_acceptor.h:44
void close_listener()
Close the listener.
Definition: connection_acceptor.h:83
void connection_event_loop()
Connection acceptor loop to accept connections from clients.
Definition: connection_acceptor.h:61
Connection_acceptor(Listener *listener)
Definition: connection_acceptor.h:47
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:76
~Connection_acceptor()
Definition: connection_acceptor.h:49
bool init_connection_acceptor()
Initialize a connection acceptor.
Definition: connection_acceptor.h:56
This is a singleton class that provides various connection management related functionalities,...
Definition: connection_handler_manager.h:59
void process_new_connection(Channel_info *channel_info)
Process a new incoming connection.
Definition: connection_handler_manager.cc:256
static Connection_handler_manager * get_instance()
Singleton method to return an instance of this class.
Definition: connection_handler_manager.h:143
bool connection_events_loop_aborted()
Definition: mysqld.h:752