Drizzled Public API Documentation

mysql_protocol.h
00001 /* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
00002  *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
00003  *
00004  *  Copyright (C) 2008 Sun Microsystems, Inc.
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; version 2 of the License.
00009  *
00010  *  This program is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *  GNU General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with this program; if not, write to the Free Software
00017  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00018  */
00019 
00020 #pragma once
00021 
00022 #include <drizzled/plugin/listen_tcp.h>
00023 #include <drizzled/plugin/client.h>
00024 #include <drizzled/atomics.h>
00025 #include <drizzled/plugin/table_function.h>
00026 
00027 #include "net_serv.h"
00028 
00029 namespace drizzle_plugin {
00030 
00031 class ProtocolCounters
00032 {
00033 public:
00034   ProtocolCounters() :
00035       max_connections(1000)
00036   { }
00037 
00038   drizzled::atomic<uint64_t> connectionCount;
00039   drizzled::atomic<uint64_t> failedConnections;
00040   drizzled::atomic<uint64_t> connected;
00041   uint32_t max_connections;
00042 };
00043 
00044 typedef drizzled::constrained_check<uint32_t, 300, 1> timeout_constraint;
00045 typedef drizzled::constrained_check<uint32_t, 300, 1> retry_constraint;
00046 typedef drizzled::constrained_check<uint32_t, 1048576, 1024, 1024> buffer_constraint;
00047 
00048 class ListenMySQLProtocol: public drizzled::plugin::ListenTcp
00049 {
00050 public:
00051   ListenMySQLProtocol(std::string name, const std::string &hostname) :
00052    drizzled::plugin::ListenTcp(name),
00053    _hostname(hostname)
00054   { }
00055   virtual const std::string getHost() const;
00056   virtual in_port_t getPort() const;
00057   virtual drizzled::plugin::Client *getClient(int fd);
00058   static ProtocolCounters mysql_counters;
00059   virtual ProtocolCounters& getCounters() const { return mysql_counters; }
00060   void addCountersToTable();
00061 protected:
00062   const std::string _hostname;
00063 };
00064 
00065 class ClientMySQLProtocol: public drizzled::plugin::Client
00066 {
00067 protected:
00068   NET net;
00069   drizzled::String packet;
00070   uint32_t client_capabilities;
00071   bool _is_interactive;
00072 
00073   bool checkConnection();
00074   void netStoreData(const void*, size_t);
00075   void writeEOFPacket(uint32_t server_status, uint32_t total_warn_count);
00076   unsigned char *storeLength(unsigned char *packet, uint64_t length);
00077   void makeScramble(char *scramble);
00078 
00079 public:
00080   ClientMySQLProtocol(int fd, ProtocolCounters&);
00081   virtual ~ClientMySQLProtocol();
00082 
00083   bool isInteractive() const
00084   {
00085     return _is_interactive;
00086   }
00087 
00088   ProtocolCounters& counters;
00089 
00090   virtual int getFileDescriptor();
00091   virtual bool isConnected();
00092   virtual bool flush();
00093   virtual void close();
00094 
00095   virtual bool authenticate();
00096   virtual bool readCommand(char **packet, uint32_t& packet_length);
00097 
00098   virtual void sendOK();
00099   virtual void sendEOF();
00100   virtual void sendError(const drizzled::error_t sql_errno, const char *err);
00101 
00102   virtual void sendFields(drizzled::List<drizzled::Item>&);
00103 
00104   using Client::store;
00105   virtual void store(drizzled::Field*);
00106   virtual void store();
00107   virtual void store(int32_t from);
00108   virtual void store(uint32_t from);
00109   virtual void store(int64_t from);
00110   virtual void store(uint64_t from);
00111   virtual void store(double from, uint32_t decimals, drizzled::String *buffer);
00112   virtual void store(const char*, size_t);
00113 
00114   virtual bool haveError();
00115   virtual bool wasAborted();
00116 };
00117 
00118 } /* namespace drizzle_plugin */
00119