|
My Project
|
#include <my_global.h>#include <mysql.h>#include <mysql_com.h>#include <mysqld_error.h>#include <my_sys.h>#include <m_string.h>#include <my_net.h>#include <violite.h>#include <signal.h>#include <errno.h>#include "probes_mysql.h"#include <algorithm>Defines | |
| #define | update_statistics(A) |
| #define | thd_increment_bytes_sent(N) |
| #define | VIO_SOCKET_ERROR ((size_t) -1) |
| #define | MAX_PACKET_LENGTH (256L*256L*256L-1) |
Functions | |
| my_bool | my_net_init (NET *net, Vio *vio) |
| void | net_end (NET *net) |
| my_bool | net_realloc (NET *net, size_t length) |
| void | net_clear (NET *net, my_bool check_buffer __attribute__((unused))) |
| my_bool | net_flush (NET *net) |
| my_bool | my_net_write (NET *net, const uchar *packet, size_t len) |
| my_bool | net_write_command (NET *net, uchar command, const uchar *header, size_t head_len, const uchar *packet, size_t len) |
| my_bool | net_write_packet (NET *net, const uchar *packet, size_t length) |
| ulong | my_net_read (NET *net) |
| void | my_net_set_read_timeout (NET *net, uint timeout) |
| void | my_net_set_write_timeout (NET *net, uint timeout) |
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 dynamicly when reading big packets. Each logical packet has the following pre-info: 3 byte length & 1 byte package-number.
This file needs to be written in C as it's used by the libmysql client as a C file.
| my_bool my_net_init | ( | NET * | net, |
| Vio * | vio | ||
| ) |
Init with packet info.
| 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.
| my_bool my_net_write | ( | NET * | net, |
| const uchar * | packet, | ||
| size_t | len | ||
| ) |
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.
| void net_clear | ( | NET * | net, |
| my_bool check_buffer | __attribute__(unused) | ||
| ) |
Clear (reinitialize) the NET structure for a new command.
| net | NET handler |
| check_buffer | Whether to check the socket buffer. |
| my_bool net_flush | ( | NET * | net | ) |
Flush write_buffer if not empty.
| my_bool net_realloc | ( | NET * | net, |
| size_t | length | ||
| ) |
Realloc the packet buffer.
| my_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 |
| my_bool net_write_packet | ( | NET * | net, |
| const uchar * | packet, | ||
| size_t | length | ||
| ) |
Write a MySQL protocol packet to the network handler.
| net | NET handler. |
| packet | The packet to write. |
| length | Length of the packet. |
1.7.6.1