61
61
static const uint32_t random_max= 0x3FFFFFFF;
62
62
static const double random_max_double= (double)0x3FFFFFFF;
65
ProtocolCounters *ListenMySQLProtocol::mysql_counters= new ProtocolCounters();
67
ListenMySQLProtocol::~ListenMySQLProtocol()
64
ProtocolCounters ListenMySQLProtocol::mysql_counters;
70
66
void ListenMySQLProtocol::addCountersToTable()
72
counters.push_back(new drizzled::plugin::ListenCounter(new std::string("connection_count"), &getCounters()->connectionCount));
73
counters.push_back(new drizzled::plugin::ListenCounter(new std::string("connected"), &getCounters()->connected));
74
counters.push_back(new drizzled::plugin::ListenCounter(new std::string("failed_connections"), &getCounters()->failedConnections));
68
counters.push_back(new drizzled::plugin::ListenCounter(new std::string("connection_count"), &getCounters().connectionCount));
69
counters.push_back(new drizzled::plugin::ListenCounter(new std::string("connected"), &getCounters().connected));
70
counters.push_back(new drizzled::plugin::ListenCounter(new std::string("failed_connections"), &getCounters().failedConnections));
77
73
const std::string ListenMySQLProtocol::getHost(void) const
87
83
plugin::Client *ListenMySQLProtocol::getClient(int fd)
90
new_fd= acceptTcp(fd);
94
return new ClientMySQLProtocol(new_fd, _using_mysql41_protocol, getCounters());
85
int new_fd= acceptTcp(fd);
86
return new_fd == -1 ? NULL : new ClientMySQLProtocol(new_fd, _using_mysql41_protocol, getCounters());
97
ClientMySQLProtocol::ClientMySQLProtocol(int fd, bool using_mysql41_protocol, ProtocolCounters *set_counters):
89
ClientMySQLProtocol::ClientMySQLProtocol(int fd, bool using_mysql41_protocol, ProtocolCounters& set_counters) :
98
90
_using_mysql41_protocol(using_mysql41_protocol),
99
91
_is_interactive(false),
100
92
counters(set_counters)
108
if (drizzleclient_net_init_sock(&net, fd, buffer_length.get()))
99
drizzleclient_net_init_sock(&net, fd, buffer_length.get());
111
100
drizzleclient_net_set_read_timeout(&net, read_timeout.get());
112
101
drizzleclient_net_set_write_timeout(&net, write_timeout.get());
113
102
net.retry_count=retry_count.get();
129
118
return net.vio != 0;
132
bool ClientMySQLProtocol::isReading(void)
121
bool ClientMySQLProtocol::isReading()
134
123
return net.reading_or_writing == 1;
137
bool ClientMySQLProtocol::isWriting(void)
126
bool ClientMySQLProtocol::isWriting()
139
128
return net.reading_or_writing == 2;
144
133
if (net.vio == NULL)
146
bool ret= drizzleclient_net_write(&net, (unsigned char*) packet.ptr(),
135
bool ret= drizzleclient_net_write(&net, (unsigned char*) packet.ptr(), packet.length());
148
136
packet.length(0);
152
void ClientMySQLProtocol::close(void)
140
void ClientMySQLProtocol::close()
156
144
drizzleclient_net_close(&net);
157
145
drizzleclient_net_end(&net);
158
counters->connected.decrement();
146
counters.connected.decrement();
162
150
bool ClientMySQLProtocol::authenticate()
164
bool connection_is_valid;
165
counters->connectionCount.increment();
166
counters->connected.increment();
152
counters.connectionCount.increment();
153
counters.connected.increment();
168
155
/* Use "connect_timeout" value during connection phase */
169
156
drizzleclient_net_set_read_timeout(&net, connect_timeout.get());
170
157
drizzleclient_net_set_write_timeout(&net, connect_timeout.get());
172
connection_is_valid= checkConnection();
174
if (connection_is_valid)
159
if (checkConnection())
176
if (counters->connected > counters->max_connections)
161
if (counters.connected > counters.max_connections)
178
163
std::string errmsg(ER(ER_CON_COUNT_ERROR));
179
164
sendError(ER_CON_COUNT_ERROR, errmsg.c_str());
180
counters->failedConnections.increment();
165
counters.failedConnections.increment();
469
454
1 Error (Note that in this case the error is not sent to the
472
bool ClientMySQLProtocol::sendFields(List<Item> *list)
457
void ClientMySQLProtocol::sendFields(List<Item>& list)
474
List<Item>::iterator it(list->begin());
459
List<Item>::iterator it(list.begin());
476
460
unsigned char buff[80];
477
461
String tmp((char*) buff,sizeof(buff),&my_charset_bin);
479
unsigned char *row_pos= storeLength(buff, list->size());
463
unsigned char *row_pos= storeLength(buff, list.size());
480
464
(void) drizzleclient_net_write(&net, buff, (size_t) (row_pos-buff));
466
while (Item* item=it++)
486
469
item->make_field(&field);
496
479
packet.realloc(packet.length()+12);
498
481
/* Store fixed length fields */
499
pos= (char*) packet.ptr()+packet.length();
482
char* pos= (char*) packet.ptr()+packet.length();
500
483
*pos++= 12; // Length of packed fields
501
484
/* No conversion */
502
485
int2store(pos, field.charsetnr);
662
644
return net.error && net.vio != 0;
665
bool ClientMySQLProtocol::haveMoreData()
667
return drizzleclient_net_more_data(&net);
670
647
bool ClientMySQLProtocol::haveError()
672
649
return net.error || net.vio == 0;
851
828
user_identifier->setUser(user);
852
829
session->setUser(user_identifier);
854
return session->checkUser(string(passwd, passwd_len),
855
string(l_db ? l_db : ""));
831
return session->checkUser(string(passwd, passwd_len), string(l_db ? l_db : ""));
859
void ClientMySQLProtocol::netStoreData(const unsigned char *from, size_t length)
835
void ClientMySQLProtocol::netStoreData(const void* from, size_t length)
861
837
size_t packet_length= packet.length();
959
static ListenMySQLProtocol *listen_obj= NULL;
960
plugin::Create_function<MySQLPassword> *mysql_password= NULL;
935
static ListenMySQLProtocol* listen_obj= NULL;
936
plugin::Create_function<MySQLPassword>* mysql_password= NULL;
962
938
static int init(drizzled::module::Context &context)
980
956
context.registerVariable(new sys_var_constrained_value<uint32_t>("write_timeout", write_timeout));
981
957
context.registerVariable(new sys_var_constrained_value<uint32_t>("retry_count", retry_count));
982
958
context.registerVariable(new sys_var_constrained_value<uint32_t>("buffer_length", buffer_length));
983
context.registerVariable(new sys_var_const_string_val("bind_address",
984
vm["bind-address"].as<std::string>()));
986
context.registerVariable(new sys_var_uint32_t_ptr("max-connections", &ListenMySQLProtocol::mysql_counters->max_connections));
959
context.registerVariable(new sys_var_const_string_val("bind_address", vm["bind-address"].as<std::string>()));
960
context.registerVariable(new sys_var_uint32_t_ptr("max-connections", &ListenMySQLProtocol::mysql_counters.max_connections));
1013
987
po::value<string>()->default_value("localhost"),
1014
988
_("Address to bind to."));
1015
989
context("max-connections",
1016
po::value<uint32_t>(&ListenMySQLProtocol::mysql_counters->max_connections)->default_value(1000),
990
po::value<uint32_t>(&ListenMySQLProtocol::mysql_counters.max_connections)->default_value(1000),
1017
991
_("Maximum simultaneous connections."));