![]() |
MySQL 8.0.43
Source Code Documentation
|
#include "my_config.h"#include <errno.h>#include <fcntl.h>#include <sys/types.h>#include <time.h>#include <netdb.h>#include <stdio.h>#include <stdlib.h>#include <algorithm>#include "my_compiler.h"#include "my_dbug.h"#include "my_inttypes.h"#include "my_io.h"#include "my_macros.h"#include "mysys_err.h"#include "template_utils.h"#include "vio/vio_priv.h"#include <netinet/tcp.h>#include <poll.h>#include <sys/ioctl.h>#include "mysql/psi/mysql_socket.h"Macros | |
| #define | VIO_DONTWAIT 0 |
| #define | VIO_UNBUFFERED_READ_MIN_SIZE 2048 |
| #define | SOCKET_PRINTF_FORMAT "%d" |
| #define | POLLRDHUP 0 |
| Set of event flags grouped by operations. More... | |
| #define | MY_POLL_SET_IN (POLLIN | POLLPRI) |
| #define | MY_POLL_SET_OUT (POLLOUT) |
| #define | MY_POLL_SET_ERR (POLLERR | POLLHUP | POLLNVAL) |
Functions | |
| int | vio_errno (Vio *vio) |
| int | vio_socket_io_wait (Vio *vio, enum enum_vio_io_event event) |
| Attempt to wait for an I/O event on a socket. More... | |
| size_t | vio_read (Vio *vio, uchar *buf, size_t size) |
| size_t | vio_read_buff (Vio *vio, uchar *buf, size_t size) |
| bool | vio_buff_has_data (Vio *vio) |
| size_t | vio_write (Vio *vio, const uchar *buf, size_t size) |
| int | vio_set_blocking (Vio *vio, bool status) |
| int | vio_set_blocking_flag (Vio *vio, bool status) |
| bool | vio_is_blocking (Vio *vio) |
| int | vio_socket_timeout (Vio *vio, uint which, bool old_mode) |
| int | vio_fastsend (Vio *vio) |
| int | vio_keepalive (Vio *vio, bool set_keep_alive) |
| bool | vio_should_retry (Vio *vio) |
| Indicate whether a I/O operation must be retried later. More... | |
| bool | vio_was_timeout (Vio *vio) |
| Indicate whether a I/O operation timed out. More... | |
| static void | vio_wait_until_woken (Vio *vio) |
| int | vio_shutdown (Vio *vio) |
| void | vio_description (Vio *vio, char *buf) |
| enum enum_vio_type | vio_type (const Vio *vio) |
| my_socket | vio_fd (Vio *vio) |
| static void | vio_get_normalized_ip (const struct sockaddr *src, size_t src_length, struct sockaddr *dst, size_t *dst_length) |
| Convert a sock-address (AF_INET or AF_INET6) into the "normalized" form, which is the IPv4 form for IPv4-mapped or IPv4-compatible IPv6 addresses. More... | |
| 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. More... | |
| bool | vio_peer_addr (Vio *vio, char *ip_buffer, uint16 *port, size_t ip_buffer_size) |
| Return IP address and port of a VIO client socket. More... | |
| static bool | socket_peek_read (Vio *vio, uint *bytes) |
| Retrieve the amount of data that can be read from a socket. More... | |
| int | vio_io_wait (Vio *vio, enum enum_vio_io_event event, int timeout) |
| Wait for an I/O event on a VIO socket. More... | |
| bool | vio_socket_connect (Vio *vio, struct sockaddr *addr, socklen_t len, bool nonblocking, int timeout, bool *connect_done) |
| Connect to a peer address. More... | |
| bool | vio_is_connected (Vio *vio) |
| Determine if the endpoint of a connection is still available. More... | |
| ssize_t | vio_pending (Vio *vio) |
| Number of bytes in the read or socket buffer. More... | |
| 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. More... | |
| 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() implementation: More... | |
| #define MY_POLL_SET_ERR (POLLERR | POLLHUP | POLLNVAL) |
| #define MY_POLL_SET_IN (POLLIN | POLLPRI) |
| #define MY_POLL_SET_OUT (POLLOUT) |
| #define POLLRDHUP 0 |
Set of event flags grouped by operations.
| #define SOCKET_PRINTF_FORMAT "%d" |
| #define VIO_DONTWAIT 0 |
| #define VIO_UNBUFFERED_READ_MIN_SIZE 2048 |
Retrieve the amount of data that can be read from a socket.
| vio | A VIO object. | |
| [out] | bytes | The amount of bytes available. |
| false | Success. |
| true | Failure. |
| bool vio_buff_has_data | ( | Vio * | vio | ) |
| void vio_description | ( | Vio * | vio, |
| char * | buf | ||
| ) |
| int vio_errno | ( | Vio * | vio | ) |
| int vio_fastsend | ( | Vio * | vio | ) |
|
static |
Convert a sock-address (AF_INET or AF_INET6) into the "normalized" form, which is the IPv4 form for IPv4-mapped or IPv4-compatible IPv6 addresses.
Having three forms of one address makes it a little difficult to compare addresses with each other (the IPv4-compatible IPv6-address of foo.bar will be different from the IPv4-mapped IPv6-address of foo.bar).
| [in] | src | source IP address (AF_INET or AF_INET6). |
| [in] | src_length | length of the src. |
| [out] | dst | a buffer to store normalized IP address (sockaddr_storage). |
| [out] | dst_length | actual length of the normalized IP address. |
| 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.
The idea is to return an IPv4-address for an IPv4-mapped and IPv4-compatible IPv6 address.
The function writes the normalized IP address to the given buffer. The buffer should have enough space, otherwise error flag is returned. The system constant INET6_ADDRSTRLEN can be used to reserve buffers of the right size.
| [in] | addr | sockaddr object (AF_INET or AF_INET6). |
| [in] | addr_length | length of the addr. |
| [out] | ip_string | buffer to write normalized IP address. |
| [in] | ip_string_size | size of the ip_string. |
| true | in case of error (the ip_string buffer is not enough). |
| false | on success. |
| 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() implementation:
| int vio_io_wait | ( | Vio * | vio, |
| enum enum_vio_io_event | event, | ||
| int | timeout | ||
| ) |
Wait for an I/O event on a VIO socket.
| vio | VIO object representing a connected socket. |
| event | The type of I/O event to wait for. |
| timeout | Interval (in milliseconds) to wait for an I/O event. A negative timeout value means an infinite timeout. |
| -1 | Failure, socket_errno indicates the error. |
| 0 | The wait has timed out. |
| 1 | The requested I/O event has occurred. |
| bool vio_is_blocking | ( | Vio * | vio | ) |
| bool vio_is_connected | ( | Vio * | vio | ) |
Determine if the endpoint of a connection is still available.
| vio | The VIO object. |
| true | EOF condition not found. |
| false | EOF condition is signaled. |
| 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.
Windows-specific note: getnameinfo() returns WSANO_DATA instead of EAI_NODATA or EAI_NONAME when no reverse mapping is available at the host (i.e. Windows can't get hostname by IP-address). This error should be treated as EAI_NONAME.
| true | if the error code is EAI_NONAME. |
| false | otherwise. |
| int vio_keepalive | ( | Vio * | vio, |
| bool | set_keep_alive | ||
| ) |
Return IP address and port of a VIO client socket.
The function returns an IPv4 address if IPv6 support is disabled.
The function returns an IPv4 address if the client socket is associated with an IPv4-compatible or IPv4-mapped IPv6 address. Otherwise, the native IPv6 address is returned.
| ssize_t vio_pending | ( | Vio * | vio | ) |
Number of bytes in the read or socket buffer.
| int vio_set_blocking | ( | Vio * | vio, |
| bool | status | ||
| ) |
| int vio_set_blocking_flag | ( | Vio * | vio, |
| bool | status | ||
| ) |
| bool vio_should_retry | ( | Vio * | vio | ) |
Indicate whether a I/O operation must be retried later.
| vio | A VIO object |
| true | Temporary failure, retry operation. |
| false | Indeterminate failure. |
| int vio_shutdown | ( | Vio * | vio | ) |
| bool vio_socket_connect | ( | Vio * | vio, |
| struct sockaddr * | addr, | ||
| socklen_t | len, | ||
| bool | nonblocking, | ||
| int | timeout, | ||
| bool * | connect_done | ||
| ) |
Connect to a peer address.
| vio | A VIO object. | |
| addr | Socket address containing the peer address. | |
| len | Length of socket address. | |
| nonblocking | flag to represent if socket is blocking or nonblocking | |
| timeout | Interval (in milliseconds) to wait until a connection is established. | |
| [out] | connect_done | Indication if connect actually completed or not. If set to true this means there's no need to wait for connect to complete anymore. |
| false | A connection was successfully established. |
| true | A fatal error. See socket_errno. |
| int vio_socket_io_wait | ( | Vio * | vio, |
| enum enum_vio_io_event | event | ||
| ) |
Attempt to wait for an I/O event on a socket.
| vio | VIO object representing a connected socket. |
| event | The type of I/O event (read or write) to wait for. |
| enum enum_vio_type vio_type | ( | const Vio * | vio | ) |
|
static |
| bool vio_was_timeout | ( | Vio * | vio | ) |
Indicate whether a I/O operation timed out.
| vio | A VIO object |
| true | Operation timed out. |
| false | Not a timeout failure. |