MySQL  8.0.15
Source Code Documentation
Protocol_classic Class Referenceabstract

#include <protocol_classic.h>

Inheritance diagram for Protocol_classic:
Protocol Protocol_text Protocol_binary

Public Member Functions

 Protocol_classic ()
 
 Protocol_classic (THD *thd)
 
virtual ~Protocol_classic ()
 
void init (THD *thd_arg)
 
virtual int read_packet ()
 Read packet from client. More...
 
virtual int get_command (COM_DATA *com_data, enum_server_command *cmd)
 Reads the command from the protocol and creates a command. More...
 
virtual bool create_command (COM_DATA *com_data, enum_server_command cmd, uchar *pkt, size_t length)
 Parses the passed parameters and creates a command. More...
 
virtual bool flush ()
 Used for the classic protocol. More...
 
virtual void end_partial_result_set ()
 Finish the result set with EOF packet, as is expected by the client, if there is an error evaluating the next row and a continue handler for the error. More...
 
virtual void start_row ()=0
 Result set sending functions. More...
 
virtual bool end_row ()
 
virtual uint get_rw_status ()
 Returns the read/writing status. More...
 
virtual bool get_compression ()
 Returns if the protocol is compressed or not. More...
 
virtual bool start_result_metadata (uint num_cols, uint flags, const CHARSET_INFO *resultcs)
 Prepares the server for metadata sending. More...
 
virtual bool end_result_metadata ()
 Signals the client that the metadata sending is done. More...
 
virtual bool send_field_metadata (Send_field *field, const CHARSET_INFO *item_charset)
 Sends a single column metadata. More...
 
virtual void abort_row ()
 
virtual enum enum_protocol_type type ()=0
 
virtual enum enum_vio_type connection_type ()
 Returns the type of the connection. More...
 
virtual my_socket get_socket ()
 
bool init_net (Vio *vio)
 
void claim_memory_ownership ()
 
void end_net ()
 
bool write (const uchar *ptr, size_t len)
 
uchar get_error ()
 
void set_max_packet_size (ulong max_packet_size)
 
virtual int shutdown (bool server_shutdown=false)
 Thread is being shut down, disconnect and free resources. More...
 
void wipe_net ()
 
virtual bool connection_alive ()
 Checks if the protocol's connection with the client is still alive. More...
 
virtual ulong get_client_capabilities ()
 Returns the client capabilities stored on the protocol. More...
 
void set_client_capabilities (ulong client_capabilities)
 
void add_client_capability (ulong client_capability)
 
void remove_client_capability (unsigned long capability)
 
virtual bool has_client_capability (unsigned long client_capability)
 Checks if the client capabilities include the one specified as parameter. More...
 
NETget_net ()
 
Vioget_vio ()
 
void set_vio (Vio *vio)
 
void set_output_pkt_nr (uint pkt_nr)
 
uint get_output_pkt_nr ()
 
Stringget_output_packet ()
 
uint get_packet_length ()
 
ucharget_raw_packet ()
 
virtual void set_read_timeout (ulong read_timeout)
 
virtual void set_write_timeout (ulong write_timeout)
 
- Public Member Functions inherited from Protocol
virtual ~Protocol ()
 
Protocolpop_protocol ()
 Remove the reference to the previous protocol and return it. More...
 
void push_protocol (Protocol *protocol)
 Set reference to "this" as the previous protocol on the protocol provided as argument. More...
 
virtual bool store_null ()=0
 
virtual bool store_tiny (longlong from)=0
 
virtual bool store_short (longlong from)=0
 
virtual bool store_long (longlong from)=0
 
virtual bool store_longlong (longlong from, bool unsigned_flag)=0
 
virtual bool store_decimal (const my_decimal *, uint, uint)=0
 
virtual bool store (const char *from, size_t length, const CHARSET_INFO *fromcs)=0
 
virtual bool store (float from, uint32 decimals, String *buffer)=0
 
virtual bool store (double from, uint32 decimals, String *buffer)=0
 
virtual bool store (MYSQL_TIME *time, uint precision)=0
 
virtual bool store_date (MYSQL_TIME *time)=0
 
virtual bool store_time (MYSQL_TIME *time, uint precision)=0
 
virtual bool store (Proto_field *field)=0
 
bool store (int from)
 
bool store (uint32 from)
 
bool store (longlong from)
 
bool store (ulonglong from)
 
bool store (const char *from, const CHARSET_INFO *fromcs)
 Send \0 end terminated string. More...
 
bool store (String *str)
 
bool store (const LEX_STRING &s, const CHARSET_INFO *cs)
 
virtual bool send_parameters (List< Item_param > *parameters, bool is_sql_prepare)=0
 Sends the OUT-parameters to the client. More...
 

Public Attributes

bool bad_packet
 

Protected Member Functions

bool net_store_data (const uchar *from, size_t length)
 
virtual bool net_store_data (const uchar *from, size_t length, const CHARSET_INFO *fromcs, const CHARSET_INFO *tocs)
 net_store_data() - extended version with character set conversion. More...
 
bool store_string_aux (const char *from, size_t length, const CHARSET_INFO *fromcs, const CHARSET_INFO *tocs)
 Auxilary function to convert string to the given character set and store in network buffer. More...
 
virtual bool send_ok (uint server_status, uint statement_warn_count, ulonglong affected_rows, ulonglong last_insert_id, const char *message)
 A default implementation of "OK" packet response to the client. More...
 
virtual bool send_eof (uint server_status, uint statement_warn_count)
 A default implementation of "EOF" packet response to the client. More...
 
virtual bool send_error (uint sql_errno, const char *err_msg, const char *sql_state)
 A default implementation of "ERROR" packet response to the client. More...
 
virtual bool store_ps_status (ulong stmt_id, uint column_count, uint param_count, ulong cond_count)
 Sends prepared statement's id and metadata to the client after prepare. More...
 

Protected Attributes

MYSQL_THD m_thd
 
Stringpacket
 
Stringconvert
 
uint field_pos
 
bool send_metadata
 
enum enum_field_typesfield_types
 
uint count
 
uint field_count
 
uint sending_flags
 
ulong input_packet_length
 
ucharinput_raw_packet
 
CHARSET_INFOresult_cs
 

Private Member Functions

virtual bool parse_packet (union COM_DATA *data, enum_server_command cmd)
 

Private Attributes

ulong m_client_capabilities
 

Additional Inherited Members

- Public Types inherited from Protocol
enum  enum_protocol_type {
  PROTOCOL_TEXT = 0, PROTOCOL_BINARY = 1, PROTOCOL_LOCAL = 2, PROTOCOL_ERROR = 3,
  PROTOCOL_PLUGIN = 4
}
 Enum used by type() to specify the protocol type. More...
 
enum  { SEND_NUM_ROWS = 1, SEND_DEFAULTS = 2, SEND_EOF = 4 }
 Flags available to alter the way the messages are sent to the client. More...
 
using Type = BaseProtocol::Type
 
- Static Public Member Functions inherited from Protocol
static Type get_default ()
 
static Type get_by_name (const std::string &name)
 Returns type of the protocol by its name. More...
 
static BaseProtocolcreate (Type type, routing::RoutingSockOpsInterface *routing_sock_ops)
 Factory method creating protocol object for handling the routing code that is protocol-specific. More...
 
static uint16_t get_default_port (Type type)
 Returns default port for the selected protocol. More...
 

Constructor & Destructor Documentation

◆ Protocol_classic() [1/2]

Protocol_classic::Protocol_classic ( )
inline

◆ Protocol_classic() [2/2]

Protocol_classic::Protocol_classic ( THD thd)
inline

◆ ~Protocol_classic()

virtual Protocol_classic::~Protocol_classic ( )
inlinevirtual

Member Function Documentation

◆ abort_row()

virtual void Protocol_classic::abort_row ( )
inlinevirtual

Implements Protocol.

◆ add_client_capability()

void Protocol_classic::add_client_capability ( ulong  client_capability)
inline

◆ claim_memory_ownership()

void Protocol_classic::claim_memory_ownership ( )

◆ connection_alive()

bool Protocol_classic::connection_alive ( )
virtual

Checks if the protocol's connection with the client is still alive.

It should always return true unless the protocol closed the connection.

Returns
true if the connection is still alive false otherwise

Implements Protocol.

◆ connection_type()

virtual enum enum_vio_type Protocol_classic::connection_type ( )
inlinevirtual

Returns the type of the connection.

Returns
enum enum_vio_type

Implements Protocol.

◆ create_command()

bool Protocol_classic::create_command ( COM_DATA com_data,
enum_server_command  cmd,
uchar pkt,
size_t  length 
)
virtual

Parses the passed parameters and creates a command.

Parameters
com_dataout parameter
cmdin parameter
pktpacket to be parsed
lengthsize of the packet
Returns
Return values
falseok
trueerror

◆ end_net()

void Protocol_classic::end_net ( )

◆ end_partial_result_set()

void Protocol_classic::end_partial_result_set ( )
virtual

Finish the result set with EOF packet, as is expected by the client, if there is an error evaluating the next row and a continue handler for the error.

Implements Protocol.

◆ end_result_metadata()

bool Protocol_classic::end_result_metadata ( )
virtual

Signals the client that the metadata sending is done.

Clears the server after sending the metadata.

Returns
Return values
falseOk
trueAn error occurred

Implements Protocol.

◆ end_row()

bool Protocol_classic::end_row ( )
virtual

Implements Protocol.

◆ flush()

bool Protocol_classic::flush ( )
virtual

Used for the classic protocol.

Makes the protocol send the messages/data to the client.

Returns
Return values
falseThe flush was successful.
trueAn error occurred.

Implements Protocol.

◆ get_client_capabilities()

virtual ulong Protocol_classic::get_client_capabilities ( )
inlinevirtual

Returns the client capabilities stored on the protocol.

The available capabilites are defined in mysql_com.h

Implements Protocol.

◆ get_command()

int Protocol_classic::get_command ( COM_DATA com_data,
enum_server_command cmd 
)
virtual

Reads the command from the protocol and creates a command.

Parameters
com_dataout parameter
cmdout parameter
Returns
-1 fatal protcol error 0 ok 1 non-fatal protocol or parsing error

Implements Protocol.

◆ get_compression()

bool Protocol_classic::get_compression ( )
virtual

Returns if the protocol is compressed or not.

Returns
Return values
falseNot compressed
trueCompressed

Implements Protocol.

◆ get_error()

uchar Protocol_classic::get_error ( )

◆ get_net()

NET * Protocol_classic::get_net ( )

◆ get_output_packet()

String * Protocol_classic::get_output_packet ( )

◆ get_output_pkt_nr()

uint Protocol_classic::get_output_pkt_nr ( )

◆ get_packet_length()

uint Protocol_classic::get_packet_length ( )
inline

◆ get_raw_packet()

uchar* Protocol_classic::get_raw_packet ( )
inline

◆ get_rw_status()

uint Protocol_classic::get_rw_status ( )
virtual

Returns the read/writing status.

Returns
Return values
1Read
2Write
0Other(Idle, Killed)

Implements Protocol.

◆ get_socket()

my_socket Protocol_classic::get_socket ( )
virtual
Returns
: the file descriptor of the socket.

◆ get_vio()

Vio * Protocol_classic::get_vio ( )

◆ has_client_capability()

virtual bool Protocol_classic::has_client_capability ( unsigned long  client_capability)
inlinevirtual

Checks if the client capabilities include the one specified as parameter.

Returns
true if it includes the specified capability false otherwise

Implements Protocol.

◆ init()

void Protocol_classic::init ( THD thd_arg)

◆ init_net()

bool Protocol_classic::init_net ( Vio vio)

◆ net_store_data() [1/2]

bool Protocol_classic::net_store_data ( const uchar from,
size_t  length 
)
protected

◆ net_store_data() [2/2]

bool Protocol_classic::net_store_data ( const uchar from,
size_t  length,
const CHARSET_INFO from_cs,
const CHARSET_INFO to_cs 
)
protectedvirtual

net_store_data() - extended version with character set conversion.

It is optimized for short strings whose length after conversion is garanteed to be less than 251, which accupies exactly one byte to store length. It allows not to use the "convert" member as a temporary buffer, conversion is done directly to the "packet" member. The limit 251 is good enough to optimize send_result_set_metadata() because column, table, database names fit into this limit.

◆ parse_packet()

bool Protocol_classic::parse_packet ( union COM_DATA data,
enum_server_command  cmd 
)
privatevirtual

◆ read_packet()

int Protocol_classic::read_packet ( )
virtual

Read packet from client.

Returns
-1 fatal error 0 ok 1 non-fatal error

Implements Protocol.

◆ remove_client_capability()

void Protocol_classic::remove_client_capability ( unsigned long  capability)
inline

◆ send_eof()

bool Protocol_classic::send_eof ( uint  server_status,
uint  statement_warn_count 
)
protectedvirtual

A default implementation of "EOF" packet response to the client.

Binary and text protocol do not differ in their EOF packet format.

Implements Protocol.

◆ send_error()

bool Protocol_classic::send_error ( uint  sql_errno,
const char *  err_msg,
const char *  sql_state 
)
protectedvirtual

A default implementation of "ERROR" packet response to the client.

Binary and text protocol do not differ in ERROR packet format.

Implements Protocol.

◆ send_field_metadata()

bool Protocol_classic::send_field_metadata ( Send_field field,
const CHARSET_INFO item_charset 
)
virtual

Sends a single column metadata.

Parameters
fieldField description
item_charsetCharacter set to use
Return values
falsesuccess
trueerror

See Column Definition for the format

Implements Protocol.

◆ send_ok()

bool Protocol_classic::send_ok ( uint  server_status,
uint  statement_warn_count,
ulonglong  affected_rows,
ulonglong  last_insert_id,
const char *  message 
)
protectedvirtual

A default implementation of "OK" packet response to the client.

Currently this implementation is re-used by both network-oriented protocols – the binary and text one. They do not differ in their OK packet format, which allows for a significant simplification on client side.

Implements Protocol.

◆ set_client_capabilities()

void Protocol_classic::set_client_capabilities ( ulong  client_capabilities)
inline

◆ set_max_packet_size()

void Protocol_classic::set_max_packet_size ( ulong  max_packet_size)

◆ set_output_pkt_nr()

void Protocol_classic::set_output_pkt_nr ( uint  pkt_nr)

◆ set_read_timeout()

void Protocol_classic::set_read_timeout ( ulong  read_timeout)
virtual

◆ set_vio()

void Protocol_classic::set_vio ( Vio vio)

◆ set_write_timeout()

void Protocol_classic::set_write_timeout ( ulong  write_timeout)
virtual

◆ shutdown()

int Protocol_classic::shutdown ( bool  server_shutdown = false)
virtual

Thread is being shut down, disconnect and free resources.

Parameters
server_shutdownIf false then this is normal thread shutdown. If true then the server is shutting down.

Implements Protocol.

◆ start_result_metadata()

bool Protocol_classic::start_result_metadata ( uint  num_cols,
uint  flags,
const CHARSET_INFO resultcs 
)
virtual

Prepares the server for metadata sending.

Notifies the client that the metadata sending will start.

Parameters
num_colsNumber of columns that will be sent
flagsFlags to alter the metadata sending Can be any of the following: SEND_NUM_ROWS, SEND_DEFAULTS, SEND_EOF
resultcsCharset to convert to
Returns
Return values
falseOk
trueAn error occurred

Implements Protocol.

Reimplemented in Protocol_binary.

◆ start_row()

virtual void Protocol_classic::start_row ( )
pure virtual

Result set sending functions.

Server uses following schema to send result: ... sending metadata ... | start_result_metadata(...) | start_row() | send_field_metadata(...) | end_row() ... same for each field sent ... | end_result_metadata(...) | ... sending result ... | start_row(...) | store_xxx(...) ... store_xxx(..) is called for each field ... | end_row(...) ... same for each row, until all rows are sent ... | send_ok/eof/error(...) However, a protocol implementation might use different schema. For example, Protocol_callback ignores start/end_row when metadata is being sent.

Implements Protocol.

Implemented in Protocol_binary, and Protocol_text.

◆ store_ps_status()

bool Protocol_classic::store_ps_status ( ulong  stmt_id,
uint  column_count,
uint  param_count,
ulong  cond_count 
)
protectedvirtual

Sends prepared statement's id and metadata to the client after prepare.

Parameters
stmt_idStatement id.
column_countNumber of columns.
param_countNumber of parameters.
cond_countNumber of conditions raised by the current statement.
Returns
Error status.
Return values
falseThe send was successful.
trueAn error occurred.

Implements Protocol.

◆ store_string_aux()

bool Protocol_classic::store_string_aux ( const char *  from,
size_t  length,
const CHARSET_INFO fromcs,
const CHARSET_INFO tocs 
)
protected

Auxilary function to convert string to the given character set and store in network buffer.

◆ type()

virtual enum enum_protocol_type Protocol_classic::type ( )
pure virtual

Implements Protocol.

Implemented in Protocol_binary, and Protocol_text.

◆ wipe_net()

void Protocol_classic::wipe_net ( )

◆ write()

bool Protocol_classic::write ( const uchar ptr,
size_t  len 
)

Member Data Documentation

◆ bad_packet

bool Protocol_classic::bad_packet

◆ convert

String* Protocol_classic::convert
protected

◆ count

uint Protocol_classic::count
protected

◆ field_count

uint Protocol_classic::field_count
protected

◆ field_pos

uint Protocol_classic::field_pos
protected

◆ field_types

enum enum_field_types* Protocol_classic::field_types
protected

◆ input_packet_length

ulong Protocol_classic::input_packet_length
protected

◆ input_raw_packet

uchar* Protocol_classic::input_raw_packet
protected

◆ m_client_capabilities

ulong Protocol_classic::m_client_capabilities
private

◆ m_thd

MYSQL_THD Protocol_classic::m_thd
protected

◆ packet

String* Protocol_classic::packet
protected

◆ result_cs

CHARSET_INFO* Protocol_classic::result_cs
protected

◆ send_metadata

bool Protocol_classic::send_metadata
protected

◆ sending_flags

uint Protocol_classic::sending_flags
protected

The documentation for this class was generated from the following files: