MySQL 8.3.0
Source Code Documentation
socket_connection.cc File Reference
#include "sql/conn_handler/socket_connection.h"
#include "my_config.h"
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <netdb.h>
#include <netinet/in.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <unistd.h>
#include <algorithm>
#include <atomic>
#include <memory>
#include <new>
#include <utility>
#include "m_string.h"
#include "my_dbug.h"
#include "my_io.h"
#include "my_sys.h"
#include "my_thread.h"
#include "mysql/components/services/log_builtins.h"
#include "mysql/my_loglevel.h"
#include "mysql/psi/mysql_thread.h"
#include "mysqld_error.h"
#include "sql-common/net_ns.h"
#include "sql/auth/sql_security_ctx.h"
#include "sql/conn_handler/channel_info.h"
#include "sql/conn_handler/init_net_server_extension.h"
#include "sql/log.h"
#include "sql/mysqld.h"
#include "sql/sql_class.h"
#include "sql/sql_const.h"
#include "violite.h"
#include <sys/un.h>
#include "connection_handler_manager.h"

Classes

struct  anonymous_namespace{socket_connection.cc}::FreeAddrInfoDeleter
 
class  Channel_info_local_socket
 This class abstracts the info. More...
 
class  Channel_info_tcpip_socket
 This class abstracts the info. More...
 
class  TCP_socket
 TCP_socket class represents the TCP sockets abstraction. More...
 
class  Unix_socket
 The Unix_socket class represents an abstraction for creating a unix socket ready to listen for new connections from clients. More...
 

Namespaces

namespace  anonymous_namespace{socket_connection.cc}
 

Typedefs

using anonymous_namespace{socket_connection.cc}::AddrInfoPtr = std::unique_ptr< addrinfo, FreeAddrInfoDeleter >
 
using admin_thread_arg_t = std::pair< MYSQL_SOCKET, std::string >
 

Functions

AddrInfoPtr anonymous_namespace{socket_connection.cc}::GetAddrInfoPtr (const char *node, const char *service, const addrinfo *hints)
 
ulong get_connection_errors_query_block ()
 
ulong get_connection_errors_accept ()
 
ulong get_connection_errors_tcpwrap ()
 
static bool accept_connection (MYSQL_SOCKET listen_sock, MYSQL_SOCKET *connect_sock)
 Accept a new connection on a ready listening socket. More...
 
static void init_psi_keys (void)
 
static void mark_admin_thread_started ()
 Signal to a spawning thread that spawned thread has been started. More...
 
static void wait_for_admin_thread_started ()
 Wait until admin thread has started execution. More...
 
static bool handle_admin_socket (MYSQL_SOCKET admin_socket, const std::string &network_namespace_for_listening_socket)
 Listen to admin interface and accept incoming connection on it. More...
 
void * admin_socket_thread (void *arg)
 Initialize thread's internal structures, run thread loop, deinitialize thread's internal structure on thread exit. More...
 
static void initialize_thread_context ()
 Initialize context required for running a thread handling connection requests on admin interface. More...
 
static bool spawn_admin_thread (MYSQL_SOCKET admin_socket, const std::string &network_namespace)
 Spawn a thread for handling incoming connections request on admin interface. More...
 

Variables

static constexpr const uint MAX_ACCEPT_RETRY {10}
 
static std::atomic< ulong > connection_errors_query_block {0}
 Number of connection errors when selecting on the listening port. More...
 
static std::atomic< ulong > connection_errors_accept {0}
 Number of connection errors when accepting sockets in the listening port. More...
 
static std::atomic< ulong > connection_errors_tcpwrap {0}
 Number of connection errors from TCP wrappers. More...
 
const char * MY_BIND_ALL_ADDRESSES = "*"
 MY_BIND_ALL_ADDRESSES defines a special value for the bind-address option, which means that the server should listen to all available network addresses, both IPv6 (if available) and IPv4. More...
 
const char * ipv4_all_addresses = "0.0.0.0"
 
const char * ipv6_all_addresses = "::"
 
static my_thread_handle admin_socket_thread_id
 
static my_thread_attr_t admin_socket_thread_attrib
 
static bool admin_thread_started = false
 
static mysql_mutex_t LOCK_start_admin_thread
 
static mysql_cond_t COND_start_admin_thread
 
static PSI_mutex_key key_LOCK_start_admin_thread
 
static PSI_cond_key key_COND_start_admin_thread
 
static PSI_mutex_info admin_socket_thread_mutexes []
 
static PSI_cond_info admin_socket_thread_conds []
 

Typedef Documentation

◆ admin_thread_arg_t

using admin_thread_arg_t = std::pair<MYSQL_SOCKET, std::string>

Function Documentation

◆ accept_connection()

static bool accept_connection ( MYSQL_SOCKET  listen_sock,
MYSQL_SOCKET connect_sock 
)
static

Accept a new connection on a ready listening socket.

Parameters
listen_sockListening socket ready to accept a new connection
[out]connect_sockSocket corresponding to a new accepted connection
Returns
operation result
Return values
trueon error
falseon success

◆ admin_socket_thread()

void * admin_socket_thread ( void *  arg)

Initialize thread's internal structures, run thread loop, deinitialize thread's internal structure on thread exit.

Parameters
argpointer to a socket for listening to admin interface

◆ get_connection_errors_accept()

ulong get_connection_errors_accept ( )

◆ get_connection_errors_query_block()

ulong get_connection_errors_query_block ( )

◆ get_connection_errors_tcpwrap()

ulong get_connection_errors_tcpwrap ( )

◆ handle_admin_socket()

static bool handle_admin_socket ( MYSQL_SOCKET  admin_socket,
const std::string &  network_namespace_for_listening_socket 
)
static

Listen to admin interface and accept incoming connection on it.

This function is run in a separate thread.

Returns
operation result. false on success, true on error
Parameters
admin_socketpointer to a socket for listening to admin interface
network_namespace_for_listening_socketnetwork namespace associated with the socket

◆ init_psi_keys()

static void init_psi_keys ( void  )
inlinestatic

◆ initialize_thread_context()

static void initialize_thread_context ( )
inlinestatic

Initialize context required for running a thread handling connection requests on admin interface.

Such context include mutex LOCK_start_admin_thread, condition variable COND_start_admin_thread and attributes used for thread spawning.

◆ mark_admin_thread_started()

static void mark_admin_thread_started ( )
inlinestatic

Signal to a spawning thread that spawned thread has been started.

◆ spawn_admin_thread()

static bool spawn_admin_thread ( MYSQL_SOCKET  admin_socket,
const std::string &  network_namespace 
)
inlinestatic

Spawn a thread for handling incoming connections request on admin interface.

Parameters
admin_socketA socket to listen corresponding admin interface.
network_namespaceNetwork namespace to use for communicating via admin socket
Returns
Operation result. false on success, true on failure.

◆ wait_for_admin_thread_started()

static void wait_for_admin_thread_started ( )
inlinestatic

Wait until admin thread has started execution.

Variable Documentation

◆ admin_socket_thread_attrib

my_thread_attr_t admin_socket_thread_attrib
static

◆ admin_socket_thread_conds

PSI_cond_info admin_socket_thread_conds[]
static
Initial value:
= {
{&key_COND_start_admin_thread, "COND_start_admin_thread",
#define PSI_DOCUMENT_ME
Definition: component_common.h:28
#define PSI_FLAG_SINGLETON
Singleton flag.
Definition: component_common.h:34
static PSI_cond_key key_COND_start_admin_thread
Definition: socket_connection.cc:1011

◆ admin_socket_thread_id

my_thread_handle admin_socket_thread_id
static

◆ admin_socket_thread_mutexes

PSI_mutex_info admin_socket_thread_mutexes[]
static
Initial value:
= {
{&key_LOCK_start_admin_thread, "LOCK_start_admin_thread",
static PSI_mutex_key key_LOCK_start_admin_thread
Definition: socket_connection.cc:1010

◆ admin_thread_started

bool admin_thread_started = false
static

◆ COND_start_admin_thread

mysql_cond_t COND_start_admin_thread
static

◆ connection_errors_accept

std::atomic<ulong> connection_errors_accept {0}
static

Number of connection errors when accepting sockets in the listening port.

◆ connection_errors_query_block

std::atomic<ulong> connection_errors_query_block {0}
static

Number of connection errors when selecting on the listening port.

◆ connection_errors_tcpwrap

std::atomic<ulong> connection_errors_tcpwrap {0}
static

Number of connection errors from TCP wrappers.

◆ ipv4_all_addresses

const char* ipv4_all_addresses = "0.0.0.0"

◆ ipv6_all_addresses

const char* ipv6_all_addresses = "::"

◆ key_COND_start_admin_thread

PSI_cond_key key_COND_start_admin_thread
static

◆ key_LOCK_start_admin_thread

PSI_mutex_key key_LOCK_start_admin_thread
static

◆ LOCK_start_admin_thread

mysql_mutex_t LOCK_start_admin_thread
static

◆ MAX_ACCEPT_RETRY

constexpr const uint MAX_ACCEPT_RETRY {10}
staticconstexpr

◆ MY_BIND_ALL_ADDRESSES

const char* MY_BIND_ALL_ADDRESSES = "*"

MY_BIND_ALL_ADDRESSES defines a special value for the bind-address option, which means that the server should listen to all available network addresses, both IPv6 (if available) and IPv4.

Basically, this value instructs the server to make an attempt to bind the server socket to '::' address, and rollback to '0.0.0.0' if the attempt fails.