MySQL 9.1.0
Source Code Documentation
|
This file is the net layer API for the MySQL client/server protocol. More...
#include <string.h>
#include <sys/types.h>
#include <algorithm>
#include <mysql/components/services/log_builtins.h>
#include <mysql/thread_pool_priv.h>
#include "../sql/current_thd.h"
#include "../sql/sql_class.h"
#include "../sql/sql_thd_internal_api.h"
#include "my_byteorder.h"
#include "my_compiler.h"
#include "my_dbug.h"
#include "my_io.h"
#include "my_macros.h"
#include "my_sys.h"
#include "mysql.h"
#include "mysql/service_mysql_alloc.h"
#include "mysql_async.h"
#include "mysql_com.h"
#include "mysqld_error.h"
#include "violite.h"
#include "sql/psi_memory_key.h"
#include "mysql_com_server.h"
Functions | |
void | thd_increment_bytes_sent (size_t length) |
void | thd_increment_bytes_received (size_t length) |
static bool | net_write_buff (NET *net, const uchar *packet, size_t len) |
Caching the data in a local buffer before sending it. More... | |
static uchar * | compress_packet (NET *net, const uchar *packet, size_t *length) |
Compress and encapsulate a packet into a compressed packet. More... | |
NET_EXTENSION * | net_extension_init () |
void | net_extension_free (NET *net) |
static mysql_compress_context * | compress_context (NET *net) |
Returns the appropriate compression_context based on caller. More... | |
bool | my_net_init (NET *net, Vio *vio) |
Init with packet info. More... | |
void | net_end (NET *net) |
void | net_claim_memory_ownership (NET *net, bool claim) |
bool | net_realloc (NET *net, size_t length) |
Realloc the packet buffer. More... | |
void | net_clear (NET *net, bool check_buffer) |
Clear (reinitialize) the NET structure for a new command. More... | |
bool | net_flush (NET *net) |
Flush write_buffer if not empty. More... | |
static bool | net_should_retry (NET *net, uint *retry_count) |
Whether a I/O operation should be retried later. More... | |
bool | my_net_write (NET *net, const uchar *packet, size_t len) |
Write a logical packet with packet header. More... | |
static void | reset_packet_write_state (NET *net) |
static int | begin_packet_write_state (NET *net, uchar command, const uchar *packet, size_t packet_len, const uchar *optional_prefix, size_t prefix_len) |
static net_async_status | net_write_vector_nonblocking (NET *net, ssize_t *res) |
net_async_status | net_write_command_nonblocking (NET *net, uchar command, const uchar *prefix, size_t prefix_len, const uchar *packet, size_t packet_len, bool *res) |
Send a command to the server in asynchronous way. More... | |
net_async_status | my_net_write_nonblocking (NET *net, const uchar *packet, size_t len, bool *res) |
bool | net_write_command (NET *net, uchar command, const uchar *header, size_t head_len, const uchar *packet, size_t len) |
Send a command to the server. More... | |
static bool | net_write_raw_loop (NET *net, const uchar *buf, size_t count) |
Write a determined number of bytes to a network handler. More... | |
bool | net_write_packet (NET *net, const uchar *packet, size_t length) |
Write a MySQL protocol packet to the network handler. More... | |
static bool | net_read_raw_loop (NET *net, size_t count) |
Read a determined number of bytes from a network handler. More... | |
static bool | net_read_packet_header (NET *net) |
Read the header of a packet. More... | |
static ulong | net_read_available (NET *net, size_t count) |
static net_async_status | net_read_data_nonblocking (NET *net, size_t count, bool *err_ptr) |
static net_async_status | net_read_packet_header_nonblocking (NET *net, bool *err_ptr) |
static net_async_status | net_read_packet_nonblocking (NET *net, ulong *ret) |
static void | net_read_init_offsets (NET *net, size_t &start_of_packet, size_t &first_packet_offset, uint &multi_byte_packet, size_t &buf_length) |
Initialize the offsets. More... | |
static bool | net_read_process_buffer (NET *net, size_t &start_of_packet, size_t &buf_length, uint &multi_byte_packet, size_t &first_packet_offset) |
Read the payload length in the packet, if it is found to multipacket omit the packet header of the subsequent packets. More... | |
static ulong | net_read_update_offsets (NET *net, size_t start_of_packet, size_t first_packet_offset, size_t buf_length, uint multi_byte_packet) |
Update the offsets in the NET structure after reading the current packet. More... | |
static net_async_status | net_read_compressed_nonblocking (NET *net, ulong *len_ptr) |
static net_async_status | net_read_uncompressed_nonblocking (NET *net, ulong *len_ptr) |
Read the usual packet that is not compressed asynchronously. More... | |
static size_t | net_read_packet (NET *net, size_t *complen) |
Read one (variable-length) MySQL protocol packet. More... | |
net_async_status | my_net_read_nonblocking (NET *net, ulong *len_ptr) |
static void | net_read_uncompressed_packet (NET *net, size_t &len) |
Reads one packet to net->buff + net->where_b. More... | |
static void | net_read_compressed_packet (NET *net, size_t &len) |
ulong | my_net_read (NET *net) |
Read a packet from the client/server and return it without the internal package header. More... | |
void | my_net_set_read_timeout (NET *net, uint timeout) |
void | my_net_set_write_timeout (NET *net, uint timeout) |
void | my_net_set_retry_count (NET *net, uint retry_count) |
This file is the net layer API for the MySQL client/server protocol.
Write and read of logical packets to/from socket.
Writes are cached into net_buffer_length big packets. Read packets are reallocated dynamically when reading big packets. Each logical packet has the following pre-info: 3 byte length & 1 byte package-number.
|
static |
|
static |
Returns the appropriate compression_context based on caller.
If the caller is server then fetch is from the server extension structure.
[in] | net | NET structure |
Compress and encapsulate a packet into a compressed packet.
net | NET handler. | |
packet | The packet to compress. | |
[in,out] | length | Length of the packet. |
See Compressed Packet Header for a description of the header structure.
ulong my_net_read | ( | NET * | net | ) |
Read a packet from the client/server and return it without the internal package header.
If the packet is the first packet of a multi-packet packet (which is indicated by the length of the packet = 0xffffff) then all sub packets are read and concatenated.
If the packet was compressed, its uncompressed and the length of the uncompressed packet is returned.
net_async_status my_net_read_nonblocking | ( | NET * | net, |
ulong * | len_ptr | ||
) |
void my_net_set_read_timeout | ( | NET * | net, |
uint | timeout | ||
) |
void my_net_set_retry_count | ( | NET * | net, |
uint | retry_count | ||
) |
void my_net_set_write_timeout | ( | NET * | net, |
uint | timeout | ||
) |
Write a logical packet with packet header.
Format: Packet length (3 bytes), packet number (1 byte) When compression is used, a 3 byte compression length is added.
net_async_status my_net_write_nonblocking | ( | NET * | net, |
const uchar * | packet, | ||
size_t | len, | ||
bool * | res | ||
) |
void net_claim_memory_ownership | ( | NET * | net, |
bool | claim | ||
) |
void net_clear | ( | NET * | net, |
bool | check_buffer | ||
) |
Clear (reinitialize) the NET structure for a new command.
net | NET handler |
check_buffer | Whether to check the socket buffer. |
void net_end | ( | NET * | net | ) |
void net_extension_free | ( | NET * | net | ) |
NET_EXTENSION * net_extension_init | ( | ) |
bool net_flush | ( | NET * | net | ) |
Flush write_buffer if not empty.
|
static |
|
static |
|
static |
|
static |
|
static |
Initialize the offsets.
If it is first packet then initialize the offsets from the beginning else initialize the offsets after the data last read in the old packet.
[in,out] | net | NET structure. |
[in,out] | start_of_packet | Starting offset of the packet to be read. In multipackets, points to the next header that will be erased. |
[in,out] | first_packet_offset | Starting offset of the packet to read. |
[in,out] | multi_byte_packet | Flag that indicate if packet is multibyte |
[in,out] | buf_length | End of readable byte. |
|
static |
Read one (variable-length) MySQL protocol packet.
A MySQL packet consists of a header and a payload.
packet_error
on error.
|
static |
Read the header of a packet.
The MySQL protocol packet header consists of the length, in bytes, of the payload (packet data) and a serial number.
net | NET handler. |
|
static |
|
static |
|
static |
Read the payload length in the packet, if it is found to multipacket omit the packet header of the subsequent packets.
[in,out] | net | NET structures |
[in,out] | start_of_packet | In multipackets, points to the next header that will be erased |
[in,out] | buf_length | End of readable byte |
[in,out] | multi_byte_packet | Flag that indicate if packet is multibyte |
[in,out] | first_packet_offset | Starting offset of the packet to read |
true | The last packet read |
false | Otherwise |
|
static |
Read a determined number of bytes from a network handler.
net | NET handler. |
count | The number of bytes to read. |
|
static |
Read the usual packet that is not compressed asynchronously.
[in,out] | net | NET structure |
[out] | len_ptr | length of the packet read |
|
static |
Reads one packet to net->buff + net->where_b.
If the packet is the first packet of a multi-packet packet (which is indicated by the length of the packet = 0xffffff) then all sub packets are read and concatenated.
[in,out] | net | NET structure |
[out] | len | length of the packet read |
|
static |
Update the offsets in the NET structure after reading the current packet.
[in,out] | net | NET structure. |
[in] | start_of_packet | In multipackets, points to the next header that will be erased. |
[in] | first_packet_offset | Starting offset of the packet to read. |
[in] | buf_length | End of readable byte. |
[in] | multi_byte_packet | Flag that indicate if packet is multibyte |
bool net_realloc | ( | NET * | net, |
size_t | length | ||
) |
Realloc the packet buffer.
|
static |
Whether a I/O operation should be retried later.
net | NET handler. |
retry_count | Maximum number of interrupted operations. |
true | Operation should be retried. |
false | Operation should not be retried. Fatal error. |
Caching the data in a local buffer before sending it.
Fill up net->buffer and send it to the client when full.
If the rest of the to-be-sent-packet is bigger than buffer, send it in one big block (to avoid copying to internal buffer). If not, copy the rest of the data to the buffer and return without sending data.
net | Network handler |
packet | Packet to send |
len | Length of packet |
0 | ok |
1 | error |
bool net_write_command | ( | NET * | net, |
uchar | command, | ||
const uchar * | header, | ||
size_t | head_len, | ||
const uchar * | packet, | ||
size_t | len | ||
) |
Send a command to the server.
The reason for having both header and packet is so that libmysql can easy add a header to a special command (like prepared statements) without having to re-alloc the string.
As the command is part of the first data packet, we have to do some data juggling to put the command in there, without having to create a new packet.
This function will split big packets into sub-packets if needed. (Each sub packet can only be 2^24 bytes)
net | NET handler |
command | Command in MySQL server (enum enum_server_command) |
header | Header to write after command |
head_len | Length of header |
packet | Query or parameter to query |
len | Length of packet |
0 | ok |
1 | error |
net_async_status net_write_command_nonblocking | ( | NET * | net, |
uchar | command, | ||
const uchar * | prefix, | ||
size_t | prefix_len, | ||
const uchar * | packet, | ||
size_t | packet_len, | ||
bool * | res | ||
) |
Send a command to the server in asynchronous way.
This function will first populate all headers in NET::async_write_headers, followed by payload in NET::async_write_vector. Once header and payload is populated in NET, were call net_write_vector_nonblocking to send the packets to server in an asynchronous way.
Write a MySQL protocol packet to the network handler.
net | NET handler. |
packet | The packet to write. |
length | Length of the packet. |
Write a determined number of bytes to a network handler.
net | NET handler. |
buf | Buffer containing the data to be written. |
count | The length, in bytes, of the buffer. |
|
static |
|
static |
void thd_increment_bytes_received | ( | size_t | length | ) |
void thd_increment_bytes_sent | ( | size_t | length | ) |