1
- /* Copyright (c) 2019 , Oracle and/or its affiliates. All rights reserved.
1
+ /* Copyright (c) 2020 , Oracle and/or its affiliates. All rights reserved.
2
2
3
3
This program is free software; you can redistribute it and/or modify
4
4
it under the terms of the GNU General Public License, version 2.0,
23
23
#ifndef MYSQL_ASYNC_INCLUDED
24
24
#define MYSQL_ASYNC_INCLUDED
25
25
26
- #define MYSQL_ASYNC_INCLUDED
27
-
28
26
#include <mysql.h>
29
27
30
- /*
31
- NOTE:this file should not be included as part of packaging.
28
+ /**
29
+ @file mysql_async.h
30
+
31
+ Declarations for asynchronous client communication.
32
+
33
+ @note this file should not be included as part of packaging.
32
34
*/
33
- /* Async MySQL extension fields here. */
34
35
35
- /*
36
+ /**
36
37
This enum is to represent different asynchronous operations like reading the
37
38
network, writing to network, idle state, or complete state.
38
39
*/
39
40
enum net_async_operation {
40
- NET_ASYNC_OP_IDLE = 0 , /* default state */
41
- NET_ASYNC_OP_READING , /* used by my_net_read calls */
42
- NET_ASYNC_OP_WRITING , /* used by my_net_write calls */
43
- NET_ASYNC_OP_COMPLETE /* network read or write is complete */
41
+ NET_ASYNC_OP_IDLE = 0 , /**< default state */
42
+ NET_ASYNC_OP_READING , /**< used by my_net_read calls */
43
+ NET_ASYNC_OP_WRITING , /**< used by my_net_write calls */
44
+ NET_ASYNC_OP_COMPLETE /**< network read or write is complete */
44
45
};
45
46
46
- /* Reading a packet is a multi-step process, so we have a state machine. */
47
+ /** Reading a packet is a multi-step process, so we have a state machine. */
47
48
enum net_async_read_packet_state {
48
- NET_ASYNC_PACKET_READ_IDLE = 0 , /* default packet read state */
49
- NET_ASYNC_PACKET_READ_HEADER , /* read packet header */
50
- NET_ASYNC_PACKET_READ_BODY , /* read packet contents */
51
- NET_ASYNC_PACKET_READ_COMPLETE /* state to define if packet is
52
- completely read */
49
+ NET_ASYNC_PACKET_READ_IDLE = 0 , /**< default packet read state */
50
+ NET_ASYNC_PACKET_READ_HEADER , /**< read packet header */
51
+ NET_ASYNC_PACKET_READ_BODY , /**< read packet contents */
52
+ NET_ASYNC_PACKET_READ_COMPLETE /**< state to define if packet is
53
+ completely read */
53
54
};
54
55
55
- /* Different states when reading a query result. */
56
+ /** Different states when reading a query result. */
56
57
enum net_read_query_result_status {
57
- NET_ASYNC_READ_QUERY_RESULT_IDLE = 0 , /* default state */
58
- NET_ASYNC_READ_QUERY_RESULT_FIELD_COUNT , /* read Ok or read field
59
- count sent as part of
60
- COM_QUERY */
61
- NET_ASYNC_READ_QUERY_RESULT_FIELD_INFO /* read result of above
62
- COM_* command */
58
+ NET_ASYNC_READ_QUERY_RESULT_IDLE = 0 , /**< default state */
59
+ NET_ASYNC_READ_QUERY_RESULT_FIELD_COUNT , /**< read Ok or read field
60
+ count sent as part of
61
+ COM_QUERY */
62
+ NET_ASYNC_READ_QUERY_RESULT_FIELD_INFO /**< read result of above
63
+ COM_* command */
63
64
};
64
65
65
- /* Sending a command involves the write as well as reading the status. */
66
+ /** Sending a command involves the write as well as reading the status. */
66
67
enum net_send_command_status {
67
- NET_ASYNC_SEND_COMMAND_IDLE = 0 , /* default send command state */
68
- NET_ASYNC_SEND_COMMAND_WRITE_COMMAND , /* send COM_* command */
69
- NET_ASYNC_SEND_COMMAND_READ_STATUS /* read result of above COM_*
70
- command */
68
+ NET_ASYNC_SEND_COMMAND_IDLE = 0 , /**< default send command state */
69
+ NET_ASYNC_SEND_COMMAND_WRITE_COMMAND , /**< send COM_* command */
70
+ NET_ASYNC_SEND_COMMAND_READ_STATUS /**< read result of above COM_*
71
+ command */
71
72
};
72
73
73
- /*
74
+ /**
74
75
Async operations are broadly classified into 3 phases:
75
76
Connection phase, phase of sending data to server (which is writing phase)
76
77
and reading data from server (which is reading phase). Below enum describes
@@ -82,49 +83,93 @@ enum net_async_block_state {
82
83
NET_NONBLOCKING_WRITE
83
84
};
84
85
86
+ /**
87
+ Represents the packet to be sent on wire asynchronously.
88
+ */
85
89
struct io_vec {
86
- void * iov_base ; /* Starting address */
87
- size_t iov_len ; /* Number of bytes to transfer */
90
+ void * iov_base ; /**< Starting address */
91
+ size_t iov_len ; /**< Number of bytes to transfer */
88
92
};
89
93
90
94
typedef struct NET_ASYNC {
91
- /* The position in buff we continue reads from when data is next available */
95
+ /**
96
+ The position in buff we continue reads from when data is next
97
+ available
98
+ */
92
99
unsigned char * cur_pos ;
93
100
/** Blocking state */
94
101
enum net_async_block_state async_blocking_state ;
95
102
/** Our current operation */
96
103
enum net_async_operation async_operation ;
97
104
/** How many bytes we want to read */
98
105
size_t async_bytes_wanted ;
99
- /*
106
+ /**
100
107
Simple state to know if we're reading the first row, and
101
108
command/query statuses.
102
109
*/
103
110
bool read_rows_is_first_read ;
104
111
enum net_send_command_status async_send_command_status ;
105
112
enum net_read_query_result_status async_read_query_result_status ;
106
113
107
- /* State when waiting on an async read */
114
+ /** State when waiting on an async read */
108
115
enum net_async_read_packet_state async_packet_read_state ;
109
- /* Size of the packet we're currently reading */
116
+ /** Size of the packet we're currently reading */
110
117
size_t async_packet_length ;
111
118
112
- /*
119
+ /**
113
120
Headers and vector for our async writes; see net_serv.c for
114
121
detailed description.
115
122
*/
116
123
unsigned char * async_write_headers ;
117
124
struct io_vec * async_write_vector ;
118
125
size_t async_write_vector_size ;
119
126
size_t async_write_vector_current ;
120
- unsigned char
121
- inline_async_write_header [NET_HEADER_SIZE + COMP_HEADER_SIZE + 1 + 1 ];
127
+
128
+ /**
129
+ If the packet length is less than MAX_PACKET_LENGTH then use a static array
130
+ to hold the meta packet header. The array either holds the usual packet
131
+ header or a compressed meta packet header as following. The compressed
132
+ meta packet header is followwed by usual compresses packet heder that is
133
+ 7 bytes in length.
134
+
135
+
136
+ Packet
137
+
138
+ Header
139
+ ~~~~~~~~~~~~~~~~~~~
140
+ B1 B2 B3 : Packet length
141
+ B4 : Packet number
142
+ ~~~~~~~~~~~~~~~~~~~
143
+
144
+ Payload
145
+ ~~~~~~~~~~~~~~~~~~~
146
+ B5 : COM_COMMAND
147
+ ~~~~~~~~~~~~~~~~~~~
148
+
149
+ Compressed Packet
150
+
151
+ Header
152
+ ~~~~~~~~~~~~~~~~~~~
153
+ B1 B2 B3 : Compress packet length
154
+ B4 : Compress Packet Nunmber
155
+ 00 00 00 : Indicates following payload is uncompressed
156
+ ~~~~~~~~~~~~~~~~~~~
157
+
158
+ Payload
159
+ ~~~~~~~~~~~~~~~~~~~
160
+ B8 B9 B10 : Packet size
161
+ B11 : Packet number
162
+ B12 : COM_COMMAND
163
+ ~~~~~~~~~~~~~~~~~~~
164
+ */
165
+ unsigned char inline_async_write_header [NET_HEADER_SIZE + COMP_HEADER_SIZE +
166
+ NET_HEADER_SIZE + 1 ];
122
167
struct io_vec inline_async_write_vector [3 ];
123
168
124
- /* State for reading responses that are larger than MAX_PACKET_LENGTH */
125
- unsigned long async_multipacket_read_saved_whereb ;
126
- unsigned long async_multipacket_read_total_len ;
127
- bool async_multipacket_read_started ;
169
+ /** Keep track of compressed buffers */
170
+ unsigned char * * compressed_write_buffers ;
171
+ /** Size of the compressed buffer */
172
+ size_t compressed_buffers_size ;
128
173
} NET_ASYNC ;
129
174
130
175
struct NET_EXTENSION {
@@ -141,7 +186,7 @@ void net_extension_free(NET *);
141
186
#define NET_ASYNC_DATA (M ) \
142
187
((NET_EXTENSION_PTR(M)) ? (NET_EXTENSION_PTR(M)->net_async_context) : NULL)
143
188
144
- /*
189
+ /**
145
190
Asynchronous operations are broadly classified into 2 categories.
146
191
1. Connection
147
192
2. Query execution
@@ -153,7 +198,7 @@ enum mysql_async_operation_status {
153
198
ASYNC_OP_QUERY
154
199
};
155
200
156
- /*
201
+ /**
157
202
Query execution in an asynchronous fashion is broadly divided into 3 states
158
203
which is described in below enum
159
204
*/
@@ -164,24 +209,24 @@ enum mysql_async_query_state_enum {
164
209
};
165
210
166
211
typedef struct MYSQL_ASYNC {
167
- /* Buffer storing the rows result for cli_read_rows_nonblocking */
212
+ /** Buffer storing the rows result for cli_read_rows_nonblocking */
168
213
MYSQL_DATA * rows_result_buffer ;
169
- /* a pointer to keep track of the previous row of the current result row */
214
+ /** a pointer to keep track of the previous row of the current result row */
170
215
MYSQL_ROWS * * prev_row_ptr ;
171
- /* Context needed to track the state of a connection being established */
216
+ /** Context needed to track the state of a connection being established */
172
217
struct mysql_async_connect * connect_context ;
173
- /* Status of the current async op */
218
+ /** Status of the current async op */
174
219
enum mysql_async_operation_status async_op_status ;
175
- /* Size of the current running async query */
220
+ /** Size of the current running async query */
176
221
size_t async_query_length ;
177
- /* If a query is running, this is its state */
222
+ /** If a query is running, this is its state */
178
223
enum mysql_async_query_state_enum async_query_state ;
179
- /* context needed to support metadata read operation */
224
+ /** context needed to support metadata read operation */
180
225
unsigned long * async_read_metadata_field_len ;
181
226
MYSQL_FIELD * async_read_metadata_fields ;
182
227
MYSQL_ROWS async_read_metadata_data ;
183
228
unsigned int async_read_metadata_cur_field ;
184
- /* a pointer to keep track of the result sets */
229
+ /** a pointer to keep track of the result sets */
185
230
struct MYSQL_RES * async_store_result_result ;
186
231
} MYSQL_ASYNC ;
187
232
@@ -192,8 +237,7 @@ enum net_async_status net_write_command_nonblocking(
192
237
NET * net , unsigned char command , const unsigned char * prefix ,
193
238
size_t prefix_len , const unsigned char * packet , size_t packet_len ,
194
239
bool * res );
195
- enum net_async_status my_net_read_nonblocking (NET * net , unsigned long * len_ptr ,
196
- unsigned long * complen_ptr );
240
+ enum net_async_status my_net_read_nonblocking (NET * net , unsigned long * len_ptr );
197
241
198
242
int mysql_get_socket_descriptor (MYSQL * mysql );
199
243
0 commit comments