38
38
extern uint32_t drizzled_tcp_port;
40
40
static const unsigned int PACKET_BUFFER_EXTRA_ALLOC= 1024;
41
static uint32_t _port= 0;
42
41
static uint32_t connect_timeout;
43
42
static uint32_t read_timeout;
44
43
static uint32_t write_timeout;
45
44
static uint32_t retry_count;
47
ListenOldLibdrizzle::ListenOldLibdrizzle()
49
port= (in_port_t) _port;
52
46
in_port_t ListenOldLibdrizzle::getPort(void) const
55
return (in_port_t ) drizzled_tcp_port;
48
return (in_port_t) drizzled_tcp_port;
60
plugin::Protocol *ListenOldLibdrizzle::protocolFactory(void) const
51
plugin::Client *ListenOldLibdrizzle::getClient(int fd)
62
return new ProtocolOldLibdrizzle;
54
return new (nothrow) ClientOldLibdrizzle(-1);
57
new_fd= acceptTcp(fd);
61
return new (nothrow) ClientOldLibdrizzle(new_fd);
65
64
static void write_eof_packet(Session *session, NET *net,
66
65
uint32_t server_status, uint32_t total_warn_count);
68
bool ProtocolOldLibdrizzle::isConnected()
67
bool ClientOldLibdrizzle::isConnected()
70
69
return net.vio != 0;
73
void ProtocolOldLibdrizzle::setError(char error)
72
void ClientOldLibdrizzle::setError(char error)
78
bool ProtocolOldLibdrizzle::haveError(void)
77
bool ClientOldLibdrizzle::haveError(void)
80
79
return net.error || net.vio == 0;
83
bool ProtocolOldLibdrizzle::wasAborted(void)
82
bool ClientOldLibdrizzle::wasAborted(void)
85
84
return net.error && net.vio != 0;
88
bool ProtocolOldLibdrizzle::haveMoreData(void)
87
bool ClientOldLibdrizzle::haveMoreData(void)
90
89
return drizzleclient_net_more_data(&net);
93
bool ProtocolOldLibdrizzle::isReading(void)
92
bool ClientOldLibdrizzle::isReading(void)
95
94
return net.reading_or_writing == 1;
98
bool ProtocolOldLibdrizzle::isWriting(void)
97
bool ClientOldLibdrizzle::isWriting(void)
100
99
return net.reading_or_writing == 2;
103
bool ProtocolOldLibdrizzle::netStoreData(const unsigned char *from, size_t length)
102
bool ClientOldLibdrizzle::netStoreData(const unsigned char *from, size_t length)
105
104
size_t packet_length= packet->length();
127
126
- id : Stored in 1-9 bytes
128
127
- server_status : Copy of session->server_status; Can be used by client
129
128
to check if we are inside an transaction.
131
- warning_count : Stored in 2 bytes; New in 4.1 protocol
130
- warning_count : Stored in 2 bytes; New in 4.1 client
132
131
- message : Stored as packed length (1-9 bytes) + message.
133
132
Is not stored if no message.
138
137
@param message Message to send to the client (Used by mysql_status)
141
void ProtocolOldLibdrizzle::sendOK()
140
void ClientOldLibdrizzle::sendOK()
143
142
unsigned char buff[DRIZZLE_ERRMSG_SIZE+10],*pos;
144
143
const char *message= NULL;
196
195
The eof packet has the following structure:
198
197
- 254 (DRIZZLE_PROTOCOL_NO_MORE_DATA) : Marker (1 byte)
199
- warning_count : Stored in 2 bytes; New in 4.1 protocol
198
- warning_count : Stored in 2 bytes; New in 4.1 client
200
199
- status_flag : Stored in 2 bytes;
201
200
For flags like SERVER_MORE_RESULTS_EXISTS.
283
282
int2store(buff,sql_errno);
286
/* The first # is to make the protocol backward compatible */
285
/* The first # is to make the client backward compatible */
288
287
pos= (unsigned char*) strcpy((char*) buff+3, drizzle_errno_to_sqlstate(sql_errno));
289
288
pos+= strlen(drizzle_errno_to_sqlstate(sql_errno));
303
ProtocolOldLibdrizzle::ProtocolOldLibdrizzle()
302
ClientOldLibdrizzle::ClientOldLibdrizzle(int fd)
310
if (drizzleclient_net_init_sock(&net, fd, 0))
313
drizzleclient_net_set_read_timeout(&net, read_timeout);
314
drizzleclient_net_set_write_timeout(&net, write_timeout);
315
net.retry_count=retry_count;
309
ProtocolOldLibdrizzle::~ProtocolOldLibdrizzle()
318
ClientOldLibdrizzle::~ClientOldLibdrizzle()
312
321
drizzleclient_vio_close(net.vio);
315
void ProtocolOldLibdrizzle::setSession(Session *session_arg)
324
void ClientOldLibdrizzle::setSession(Session *session_arg)
317
326
session= session_arg;
318
327
packet= &session->packet;
319
328
convert= &session->convert_buffer;
404
bool ProtocolOldLibdrizzle::write()
414
bool ClientOldLibdrizzle::flush()
406
return(drizzleclient_net_write(&net, (unsigned char*) packet->ptr(),
418
bool ret= drizzleclient_net_write(&net, (unsigned char*) packet->ptr(),
410
void ProtocolOldLibdrizzle::free()
424
void ClientOldLibdrizzle::free()
415
bool ProtocolOldLibdrizzle::setFileDescriptor(int fd)
417
if (drizzleclient_net_init_sock(&net, fd, 0))
420
drizzleclient_net_set_read_timeout(&net, read_timeout);
421
drizzleclient_net_set_write_timeout(&net, write_timeout);
422
net.retry_count=retry_count;
427
int ProtocolOldLibdrizzle::fileDescriptor(void)
429
int ClientOldLibdrizzle::getFileDescriptor(void)
429
431
return drizzleclient_net_get_sd(&net);
432
bool ProtocolOldLibdrizzle::authenticate()
434
bool ClientOldLibdrizzle::authenticate()
434
436
bool connection_is_valid;
535
void ProtocolOldLibdrizzle::forceClose(void)
534
void ClientOldLibdrizzle::forceClose(void)
538
537
drizzleclient_vio_close(net.vio);
541
void ProtocolOldLibdrizzle::prepareForResend()
540
void ClientOldLibdrizzle::prepareForResend()
543
542
packet->length(0);
546
bool ProtocolOldLibdrizzle::store(void)
545
bool ClientOldLibdrizzle::store(void)
549
548
buff[0]= (char)251;
554
bool ProtocolOldLibdrizzle::store(const char *from, size_t length)
553
bool ClientOldLibdrizzle::store(const char *from, size_t length)
556
555
return netStoreData((const unsigned char *)from, length);
560
bool ProtocolOldLibdrizzle::store(int32_t from)
559
bool ClientOldLibdrizzle::store(int32_t from)
563
562
return netStoreData((unsigned char*) buff,
564
563
(size_t) (int10_to_str(from, buff, -10) - buff));
567
bool ProtocolOldLibdrizzle::store(uint32_t from)
566
bool ClientOldLibdrizzle::store(uint32_t from)
570
569
return netStoreData((unsigned char*) buff,
571
570
(size_t) (int10_to_str(from, buff, 10) - buff));
574
bool ProtocolOldLibdrizzle::store(int64_t from)
573
bool ClientOldLibdrizzle::store(int64_t from)
577
576
return netStoreData((unsigned char*) buff,
578
577
(size_t) (int64_t10_to_str(from, buff, -10) - buff));
581
bool ProtocolOldLibdrizzle::store(uint64_t from)
580
bool ClientOldLibdrizzle::store(uint64_t from)
584
583
return netStoreData((unsigned char*) buff,
589
bool ProtocolOldLibdrizzle::store(double from, uint32_t decimals, String *buffer)
588
bool ClientOldLibdrizzle::store(double from, uint32_t decimals, String *buffer)
591
590
buffer->set_real(from, decimals, session->charset());
592
591
return netStoreData((unsigned char*) buffer->ptr(), buffer->length());
596
bool ProtocolOldLibdrizzle::store(Field *from)
595
bool ClientOldLibdrizzle::store(Field *from)
598
597
if (from->is_null())
669
668
// TCP/IP connection
671
670
char ip[NI_MAXHOST];
673
if (drizzleclient_net_peer_addr(&net, ip, &session->peer_port, NI_MAXHOST))
673
if (drizzleclient_net_peer_addr(&net, ip, &port, NI_MAXHOST))
675
675
my_error(ER_BAD_HOST_ERROR, MYF(0), session->security_ctx.ip.c_str());
780
780
the size (1 byte) + string (not null-terminated). Hence in case of empty
781
781
password both send '\0'.
783
This strlen() can't be easily deleted without changing protocol.
783
This strlen() can't be easily deleted without changing client.
785
785
Cast *passwd to an unsigned char, so that it doesn't extend the sign for
786
786
*passwd > 127 and become 2**32-127+ after casting to uint.
789
789
(unsigned char)(*passwd++) : strlen(passwd);
790
790
l_db= client_capabilities & CLIENT_CONNECT_WITH_DB ? l_db + passwd_len + 1 : 0;
792
/* strlen() can't be easily deleted without changing protocol */
792
/* strlen() can't be easily deleted without changing client */
793
793
uint32_t db_len= l_db ? strlen(l_db) : 0;
795
795
if (passwd + passwd_len + db_len > (char *) net.read_pos + pkt_len)