MySQL  8.0.16
Source Code Documentation
Protocol Class Referencefinalabstract

#include <protocol.h>

Inheritance diagram for Protocol:
Protocol_callback Protocol_classic Protocol_local Protocol_text Protocol_binary

Public Types

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
 

Public Member Functions

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 int read_packet ()=0
 Read packet from client. More...
 
virtual int get_command (COM_DATA *com_data, enum_server_command *cmd)=0
 Reads the command from the protocol and creates a command. More...
 
virtual enum enum_protocol_type type () const =0
 
virtual enum enum_vio_type connection_type () const =0
 
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 ulong get_client_capabilities ()=0
 Returns the client capabilities stored on the protocol. More...
 
virtual bool has_client_capability (unsigned long client_capability)=0
 Checks if the client capabilities include the one specified as parameter. More...
 
virtual bool connection_alive () const =0
 Checks if the protocol's connection with the client is still alive. More...
 
virtual void start_row ()=0
 Result set sending functions. More...
 
virtual bool end_row ()=0
 
virtual void abort_row ()=0
 
virtual void end_partial_result_set ()=0
 
virtual int shutdown (bool server_shutdown=false)=0
 Thread is being shut down, disconnect and free resources. More...
 
virtual uint get_rw_status ()=0
 Returns the read/writing status. More...
 
virtual bool get_compression ()=0
 Returns if the protocol is compressed or not. More...
 
virtual bool start_result_metadata (uint num_cols, uint flags, const CHARSET_INFO *resultcs)=0
 Prepares the server for metadata sending. More...
 
virtual bool send_field_metadata (Send_field *field, const CHARSET_INFO *charset)=0
 Sends field metadata. More...
 
virtual bool end_result_metadata ()=0
 Signals the client that the metadata sending is done. More...
 
virtual bool send_ok (uint server_status, uint statement_warn_count, ulonglong affected_rows, ulonglong last_insert_id, const char *message)=0
 Send ok message to the client. More...
 
virtual bool send_eof (uint server_status, uint statement_warn_count)=0
 Send eof message to the client. More...
 
virtual bool send_error (uint sql_errno, const char *err_msg, const char *sql_state)=0
 Send error message to the client. More...
 
virtual bool flush ()=0
 Used for the classic protocol. More...
 
virtual bool store_ps_status (ulong stmt_id, uint column_count, uint param_count, ulong cond_count)=0
 Sends prepared statement's id and metadata to the client after prepare. More...
 
virtual bool send_parameters (List< Item_param > *parameters, bool is_sql_prepare)=0
 Sends the OUT-parameters to the client. More...
 

Static Public Member Functions

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...
 

Private Attributes

Protocolm_previous_protocol = nullptr
 Pointer to the Protocol below on the stack. More...
 

Static Private Attributes

static constexpr uint16_t kClassicProtocolDefaultPort {3306}
 default server ports for supported protocols More...
 
static constexpr uint16_t kXProtocolDefaultPort {33060}
 

Member Typedef Documentation

◆ Type

Member Enumeration Documentation

◆ anonymous enum

anonymous enum

Flags available to alter the way the messages are sent to the client.

Enumerator
SEND_NUM_ROWS 
SEND_DEFAULTS 
SEND_EOF 

◆ enum_protocol_type

Enum used by type() to specify the protocol type.

Enumerator
PROTOCOL_TEXT 
PROTOCOL_BINARY 
PROTOCOL_LOCAL 
PROTOCOL_ERROR 
PROTOCOL_PLUGIN 

Constructor & Destructor Documentation

◆ ~Protocol()

virtual Protocol::~Protocol ( )
inlinevirtual

Member Function Documentation

◆ abort_row()

virtual void Protocol::abort_row ( )
pure virtual

◆ connection_alive()

virtual bool Protocol::connection_alive ( ) const
pure 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

Implemented in Protocol_callback, Protocol_local, and Protocol_classic.

◆ connection_type()

virtual enum enum_vio_type Protocol::connection_type ( ) const
pure virtual

◆ create()

static BaseProtocol* Protocol::create ( Type  type,
routing::RoutingSockOpsInterface routing_sock_ops 
)
inlinestatic

Factory method creating protocol object for handling the routing code that is protocol-specific.

Parameters
typetype of the protocol for which the handler should be created
routing_sock_opssocket operations
Returns
pointer to the created object

◆ end_partial_result_set()

virtual void Protocol::end_partial_result_set ( )
pure virtual

◆ end_result_metadata()

virtual bool Protocol::end_result_metadata ( )
pure virtual

Signals the client that the metadata sending is done.

Clears the server after sending the metadata.

Returns
Return values
falseOk
trueAn error occurred

Implemented in Protocol_callback, Protocol_local, and Protocol_classic.

◆ end_row()

virtual bool Protocol::end_row ( )
pure virtual

◆ flush()

virtual bool Protocol::flush ( )
pure 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.

Implemented in Protocol_callback, Protocol_local, and Protocol_classic.

◆ get_by_name()

static Type Protocol::get_by_name ( const std::string &  name)
inlinestatic

Returns type of the protocol by its name.

◆ get_client_capabilities()

virtual ulong Protocol::get_client_capabilities ( )
pure virtual

Returns the client capabilities stored on the protocol.

The available capabilites are defined in mysql_com.h

Implemented in Protocol_callback, Protocol_local, and Protocol_classic.

◆ get_command()

virtual int Protocol::get_command ( COM_DATA com_data,
enum_server_command cmd 
)
pure 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

Implemented in Protocol_local, Protocol_classic, and Protocol_callback.

◆ get_compression()

virtual bool Protocol::get_compression ( )
pure virtual

Returns if the protocol is compressed or not.

Returns
Return values
falseNot compressed
trueCompressed

Implemented in Protocol_callback, Protocol_local, and Protocol_classic.

◆ get_default()

static Type Protocol::get_default ( )
inlinestatic

◆ get_default_port()

static uint16_t Protocol::get_default_port ( Type  type)
inlinestatic

Returns default port for the selected protocol.

◆ get_rw_status()

virtual uint Protocol::get_rw_status ( )
pure virtual

Returns the read/writing status.

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

Implemented in Protocol_callback, Protocol_local, and Protocol_classic.

◆ has_client_capability()

virtual bool Protocol::has_client_capability ( unsigned long  client_capability)
pure virtual

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

Returns
true if it includes the specified capability false otherwise

Implemented in Protocol_callback, Protocol_local, and Protocol_classic.

◆ pop_protocol()

Protocol* Protocol::pop_protocol ( )
inline

Remove the reference to the previous protocol and return it.

Returns
The new top of the Protocol stack.

◆ push_protocol()

void Protocol::push_protocol ( Protocol protocol)
inline

Set reference to "this" as the previous protocol on the protocol provided as argument.

Parameters
protocolProtocol to become the top of Protocol stack.

◆ read_packet()

virtual int Protocol::read_packet ( )
pure virtual

Read packet from client.

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

Implemented in Protocol_local, Protocol_classic, and Protocol_callback.

◆ send_eof()

virtual bool Protocol::send_eof ( uint  server_status,
uint  statement_warn_count 
)
pure virtual

Send eof message to the client.

Parameters
server_statusThe server status
statement_warn_countTotal number of warnings
Returns
Return values
falseThe message was successfully sent
trueAn error occurred and the messages wasn't sent properly

Implemented in Protocol_callback, Protocol_local, and Protocol_classic.

◆ send_error()

virtual bool Protocol::send_error ( uint  sql_errno,
const char *  err_msg,
const char *  sql_state 
)
pure virtual

Send error message to the client.

Parameters
sql_errnoThe error code to send
err_msgA pointer to the error message
sql_stateSQL state
Returns
Return values
falseThe message was successfully sent
trueAn error occurred and the messages wasn't sent properly

Implemented in Protocol_callback, Protocol_local, and Protocol_classic.

◆ send_field_metadata()

virtual bool Protocol::send_field_metadata ( Send_field field,
const CHARSET_INFO charset 
)
pure virtual

Sends field metadata.

Parameters
fieldField metadata to be send to the client
charsetField's charset: in case it is different than the one used by the connection it will be used to convert the value to the connection's charset
Returns
Return values
falseThe metadata was successfully sent
trueAn error occurred

Implemented in Protocol_callback, Protocol_local, and Protocol_classic.

◆ send_ok()

virtual bool Protocol::send_ok ( uint  server_status,
uint  statement_warn_count,
ulonglong  affected_rows,
ulonglong  last_insert_id,
const char *  message 
)
pure virtual

Send ok message to the client.

Parameters
server_statusThe server status
statement_warn_countTotal number of warnings
affected_rowsNumber of rows changed by statement
last_insert_idLast insert id (Auto_increment id for first row if used)
messageMessage to send to the client
Returns
Return values
falseThe message was successfully sent
trueAn error occurred and the messages wasn't sent properly

Implemented in Protocol_callback, Protocol_local, and Protocol_classic.

◆ send_parameters()

virtual bool Protocol::send_parameters ( List< Item_param > *  parameters,
bool  is_sql_prepare 
)
pure virtual

Sends the OUT-parameters to the client.

Parameters
parametersList of PS/SP parameters (both input and output).
is_sql_prepareUsed for the legacy protocol. If we're dealing with sql prepare then text protocol wil be used.
Returns
Error status.
Return values
falseSuccess.
trueError.

Implemented in Protocol_callback, Protocol_binary, Protocol_local, and Protocol_text.

◆ shutdown()

virtual int Protocol::shutdown ( bool  server_shutdown = false)
pure 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.

Implemented in Protocol_callback, Protocol_local, and Protocol_classic.

◆ start_result_metadata()

virtual bool Protocol::start_result_metadata ( uint  num_cols,
uint  flags,
const CHARSET_INFO resultcs 
)
pure 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

Implemented in Protocol_callback, Protocol_binary, Protocol_local, and Protocol_classic.

◆ start_row()

virtual void Protocol::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.

Implemented in Protocol_callback, Protocol_binary, Protocol_text, Protocol_local, and Protocol_classic.

◆ store() [1/12]

virtual bool Protocol::store ( const char *  from,
size_t  length,
const CHARSET_INFO fromcs 
)
pure virtual

◆ store() [2/12]

virtual bool Protocol::store ( float  from,
uint32  decimals,
String buffer 
)
pure virtual

◆ store() [3/12]

virtual bool Protocol::store ( double  from,
uint32  decimals,
String buffer 
)
pure virtual

◆ store() [4/12]

virtual bool Protocol::store ( MYSQL_TIME time,
uint  precision 
)
pure virtual

◆ store() [5/12]

virtual bool Protocol::store ( Proto_field field)
pure virtual

◆ store() [6/12]

bool Protocol::store ( int  from)
inline

◆ store() [7/12]

bool Protocol::store ( uint32  from)
inline

◆ store() [8/12]

bool Protocol::store ( longlong  from)
inline

◆ store() [9/12]

bool Protocol::store ( ulonglong  from)
inline

◆ store() [10/12]

bool Protocol::store ( const char *  from,
const CHARSET_INFO fromcs 
)
inline

Send \0 end terminated string.

Parameters
fromNullS or \0 terminated string.
fromcsCharacter set of the from string.
Note
In most cases one should use store(from, length, cs) instead of this function
Returns
false ok true error

◆ store() [11/12]

bool Protocol::store ( String str)
inline

◆ store() [12/12]

bool Protocol::store ( const LEX_STRING s,
const CHARSET_INFO cs 
)
inline

◆ store_date()

virtual bool Protocol::store_date ( MYSQL_TIME time)
pure virtual

◆ store_decimal()

virtual bool Protocol::store_decimal ( const my_decimal ,
uint  ,
uint   
)
pure virtual

◆ store_long()

virtual bool Protocol::store_long ( longlong  from)
pure virtual

◆ store_longlong()

virtual bool Protocol::store_longlong ( longlong  from,
bool  unsigned_flag 
)
pure virtual

◆ store_null()

virtual bool Protocol::store_null ( )
pure virtual

◆ store_ps_status()

virtual bool Protocol::store_ps_status ( ulong  stmt_id,
uint  column_count,
uint  param_count,
ulong  cond_count 
)
pure virtual

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.

Implemented in Protocol_callback, Protocol_local, and Protocol_classic.

◆ store_short()

virtual bool Protocol::store_short ( longlong  from)
pure virtual

◆ store_time()

virtual bool Protocol::store_time ( MYSQL_TIME time,
uint  precision 
)
pure virtual

◆ store_tiny()

virtual bool Protocol::store_tiny ( longlong  from)
pure virtual

◆ type()

virtual enum enum_protocol_type Protocol::type ( ) const
pure virtual

Member Data Documentation

◆ kClassicProtocolDefaultPort

constexpr uint16_t Protocol::kClassicProtocolDefaultPort {3306}
staticprivate

default server ports for supported protocols

◆ kXProtocolDefaultPort

constexpr uint16_t Protocol::kXProtocolDefaultPort {33060}
staticprivate

◆ m_previous_protocol

Protocol* Protocol::m_previous_protocol = nullptr
private

Pointer to the Protocol below on the stack.


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