Drizzled Public API Documentation

drizzle_protocol.cc
00001 /* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
00002  *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
00003  *
00004  *  Copyright (C) 2010 Brian Aker
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; either version 2 of the License, or
00009  *  (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00019  */
00020 
00021 
00022 #include <config.h>
00023 #include <drizzled/gettext.h>
00024 #include <drizzled/error.h>
00025 #include <drizzled/session.h>
00026 #include <drizzled/internal/my_sys.h>
00027 #include <drizzled/internal/m_string.h>
00028 #include <algorithm>
00029 #include <iostream>
00030 #include <boost/program_options.hpp>
00031 #include <drizzled/module/option_map.h>
00032 #include <drizzled/util/tokenize.h>
00033 #include "drizzle_protocol.h"
00034 
00035 namespace po= boost::program_options;
00036 using namespace drizzled;
00037 using namespace std;
00038 
00039 namespace drizzle_plugin {
00040 namespace drizzle_protocol {
00041 
00042 static port_constraint port;
00043 static timeout_constraint connect_timeout;
00044 static timeout_constraint read_timeout;
00045 static timeout_constraint write_timeout;
00046 static retry_constraint retry_count;
00047 static buffer_constraint buffer_length;
00048 
00049 static const uint32_t DRIZZLE_TCP_PORT= 4427;
00050 
00051 ProtocolCounters ListenDrizzleProtocol::drizzle_counters;
00052 
00053 in_port_t ListenDrizzleProtocol::getPort() const
00054 {
00055   return port;
00056 }
00057 
00058 plugin::Client *ListenDrizzleProtocol::getClient(int fd)
00059 {
00060   int new_fd= acceptTcp(fd);
00061   return new_fd == -1 ? NULL : new ClientMySQLProtocol(new_fd, getCounters());
00062 }
00063 
00064 static int init(drizzled::module::Context &context)
00065 {  
00066   const module::option_map &vm= context.getOptions();
00067 
00068   ListenDrizzleProtocol *protocol=new ListenDrizzleProtocol("drizzle_protocol", vm["bind-address"].as<std::string>());
00069   protocol->addCountersToTable();
00070   context.add(protocol);
00071   context.registerVariable(new sys_var_constrained_value_readonly<in_port_t>("port", port));
00072   context.registerVariable(new sys_var_constrained_value_readonly<uint32_t>("connect_timeout", connect_timeout));
00073   context.registerVariable(new sys_var_constrained_value_readonly<uint32_t>("read_timeout", read_timeout));
00074   context.registerVariable(new sys_var_constrained_value_readonly<uint32_t>("write_timeout", write_timeout));
00075   context.registerVariable(new sys_var_constrained_value_readonly<uint32_t>("retry_count", retry_count));
00076   context.registerVariable(new sys_var_constrained_value_readonly<uint32_t>("buffer_length", buffer_length));
00077   context.registerVariable(new sys_var_const_string_val("bind_address", vm["bind-address"].as<std::string>()));
00078   context.registerVariable(new sys_var_uint32_t_ptr("max-connections", &ListenDrizzleProtocol::drizzle_counters.max_connections));
00079 
00080   return 0;
00081 }
00082 
00083 
00084 static void init_options(drizzled::module::option_context &context)
00085 {
00086   context("port",
00087           po::value<port_constraint>(&port)->default_value(DRIZZLE_TCP_PORT),
00088           N_("Port number to use for connection or 0 for default to with Drizzle/MySQL protocol."));
00089   context("connect-timeout",
00090           po::value<timeout_constraint>(&connect_timeout)->default_value(10),
00091           N_("Connect Timeout."));
00092   context("read-timeout",
00093           po::value<timeout_constraint>(&read_timeout)->default_value(30),
00094           N_("Read Timeout."));
00095   context("write-timeout",
00096           po::value<timeout_constraint>(&write_timeout)->default_value(60),
00097           N_("Write Timeout."));
00098   context("retry-count",
00099           po::value<retry_constraint>(&retry_count)->default_value(10),
00100           N_("Retry Count."));
00101   context("buffer-length",
00102           po::value<buffer_constraint>(&buffer_length)->default_value(16384),
00103           N_("Buffer length."));
00104   context("bind-address",
00105           po::value<std::string>()->default_value("localhost"),
00106           N_("Address to bind to."));
00107   context("max-connections",
00108           po::value<uint32_t>(&ListenDrizzleProtocol::drizzle_counters.max_connections)->default_value(1000),
00109           N_("Maximum simultaneous connections."));
00110 }
00111 
00112 } /* namespace drizzle_protocol */
00113 } /* namespace drizzle_plugin */
00114 
00115 DRIZZLE_PLUGIN(drizzle_plugin::drizzle_protocol::init, NULL, drizzle_plugin::drizzle_protocol::init_options);