45
44
static uint32_t buffer_length;
46
45
static char* bind_address;
48
const char* ListenOldLibdrizzle::getHost(void) const
47
const char* ListenDrizzleProtocol::getHost(void) const
50
49
return bind_address;
53
in_port_t ListenOldLibdrizzle::getPort(void) const
52
in_port_t ListenDrizzleProtocol::getPort(void) const
55
return (in_port_t) drizzled_tcp_port;
54
struct servent *serv_ptr;
59
port= DRIZZLE_TCP_PORT;
61
if (DRIZZLE_TCP_PORT_DEFAULT == 0)
63
if ((serv_ptr= getservbyname("drizzle", "tcp")))
64
port= ntohs((u_short) serv_ptr->s_port);
67
if ((env = getenv("DRIZZLE_TCP_PORT")))
68
port= (uint32_t) atoi(env);
73
return (in_port_t) port;
58
plugin::Client *ListenOldLibdrizzle::getClient(int fd)
76
plugin::Client *ListenDrizzleProtocol::getClient(int fd)
61
79
new_fd= acceptTcp(fd);
65
return new (nothrow) ClientOldLibdrizzle(new_fd);
83
return new (nothrow) ClientDrizzleProtocol(new_fd, using_mysql41_protocol);
68
ClientOldLibdrizzle::ClientOldLibdrizzle(int fd)
86
ClientDrizzleProtocol::ClientDrizzleProtocol(int fd, bool using_mysql41_protocol_arg):
87
using_mysql41_protocol(using_mysql41_protocol_arg)
80
99
net.retry_count=retry_count;
83
ClientOldLibdrizzle::~ClientOldLibdrizzle()
102
ClientDrizzleProtocol::~ClientDrizzleProtocol()
86
105
drizzleclient_vio_close(net.vio);
89
int ClientOldLibdrizzle::getFileDescriptor(void)
108
int ClientDrizzleProtocol::getFileDescriptor(void)
91
110
return drizzleclient_net_get_sd(&net);
94
bool ClientOldLibdrizzle::isConnected()
113
bool ClientDrizzleProtocol::isConnected()
96
115
return net.vio != 0;
99
bool ClientOldLibdrizzle::isReading(void)
118
bool ClientDrizzleProtocol::isReading(void)
101
120
return net.reading_or_writing == 1;
104
bool ClientOldLibdrizzle::isWriting(void)
123
bool ClientDrizzleProtocol::isWriting(void)
106
125
return net.reading_or_writing == 2;
109
bool ClientOldLibdrizzle::flush()
128
bool ClientDrizzleProtocol::flush()
111
130
if (net.vio == NULL)
203
222
(*l_packet)[0]= (unsigned char) COM_SLEEP;
204
223
*packet_length= 1;
225
else if (using_mysql41_protocol)
227
/* Map from MySQL commands to Drizzle commands. */
228
switch ((int)(*l_packet)[0])
232
case 2: /* INIT_DB */
236
case 8: /* SHUTDOWN */
237
(*l_packet)[0]= (unsigned char) COM_SHUTDOWN;
241
(*l_packet)[0]= (unsigned char) COM_SHUTDOWN;
246
/* Just drop connection for MySQL commands we don't support. */
247
(*l_packet)[0]= (unsigned char) COM_QUIT;
206
253
/* Do not rely on drizzleclient_net_read, extra safety against programming errors. */
207
254
(*l_packet)[*packet_length]= '\0'; /* safety */
422
469
/* No conversion */
423
470
int2store(pos, field.charsetnr);
424
471
int4store(pos+2, field.length);
425
/* Add one to compensate for tinyint removal from enum. */
426
pos[6]= field.type + 1;
473
if (using_mysql41_protocol)
475
/* Switch to MySQL field numbering. */
478
case DRIZZLE_TYPE_LONG:
482
case DRIZZLE_TYPE_DOUBLE:
486
case DRIZZLE_TYPE_NULL:
490
case DRIZZLE_TYPE_TIMESTAMP:
494
case DRIZZLE_TYPE_LONGLONG:
498
case DRIZZLE_TYPE_DATETIME:
502
case DRIZZLE_TYPE_DATE:
506
case DRIZZLE_TYPE_VARCHAR:
510
case DRIZZLE_TYPE_DECIMAL:
514
case DRIZZLE_TYPE_ENUM:
518
case DRIZZLE_TYPE_BLOB:
525
/* Add one to compensate for tinyint removal from enum. */
526
pos[6]= field.type + 1;
427
529
int2store(pos+7,field.flags);
428
530
pos[9]= (char) field.decimals;
429
531
pos[10]= 0; // For the future
461
563
return netStoreData((const unsigned char *)str.ptr(), str.length());
464
bool ClientOldLibdrizzle::store(void)
566
bool ClientDrizzleProtocol::store(void)
467
569
buff[0]= (char)251;
468
570
return packet.append(buff, sizeof(buff), PACKET_BUFFER_EXTRA_ALLOC);
471
bool ClientOldLibdrizzle::store(int32_t from)
573
bool ClientDrizzleProtocol::store(int32_t from)
474
576
return netStoreData((unsigned char*) buff,
475
577
(size_t) (int10_to_str(from, buff, -10) - buff));
478
bool ClientOldLibdrizzle::store(uint32_t from)
580
bool ClientDrizzleProtocol::store(uint32_t from)
481
583
return netStoreData((unsigned char*) buff,
482
584
(size_t) (int10_to_str(from, buff, 10) - buff));
485
bool ClientOldLibdrizzle::store(int64_t from)
587
bool ClientDrizzleProtocol::store(int64_t from)
488
590
return netStoreData((unsigned char*) buff,
489
591
(size_t) (int64_t10_to_str(from, buff, -10) - buff));
492
bool ClientOldLibdrizzle::store(uint64_t from)
594
bool ClientDrizzleProtocol::store(uint64_t from)
495
597
return netStoreData((unsigned char*) buff,
496
598
(size_t) (int64_t10_to_str(from, buff, 10) - buff));
499
bool ClientOldLibdrizzle::store(double from, uint32_t decimals, String *buffer)
601
bool ClientDrizzleProtocol::store(double from, uint32_t decimals, String *buffer)
501
603
buffer->set_real(from, decimals, session->charset());
502
604
return netStoreData((unsigned char*) buffer->ptr(), buffer->length());
505
bool ClientOldLibdrizzle::store(const char *from, size_t length)
607
bool ClientDrizzleProtocol::store(const char *from, size_t length)
507
609
return netStoreData((const unsigned char *)from, length);
510
bool ClientOldLibdrizzle::wasAborted(void)
612
bool ClientDrizzleProtocol::wasAborted(void)
512
614
return net.error && net.vio != 0;
515
bool ClientOldLibdrizzle::haveMoreData(void)
617
bool ClientDrizzleProtocol::haveMoreData(void)
517
619
return drizzleclient_net_more_data(&net);
520
bool ClientOldLibdrizzle::haveError(void)
622
bool ClientDrizzleProtocol::haveError(void)
522
624
return net.error || net.vio == 0;
525
bool ClientOldLibdrizzle::checkConnection(void)
627
bool ClientDrizzleProtocol::checkConnection(void)
527
629
uint32_t pkt_len= 0;
702
807
drizzleclient_net_write(&net, buff, 5);
705
static ListenOldLibdrizzle *listen_obj= NULL;
810
static ListenDrizzleProtocol *listen_obj= NULL;
707
812
static int init(drizzled::plugin::Registry ®istry)
709
listen_obj= new ListenOldLibdrizzle("oldlibdrizzle");
814
listen_obj= new ListenDrizzleProtocol("drizzle_protocol", false);
710
815
registry.add(listen_obj);
826
static DRIZZLE_SYSVAR_UINT(port, port, PLUGIN_VAR_RQCMDARG,
827
N_("Port number to use for connection or 0 for default to, in order of "
828
"preference, drizzle.cnf, $DRIZZLE_TCP_PORT, built-in default ("
829
STRINGIFY_ARG(DRIZZLE_TCP_PORT) ")."),
830
NULL, NULL, 0, 0, 65535, 0);
721
831
static DRIZZLE_SYSVAR_UINT(connect_timeout, connect_timeout,
722
832
PLUGIN_VAR_RQCMDARG, N_("Connect Timeout."),
723
833
NULL, NULL, 10, 1, 300, 0);
734
844
N_("Address to bind to."), NULL, NULL, NULL);
736
846
static struct st_mysql_sys_var* system_variables[]= {
847
DRIZZLE_SYSVAR(port),
737
848
DRIZZLE_SYSVAR(connect_timeout),
738
849
DRIZZLE_SYSVAR(read_timeout),
739
850
DRIZZLE_SYSVAR(write_timeout),