1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008 Sun Microsystems
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; version 2 of the License.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
#ifndef PLUGIN_MYSQL_PROTOCOL_MYSQL_PROTOCOL_H
21
#define PLUGIN_MYSQL_PROTOCOL_MYSQL_PROTOCOL_H
23
#include <drizzled/plugin/listen_tcp.h>
24
#include <drizzled/plugin/client.h>
25
#include <drizzled/atomics.h>
26
#include "drizzled/plugin/table_function.h"
30
namespace drizzle_plugin
32
class ProtocolCounters
38
drizzled::atomic<uint64_t> connectionCount;
39
drizzled::atomic<uint64_t> failedConnections;
40
drizzled::atomic<uint64_t> connected;
41
uint32_t max_connections;
44
typedef drizzled::constrained_check<uint32_t, 300, 1> timeout_constraint;
45
typedef drizzled::constrained_check<uint32_t, 300, 1> retry_constraint;
46
typedef drizzled::constrained_check<uint32_t, 1048576, 1024, 1024> buffer_constraint;
48
class ListenMySQLProtocol: public drizzled::plugin::ListenTcp
51
const std::string _hostname;
52
bool _using_mysql41_protocol;
55
ListenMySQLProtocol(std::string name,
56
const std::string &hostname,
57
bool using_mysql41_protocol):
58
drizzled::plugin::ListenTcp(name),
60
_using_mysql41_protocol(using_mysql41_protocol)
62
virtual ~ListenMySQLProtocol();
63
virtual const std::string getHost(void) const;
64
virtual in_port_t getPort(void) const;
65
virtual drizzled::plugin::Client *getClient(int fd);
66
static ProtocolCounters *mysql_counters;
67
virtual ProtocolCounters *getCounters(void) const { return mysql_counters; }
70
class ClientMySQLProtocol: public drizzled::plugin::Client
74
drizzled::String packet;
75
uint32_t client_capabilities;
76
bool _using_mysql41_protocol;
78
bool checkConnection(void);
79
bool netStoreData(const unsigned char *from, size_t length);
80
void writeEOFPacket(uint32_t server_status, uint32_t total_warn_count);
81
unsigned char *storeLength(unsigned char *packet, uint64_t length);
82
void makeScramble(char *scramble);
85
ClientMySQLProtocol(int fd, bool _using_mysql41_protocol, ProtocolCounters *set_counters);
86
virtual ~ClientMySQLProtocol();
88
ProtocolCounters *counters;
90
virtual int getFileDescriptor(void);
91
virtual bool isConnected();
92
virtual bool isReading(void);
93
virtual bool isWriting(void);
94
virtual bool flush(void);
95
virtual void close(void);
97
virtual bool authenticate(void);
98
virtual bool readCommand(char **packet, uint32_t *packet_length);
100
virtual void sendOK(void);
101
virtual void sendEOF(void);
102
virtual void sendError(uint32_t sql_errno, const char *err);
104
virtual bool sendFields(drizzled::List<drizzled::Item> *list);
107
virtual bool store(drizzled::Field *from);
108
virtual bool store(void);
109
virtual bool store(int32_t from);
110
virtual bool store(uint32_t from);
111
virtual bool store(int64_t from);
112
virtual bool store(uint64_t from);
113
virtual bool store(double from, uint32_t decimals, drizzled::String *buffer);
114
virtual bool store(const char *from, size_t length);
116
virtual bool haveError(void);
117
virtual bool haveMoreData(void);
118
virtual bool wasAborted(void);
121
} /* namespace drizzle_plugin */
123
#endif /* PLUGIN_MYSQL_PROTOCOL_MYSQL_PROTOCOL_H */