176
176
return con->options;
179
void drizzle_con_set_options(drizzle_con_st *con, int options)
179
void drizzle_con_set_options(drizzle_con_st *con,
181
182
con->options= options;
184
void drizzle_con_add_options(drizzle_con_st *con, int options)
185
void drizzle_con_add_options(drizzle_con_st *con,
186
188
con->options|= options;
188
190
/* If asking for the experimental Drizzle protocol, clean the MySQL flag. */
189
191
if (con->options & DRIZZLE_CON_EXPERIMENTAL)
191
192
con->options&= ~DRIZZLE_CON_MYSQL;
195
void drizzle_con_remove_options(drizzle_con_st *con, int options)
195
void drizzle_con_remove_options(drizzle_con_st *con,
197
198
con->options&= ~options;
200
201
const char *drizzle_con_host(const drizzle_con_st *con)
207
203
if (con->socket_type == DRIZZLE_CON_SOCKET_TCP)
209
205
if (con->socket.tcp.host == NULL && !(con->options & DRIZZLE_CON_LISTEN))
211
206
return DRIZZLE_DEFAULT_TCP_HOST;
214
208
return con->socket.tcp.host;
256
248
const char *drizzle_con_user(const drizzle_con_st *con)
263
250
return con->user;
266
253
const char *drizzle_con_password(const drizzle_con_st *con)
273
255
return con->password;
276
void drizzle_con_set_auth(drizzle_con_st *con, const char *user, const char *password)
258
void drizzle_con_set_auth(drizzle_con_st *con, const char *user,
259
const char *password)
283
261
if (user == NULL)
289
265
strncpy(con->user, user, DRIZZLE_MAX_USER_SIZE);
304
const char *drizzle_con_schema(const drizzle_con_st *con)
314
278
const char *drizzle_con_db(const drizzle_con_st *con)
316
return drizzle_con_schema(con);
319
void drizzle_con_set_schema(drizzle_con_st *con, const char *schema)
283
void drizzle_con_set_db(drizzle_con_st *con, const char *db)
332
strncpy(con->schema, schema, DRIZZLE_MAX_DB_SIZE);
333
con->schema[DRIZZLE_MAX_DB_SIZE - 1]= 0;
289
strncpy(con->db, db, DRIZZLE_MAX_DB_SIZE);
290
con->db[DRIZZLE_MAX_DB_SIZE - 1]= 0;
337
void drizzle_con_set_db(drizzle_con_st *con, const char *schema)
339
drizzle_con_set_schema(con, schema);
342
294
void *drizzle_con_context(const drizzle_con_st *con)
349
296
return con->context;
352
299
void drizzle_con_set_context(drizzle_con_st *con, void *context)
359
301
con->context= context;
362
304
void drizzle_con_set_context_free_fn(drizzle_con_st *con,
363
305
drizzle_con_context_free_fn *function)
370
307
con->context_free_fn= function;
373
310
uint8_t drizzle_con_protocol_version(const drizzle_con_st *con)
380
312
return con->protocol_version;
383
315
const char *drizzle_con_server_version(const drizzle_con_st *con)
390
317
return con->server_version;
393
320
uint32_t drizzle_con_server_version_number(const drizzle_con_st *con)
395
if (con == NULL or con->server_version)
400
327
const char *current= con->server_version;
403
uint32_t major= (uint32_t)strtoul(current, &end, 10);
406
uint32_t minor= (uint32_t)strtoul(current, &end, 10);
409
uint32_t version= (uint32_t)strtoul(current, &end, 10);
329
major= (uint32_t)strtoul(current, &end, 10);
331
minor= (uint32_t)strtoul(current, &end, 10);
333
version= (uint32_t)strtoul(current, &end, 10);
411
335
return (major * 10000) + (minor * 100) + version;
414
338
uint32_t drizzle_con_thread_id(const drizzle_con_st *con)
421
340
return con->thread_id;
424
343
const uint8_t *drizzle_con_scramble(const drizzle_con_st *con)
431
345
return con->scramble;
434
348
int drizzle_con_capabilities(const drizzle_con_st *con)
441
350
return con->capabilities;
444
353
drizzle_charset_t drizzle_con_charset(const drizzle_con_st *con)
448
return drizzle_charset_t();
451
355
return con->charset;
454
358
drizzle_con_status_t drizzle_con_status(const drizzle_con_st *con)
458
return drizzle_con_status_t();
461
360
return con->status;
464
363
uint32_t drizzle_con_max_packet_size(const drizzle_con_st *con)
471
365
return con->max_packet_size;
557
439
drizzle_result_st *drizzle_shutdown(drizzle_con_st *con,
558
drizzle_result_st *result, uint32_t,
440
drizzle_result_st *result, uint32_t level,
559
441
drizzle_return_t *ret_ptr)
561
444
return drizzle_con_shutdown(con, result, ret_ptr);
604
484
ret_ptr= &unused;
607
if ((con->options & DRIZZLE_CON_READY) == 0)
487
if (!(con->options & DRIZZLE_CON_READY))
609
489
if (con->options & DRIZZLE_CON_RAW_PACKET)
611
drizzle_set_error(con->drizzle, "drizzle_command_write", "connection not ready");
491
drizzle_set_error(con->drizzle, "drizzle_command_write",
492
"connection not ready");
612
493
*ret_ptr= DRIZZLE_RETURN_NOT_READY;
616
497
*ret_ptr= drizzle_con_connect(con);
617
498
if (*ret_ptr != DRIZZLE_RETURN_OK)
631
for (drizzle_result_st *old_result= con->result_list; old_result != NULL; old_result= old_result->next)
512
for (old_result= con->result_list; old_result != NULL; old_result= old_result->next)
633
514
if (result == old_result)
635
516
drizzle_set_error(con->drizzle, "drizzle_command_write", "result struct already in use");
636
517
*ret_ptr= DRIZZLE_RETURN_INTERNAL_ERROR;
641
con->result= drizzle_result_create_with(con, result);
522
con->result= drizzle_result_create(con, result);
642
523
if (con->result == NULL)
644
525
*ret_ptr= DRIZZLE_RETURN_MEMORY;
704
576
int drizzle_con_backlog(const drizzle_con_st *con)
711
578
return con->backlog;
714
581
void drizzle_con_set_backlog(drizzle_con_st *con, int backlog)
721
583
con->backlog= backlog;
724
void drizzle_con_set_protocol_version(drizzle_con_st *con, uint8_t protocol_version)
586
void drizzle_con_set_protocol_version(drizzle_con_st *con,
587
uint8_t protocol_version)
731
589
con->protocol_version= protocol_version;
734
592
void drizzle_con_set_server_version(drizzle_con_st *con,
735
593
const char *server_version)
742
595
if (server_version == NULL)
744
596
con->server_version[0]= 0;
748
599
strncpy(con->server_version, server_version,
782
621
void drizzle_con_set_capabilities(drizzle_con_st *con,
783
622
int capabilities)
790
624
con->capabilities= capabilities;
793
627
void drizzle_con_set_charset(drizzle_con_st *con, drizzle_charset_t charset)
800
629
con->charset= charset;
803
632
void drizzle_con_set_status(drizzle_con_st *con, drizzle_con_status_t status)
810
634
con->status= status;
813
637
void drizzle_con_set_max_packet_size(drizzle_con_st *con,
814
638
uint32_t max_packet_size)
821
640
con->max_packet_size= max_packet_size;
824
643
void drizzle_con_copy_handshake(drizzle_con_st *con, drizzle_con_st *from)
831
645
drizzle_con_set_auth(con, from->user, NULL);
832
646
drizzle_con_set_scramble(con, from->scramble);
833
drizzle_con_set_db(con, from->schema);
647
drizzle_con_set_db(con, from->db);
834
648
drizzle_con_set_protocol_version(con, from->protocol_version);
835
649
drizzle_con_set_server_version(con, from->server_version);
836
650
drizzle_con_set_thread_id(con, from->thread_id);
921
705
if (con->command_buffer == NULL)
923
con->command_buffer= new (std::nothrow) uint8_t[(*total) + 1];
925
if (con->command_buffer == NULL)
928
*ret_ptr= DRIZZLE_RETURN_MEMORY;
707
con->command_buffer= new uint8_t[(*total) + 1];
933
710
memcpy(con->command_buffer + offset, command_data, size);
1016
786
if (tcp->port != 0)
1018
787
snprintf(port, NI_MAXSERV, "%u", tcp->port);
1020
788
else if (con->options & DRIZZLE_CON_MYSQL)
1022
789
snprintf(port, NI_MAXSERV, "%u", DRIZZLE_DEFAULT_TCP_PORT_MYSQL);
1026
791
snprintf(port, NI_MAXSERV, "%u", DRIZZLE_DEFAULT_TCP_PORT);
1028
792
port[NI_MAXSERV-1]= 0;
1030
794
memset(&ai, 0, sizeof(ai));
1206
962
if (ret != DRIZZLE_RETURN_OK)
1209
if (con->drizzle->options.is_non_blocking)
965
if (con->drizzle->options & DRIZZLE_NON_BLOCKING)
1211
966
return DRIZZLE_RETURN_IO_WAIT;
1214
968
ret= drizzle_con_wait(con->drizzle);
1215
969
if (ret != DRIZZLE_RETURN_OK)
1222
974
drizzle_return_t drizzle_state_read(drizzle_con_st *con)
1226
return DRIZZLE_RETURN_INVALID_ARGUMENT;
976
drizzle_return_t ret;
1229
978
drizzle_log_debug(con->drizzle, "drizzle_state_read");
1239
988
if ((con->revents & POLLIN) == 0 &&
1240
(con->drizzle->options.is_non_blocking))
989
(con->drizzle->options & DRIZZLE_NON_BLOCKING))
1242
991
/* non-blocking mode: return IO_WAIT instead of attempting to read. This
1243
992
* avoids reading immediately after writing a command, which typically
1244
993
* returns EAGAIN. This improves performance. */
1245
drizzle_return_t ret= drizzle_con_set_events(con, POLLIN);
994
ret= drizzle_con_set_events(con, POLLIN);
1246
995
if (ret != DRIZZLE_RETURN_OK)
1250
997
return DRIZZLE_RETURN_IO_WAIT;
1309
1056
/* clear the read ready flag */
1310
1057
con->revents&= ~POLLIN;
1311
drizzle_return_t ret= drizzle_con_set_events(con, POLLIN);
1058
ret= drizzle_con_set_events(con, POLLIN);
1312
1059
if (ret != DRIZZLE_RETURN_OK)
1317
if (con->drizzle->options.is_non_blocking)
1062
if (con->drizzle->options & DRIZZLE_NON_BLOCKING)
1319
1063
return DRIZZLE_RETURN_IO_WAIT;
1322
1065
ret= drizzle_con_wait(con->drizzle);
1323
1066
if (ret != DRIZZLE_RETURN_OK)
1423
1161
if (errno == EAGAIN)
1425
drizzle_return_t ret= drizzle_con_set_events(con, POLLOUT);
1163
ret= drizzle_con_set_events(con, POLLOUT);
1426
1164
if (ret != DRIZZLE_RETURN_OK)
1431
if (con->drizzle->options.is_non_blocking)
1167
if (con->drizzle->options & DRIZZLE_NON_BLOCKING)
1433
1168
return DRIZZLE_RETURN_IO_WAIT;
1436
1170
ret= drizzle_con_wait(con->drizzle);
1437
1171
if (ret != DRIZZLE_RETURN_OK)
1444
1176
else if (errno == EINTR)
1448
1178
else if (errno == EPIPE || errno == ECONNRESET)
1450
1180
drizzle_set_error(con->drizzle, "drizzle_state_write",