MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
net_serv.cc File Reference
#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>
Include dependency graph for net_serv.cc:

Go to the source code of this file.

Macros

#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)

Detailed Description

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.

Definition in file net_serv.cc.

Function Documentation

my_bool my_net_init ( NET net,
Vio vio 
)

Init with packet info.

Definition at line 98 of file net_serv.cc.

Here is the caller graph for this function:

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.

Returns
The function returns the length of the found packet or packet_error. net->read_pos points to the read data.

Definition at line 878 of file net_serv.cc.

Here is the caller graph for this function:

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.

Note
If compression is used, the original packet is modified!

Definition at line 279 of file net_serv.cc.

Here is the caller graph for this function:

void net_clear ( NET net,
my_bool check_buffer   __attribute__(unused) 
)

Clear (reinitialize) the NET structure for a new command.

Remarks
Performs debug checking of the socket buffer to ensure that the protocol sequence is correct.
Parameters
netNET handler
check_bufferWhether to check the socket buffer.

Definition at line 193 of file net_serv.cc.

my_bool net_flush ( NET net)

Flush write_buffer if not empty.

Definition at line 213 of file net_serv.cc.

Here is the call graph for this function:

Here is the caller graph for this function:

my_bool net_realloc ( NET net,
size_t  length 
)

Realloc the packet buffer.

Definition at line 141 of file net_serv.cc.

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)

Parameters
netNET handler
commandCommand in MySQL server (enum enum_server_command)
headerHeader to write after command
head_lenLength of header
packetQuery or parameter to query
lenLength of packet
Return values
0ok
1error

Definition at line 353 of file net_serv.cc.

Here is the call graph for this function:

my_bool net_write_packet ( NET net,
const uchar *  packet,
size_t  length 
)

Write a MySQL protocol packet to the network handler.

Parameters
netNET handler.
packetThe packet to write.
lengthLength of the packet.
Remarks
The packet might be encapsulated into a compressed packet.
Returns
TRUE on error, FALSE on success.

Definition at line 596 of file net_serv.cc.

Here is the caller graph for this function: