36#ifdef HAVE_SYS_SOCKET_H
37#include <sys/socket.h>
55#if !defined(_WIN32) && !defined(HAVE_KQUEUE)
56#define USE_PPOLL_IN_VIO
59#if defined(__cplusplus) && defined(USE_PPOLL_IN_VIO)
63#elif defined(__cplusplus) && defined(HAVE_KQUEUE)
68#ifdef HAVE_PSI_INTERFACE
76#define MYSQL_VIO Vio *
138#define VIO_SOCKET_ERROR ((size_t)-1)
139#define VIO_SOCKET_WANT_READ ((size_t)-2)
140#define VIO_SOCKET_WANT_WRITE ((size_t)-3)
142#define VIO_LOCALHOST 1
143#define VIO_BUFFERED_READ 2
144#define VIO_READ_BUFFER_SIZE 16384
153 HANDLE event_server_wrote,
155 HANDLE event_client_wrote,
157 HANDLE event_conn_closed);
182#define VIO_DESCRIPTION_SIZE 30
204 bool *connect_done =
nullptr);
207 size_t addr_length,
char *ip_string,
208 size_t ip_string_size);
213 size_t hostname_size,
char *
port,
size_t port_size,
217#include <openssl/opensslv.h>
219#if OPENSSL_VERSION_NUMBER < 0x0090700f
220#define DES_cblock des_cblock
221#define DES_key_schedule des_key_schedule
222#define DES_set_key_unchecked(k, ks) des_set_key_unchecked((k), *(ks))
223#define DES_ede3_cbc_encrypt(i, o, l, k1, k2, k3, iv, e) \
224 des_ede3_cbc_encrypt((i), (o), (l), *(k1), *(k2), *(k3), (iv), (e))
227#if OPENSSL_VERSION_NUMBER >= 0x10100000L
228#define HAVE_OPENSSL11 1
231#define HEADER_DES_LOCL_H dummy_something
233#include <openssl/err.h>
234#include <openssl/ssl.h>
261 unsigned long *errptr);
263 SSL_SESSION *session,
unsigned long *errptr, SSL **
ssl,
264 const char *sni_servername);
267 const char *key_file,
const char *cert_file,
const char *ca_file,
268 const char *ca_path,
const char *cipher,
const char *ciphersuites,
270 const long ssl_ctx_flags,
const char *server_host);
275 const char *key_file,
const char *cert_file,
const char *ca_file,
276 const char *ca_path,
const char *cipher,
const char *ciphersuites,
278 const long ssl_ctx_flags);
286#if !defined(DONT_MAP_VIO)
287#define vio_delete(vio) (vio)->viodelete(vio)
288#define vio_errno(vio) (vio)->vioerrno(vio)
289#define vio_read(vio, buf, size) ((vio)->read)(vio, buf, size)
290#define vio_write(vio, buf, size) ((vio)->write)(vio, buf, size)
291#define vio_fastsend(vio) (vio)->fastsend(vio)
292#define vio_keepalive(vio, set_keep_alive) \
293 (vio)->viokeepalive(vio, set_keep_alive)
294#define vio_should_retry(vio) (vio)->should_retry(vio)
295#define vio_was_timeout(vio) (vio)->was_timeout(vio)
296#define vio_shutdown(vio) ((vio)->vioshutdown)(vio)
297#define vio_peer_addr(vio, buf, prt, buflen) \
298 (vio)->peer_addr(vio, buf, prt, buflen)
299#define vio_io_wait(vio, event, timeout) (vio)->io_wait(vio, event, timeout)
300#define vio_is_connected(vio) (vio)->is_connected(vio)
301#define vio_is_blocking(vio) (vio)->is_blocking(vio)
302#define vio_set_blocking(vio, val) (vio)->set_blocking(vio, val)
303#define vio_set_blocking_flag(vio, val) (vio)->set_blocking_flag(vio, val)
338#ifdef USE_PPOLL_IN_VIO
366#elif defined HAVE_KQUEUE
368 std::atomic_flag kevent_wakeup_flag = ATOMIC_FLAG_INIT;
409 OVERLAPPED overlapped = {0, 0, {{0, 0}},
nullptr};
412 OVERLAPPED overlapped = {0};
422 HANDLE handle_file_map = {
nullptr};
423 char *handle_map = {
nullptr};
424 HANDLE event_server_wrote = {
nullptr};
425 HANDLE event_server_read = {
nullptr};
426 HANDLE event_client_wrote = {
nullptr};
427 HANDLE event_client_read = {
nullptr};
428 HANDLE event_conn_closed = {
nullptr};
429 size_t shared_memory_remain = {0};
430 char *shared_memory_pos = {
nullptr};
454#define SSL_handle SSL *
struct PSI_socket_locker PSI_socket_locker
Definition: psi_socket_bits.h:77
static int flags[50]
Definition: hp_test1.cc:40
static int kq_fd
Definition: kqueue_timers.cc:45
Some integer typedefs for easier portability.
unsigned char uchar
Definition: my_inttypes.h:52
uint16_t uint16
Definition: my_inttypes.h:65
Types to make file and socket I/O compatible.
Defines various enable/disable and HAVE_ macros related to the performance schema instrumentation sys...
Types to make different thread packages compatible.
int my_socket
Definition: mysql.h:65
void error(const char *format,...)
std::string str(const mysqlrouter::ConfigGenerator::Options::Endpoint &ep)
Definition: config_generator.cc:1105
Definition: buf0block_hint.cc:30
constexpr value_type ssl
Definition: classic_protocol_constants.h:49
static Value err()
Create a Value object that represents an error condition.
Definition: json_binary.cc:908
static bool timeout(bool(*wait_condition)())
Timeout function.
Definition: log0meb.cc:498
size_t size(const char *const c)
Definition: base64.h:46
required uint64 port
Definition: replication_asynchronous_connection_failover.proto:33
required string type
Definition: replication_group_member_actions.proto:34
required string event
Definition: replication_group_member_actions.proto:32
struct sockaddr sockaddr
Definition: sock_probe_win32.h:63
struct in_addr in_addr
Definition: sock_probe_win32.h:65
An instrumented socket.
Definition: mysql_socket_bits.h:35
State data storage for start_socket_wait_v1_t.
Definition: psi_socket_bits.h:158
Definition: violite.h:320
size_t(* read)(MYSQL_VIO, uchar *, size_t)
Definition: violite.h:388
PSI_socket_locker_state m_psi_write_state
Definition: violite.h:420
char * read_end
Definition: violite.h:336
bool localhost
Definition: violite.h:322
friend bool vio_reset(Vio *vio, enum_vio_type type, my_socket sd, void *ssl, uint flags)
Reinitialize an existing Vio object.
Definition: vio.cc:353
int(* vioshutdown)(MYSQL_VIO)
Definition: violite.h:402
int write_timeout
Definition: violite.h:326
int(* fastsend)(MYSQL_VIO)
Definition: violite.h:392
sigset_t signal_mask
Definition: violite.h:350
char * read_buffer
Definition: violite.h:333
std::optional< my_thread_t > thread_id
Thread PID which is to be sent SIGALRM to terminate ppoll wait when shutting down vio.
Definition: violite.h:349
int(* set_blocking)(Vio *vio, bool val)
Definition: violite.h:434
PSI_socket_locker_state m_psi_read_state
Definition: violite.h:418
bool(* should_retry)(MYSQL_VIO)
Definition: violite.h:395
std::atomic_flag poll_shutdown_flag
Definition: violite.h:365
char network_namespace[256]
Socket network namespace.
Definition: violite.h:375
char * read_pos
Definition: violite.h:334
int(* set_blocking_flag)(Vio *vio, bool val)
Definition: violite.h:435
int(* vioerrno)(MYSQL_VIO)
Definition: violite.h:387
bool(* is_blocking)(Vio *vio)
Definition: violite.h:433
size_t(* write)(MYSQL_VIO, const uchar *, size_t)
Definition: violite.h:389
bool is_blocking_flag
Definition: violite.h:437
bool(* peer_addr)(MYSQL_VIO, char *, uint16 *, size_t)
Definition: violite.h:393
enum_vio_type type
Definition: violite.h:323
bool(* connect)(MYSQL_VIO, struct sockaddr *, socklen_t, int)
Definition: violite.h:406
friend void internal_vio_delete(Vio *vio)
Definition: vio.cc:547
void(* viodelete)(MYSQL_VIO)
Definition: violite.h:386
bool inactive
Definition: violite.h:328
~Vio()
Definition: vio.cc:116
int(* viokeepalive)(MYSQL_VIO, bool)
Definition: violite.h:391
struct PSI_socket_locker * m_psi_write_locker
Definition: violite.h:419
friend Vio * internal_vio_create(uint flags)
Definition: vio.cc:418
size_t addrLen
Definition: violite.h:332
MYSQL_SOCKET mysql_socket
Definition: violite.h:321
bool(* was_timeout)(MYSQL_VIO)
Definition: violite.h:396
struct PSI_socket_locker * m_psi_read_locker
Definition: violite.h:417
int retry_count
Definition: violite.h:327
void * ssl_arg
Definition: violite.h:416
Vio & operator=(const Vio &)=delete
Vio(uint flags)
Definition: vio.cc:102
int read_timeout
Definition: violite.h:325
int(* io_wait)(MYSQL_VIO, enum enum_vio_io_event, int)
Definition: violite.h:405
int(* timeout)(MYSQL_VIO, uint, bool)
Definition: violite.h:390
struct sockaddr_storage remote
Definition: violite.h:331
bool(* is_connected)(MYSQL_VIO)
Definition: violite.h:403
bool(* has_data)(MYSQL_VIO)
Definition: violite.h:404
Definition: violite.h:256
SSL_CTX * ssl_context
Definition: violite.h:257
void vio_ssl_end()
Definition: viosslfactories.cc:294
#define vio_errno(vio)
Definition: violite.h:288
my_socket vio_fd(MYSQL_VIO vio)
SSL_type
Definition: violite.h:307
@ SSL_TYPE_NOT_SPECIFIED
Definition: violite.h:308
@ SSL_TYPE_NONE
Definition: violite.h:309
@ SSL_TYPE_ANY
Definition: violite.h:310
@ SSL_TYPE_X509
Definition: violite.h:311
@ SSL_TYPE_SPECIFIED
Definition: violite.h:312
#define vio_is_blocking(vio)
Definition: violite.h:301
#define vio_keepalive(vio, set_keep_alive)
Definition: violite.h:292
MYSQL_VIO vio_new(my_socket sd, enum enum_vio_type type, uint flags)
Definition: vio.cc:445
bool vio_reset(MYSQL_VIO vio, enum enum_vio_type type, my_socket sd, void *ssl, uint flags)
long process_tls_version(const char *tls_version)
Definition: viosslfactories.cc:333
enum enum_vio_type vio_type(const MYSQL_VIO vio)
void ssl_start(void)
Definition: viosslfactories.cc:317
int sslaccept(struct st_VioSSLFd *, MYSQL_VIO, long timeout, unsigned long *errptr)
void vio_end(void)
Definition: vio.cc:561
int vio_timeout(MYSQL_VIO vio, uint which, int timeout_sec)
#define MYSQL_VIO
Definition: violite.h:76
#define vio_should_retry(vio)
Definition: violite.h:294
#define vio_set_blocking_flag(vio, val)
Definition: violite.h:303
struct st_VioSSLFd * new_VioSSLConnectorFd(const char *key_file, const char *cert_file, const char *ca_file, const char *ca_path, const char *cipher, const char *ciphersuites, enum enum_ssl_init_error *error, const char *crl_file, const char *crl_path, const long ssl_ctx_flags, const char *server_host)
Definition: viosslfactories.cc:575
void get_vio_type_name(enum enum_vio_type vio_type, const char **str, int *len)
Convert a vio type to a printable string.
Definition: vio.cc:582
int sslconnect(struct st_VioSSLFd *, MYSQL_VIO, long timeout, SSL_SESSION *session, unsigned long *errptr, SSL **ssl, const char *sni_servername)
void vio_description(MYSQL_VIO vio, char *buf)
const char * sslGetErrString(enum enum_ssl_init_error err)
Definition: viosslfactories.cc:93
enum_ssl_init_error
Definition: violite.h:236
@ SSL_FIPS_MODE_INVALID
Definition: violite.h:247
@ SSL_INITERR_NO_USABLE_CTX
Definition: violite.h:244
@ SSL_FIPS_MODE_FAILED
Definition: violite.h:248
@ SSL_INITERR_X509_VERIFY_PARAM
Definition: violite.h:250
@ SSL_INITERR_KEY
Definition: violite.h:239
@ SSL_INITERR_LASTERR
Definition: violite.h:252
@ SSL_INITERR_CERT
Definition: violite.h:238
@ SSL_INITERR_BAD_PATHS
Definition: violite.h:241
@ SSL_INITERR_INVALID_CERTIFICATES
Definition: violite.h:251
@ SSL_INITERR_NOMATCH
Definition: violite.h:240
@ SSL_INITERR_MEMFAIL
Definition: violite.h:243
@ SSL_INITERR_ECDHFAIL
Definition: violite.h:249
@ SSL_INITERR_CIPHERS
Definition: violite.h:242
@ SSL_TLS_VERSION_INVALID
Definition: violite.h:246
@ SSL_INITERR_NOERROR
Definition: violite.h:237
@ SSL_INITERR_DHFAIL
Definition: violite.h:245
void free_vio_ssl_acceptor_fd(struct st_VioSSLFd *fd)
Definition: viosslfactories.cc:632
bool vio_is_no_name_error(int err_code)
Checks if the error code, returned by vio_getnameinfo(), means it was the "No-name" error.
Definition: viosocket.cc:1237
enum_vio_io_event
VIO I/O events.
Definition: violite.h:132
@ VIO_IO_EVENT_WRITE
Definition: violite.h:134
@ VIO_IO_EVENT_CONNECT
Definition: violite.h:135
@ VIO_IO_EVENT_READ
Definition: violite.h:133
#define vio_fastsend(vio)
Definition: violite.h:291
#define vio_set_blocking(vio, val)
Definition: violite.h:302
#define vio_shutdown(vio)
Definition: violite.h:296
size_t vio_read_buff(MYSQL_VIO vio, uchar *buf, size_t size)
#define vio_delete(vio)
Definition: violite.h:287
bool vio_socket_connect(MYSQL_VIO vio, struct sockaddr *addr, socklen_t len, bool nonblocking, int timeout, bool *connect_done=nullptr)
void init_vio_psi_keys()
Definition: vio.cc:63
#define HANDLE
Definition: violite.h:159
#define vio_peer_addr(vio, buf, prt, buflen)
Definition: violite.h:297
ssize_t vio_pending(MYSQL_VIO vio)
Vio Vio
Definition: violite.h:73
#define vio_was_timeout(vio)
Definition: violite.h:295
#define vio_read(vio, buf, size)
Definition: violite.h:289
#define vio_write(vio, buf, size)
Definition: violite.h:290
#define vio_io_wait(vio, event, timeout)
Definition: violite.h:299
struct st_VioSSLFd * new_VioSSLAcceptorFd(const char *key_file, const char *cert_file, const char *ca_file, const char *ca_path, const char *cipher, const char *ciphersuites, enum enum_ssl_init_error *error, const char *crl_file, const char *crl_path, const long ssl_ctx_flags)
Definition: viosslfactories.cc:603
enum_vio_type
Definition: violite.h:79
@ LAST_VIO_TYPE
Definition: violite.h:118
@ VIO_TYPE_SHARED_MEMORY
Used for shared memory connections.
Definition: violite.h:103
@ NO_VIO_TYPE
Type of the connection is unknown.
Definition: violite.h:83
@ FIRST_VIO_TYPE
Definition: violite.h:113
@ VIO_TYPE_PLUGIN
Implicitly used by plugins that doesn't support any other VIO_TYPE.
Definition: violite.h:111
@ VIO_TYPE_SSL
Used in case of SSL connections.
Definition: violite.h:99
@ VIO_TYPE_NAMEDPIPE
Used for named pipe connections.
Definition: violite.h:95
@ VIO_TYPE_TCPIP
Used in case of TCP/IP connections.
Definition: violite.h:87
@ VIO_TYPE_LOCAL
Used internally by the prepared statements.
Definition: violite.h:107
@ VIO_TYPE_SOCKET
Used for Unix Domain socket connections.
Definition: violite.h:91
bool vio_get_normalized_ip_string(const struct sockaddr *addr, size_t addr_length, char *ip_string, size_t ip_string_size)
Return the normalized IP address string for a sock-address.
Definition: viosocket.cc:640
#define vio_is_connected(vio)
Definition: violite.h:300
MYSQL_VIO mysql_socket_vio_new(MYSQL_SOCKET mysql_socket, enum enum_vio_type type, uint flags)
Definition: vio.cc:426
int vio_getnameinfo(const struct sockaddr *sa, char *hostname, size_t hostname_size, char *port, size_t port_size, int flags)
This is a wrapper for the system getnameinfo(), because different OS differ in the getnameinfo() impl...
Definition: viosocket.cc:1258