drizzle
C++ MySQL-protocol-compatible database server
Loading...
Searching...
No Matches
mysql_protocol.h
1/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3 *
4 * Copyright (C) 2008 Sun Microsystems, Inc.
5 *
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.
9 *
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.
14 *
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
18 */
19
20#pragma once
21
22#include <drizzled/plugin/listen_tcp.h>
23#include <drizzled/plugin/client.h>
24#include <drizzled/atomics.h>
25#include <drizzled/plugin/table_function.h>
26
27#include "net_serv.h"
28
29namespace drizzle_plugin {
30
31class ProtocolCounters
32{
33public:
34 ProtocolCounters() :
35 max_connections(1000)
36 { }
37
38 drizzled::atomic<uint64_t> connectionCount;
39 drizzled::atomic<uint64_t> failedConnections;
40 drizzled::atomic<uint64_t> connected;
41 uint32_t max_connections;
42};
43
44typedef drizzled::constrained_check<uint32_t, 300, 1> timeout_constraint;
47
48class ListenMySQLProtocol: public drizzled::plugin::ListenTcp
49{
50public:
51 ListenMySQLProtocol(std::string name, const std::string &hostname) :
53 _hostname(hostname)
54 { }
55 virtual const std::string getHost() const;
56 virtual in_port_t getPort() const;
57 virtual drizzled::plugin::Client *getClient(int fd);
58 static ProtocolCounters mysql_counters;
59 virtual ProtocolCounters& getCounters() const { return mysql_counters; }
60 void addCountersToTable();
61protected:
62 const std::string _hostname;
63};
64
65class ClientMySQLProtocol: public drizzled::plugin::Client
66{
67protected:
68 NET net;
69 drizzled::String packet;
70 uint32_t client_capabilities;
71 bool _is_interactive;
72
73 bool checkConnection();
74 void netStoreData(const void*, size_t);
75 void writeEOFPacket(uint32_t server_status, uint32_t total_warn_count);
76 unsigned char *storeLength(unsigned char *packet, uint64_t length);
77 void makeScramble(char *scramble);
78
79public:
80 ClientMySQLProtocol(int fd, ProtocolCounters&);
81 virtual ~ClientMySQLProtocol();
82
83 bool isInteractive() const
84 {
85 return _is_interactive;
86 }
87
88 ProtocolCounters& counters;
89
90 virtual int getFileDescriptor();
91 virtual bool isConnected();
92 virtual bool flush();
93 virtual void close();
94
95 virtual bool authenticate();
96 virtual bool readCommand(char **packet, uint32_t& packet_length);
97
98 virtual void sendOK();
99 virtual void sendEOF();
100 virtual void sendError(const drizzled::error_t sql_errno, const char *err);
101
103
104 using Client::store;
105 virtual void store(drizzled::Field*);
106 virtual void store();
107 virtual void store(int32_t from);
108 virtual void store(uint32_t from);
109 virtual void store(int64_t from);
110 virtual void store(uint64_t from);
111 virtual void store(double from, uint32_t decimals, drizzled::String *buffer);
112 virtual void store(const char*, size_t);
113
114 virtual bool haveError();
115 virtual bool wasAborted();
116};
117
118} /* namespace drizzle_plugin */
119
void writeEOFPacket(uint32_t server_status, uint32_t total_warn_count)
virtual void sendFields(drizzled::List< drizzled::Item > &)
virtual void sendError(const drizzled::error_t sql_errno, const char *err)
virtual bool readCommand(char **packet, uint32_t &packet_length)
virtual in_port_t getPort() const
virtual const std::string getHost() const
virtual drizzled::plugin::Client * getClient(int fd)