Drizzled Public API Documentation

drizzle_protocol.cc
1 /* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3  *
4  * Copyright (C) 2010 Brian Aker
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; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 
22 #include <config.h>
23 #include <drizzled/gettext.h>
24 #include <drizzled/error.h>
25 #include <drizzled/session.h>
26 #include <drizzled/internal/my_sys.h>
27 #include <drizzled/internal/m_string.h>
28 #include <algorithm>
29 #include <iostream>
30 #include <boost/program_options.hpp>
32 #include <drizzled/util/tokenize.h>
33 #include "drizzle_protocol.h"
34 
35 namespace po= boost::program_options;
36 using namespace drizzled;
37 using namespace std;
38 
39 namespace drizzle_plugin {
40 namespace drizzle_protocol {
41 
42 static port_constraint port;
43 static timeout_constraint connect_timeout;
44 static timeout_constraint read_timeout;
45 static timeout_constraint write_timeout;
46 static retry_constraint retry_count;
47 static buffer_constraint buffer_length;
48 
49 static const uint32_t DRIZZLE_TCP_PORT= 4427;
50 
51 ProtocolCounters ListenDrizzleProtocol::drizzle_counters;
52 
53 in_port_t ListenDrizzleProtocol::getPort() const
54 {
55  return port;
56 }
57 
58 plugin::Client *ListenDrizzleProtocol::getClient(int fd)
59 {
60  int new_fd= acceptTcp(fd);
61  return new_fd == -1 ? NULL : new ClientMySQLProtocol(new_fd, getCounters());
62 }
63 
64 static int init(drizzled::module::Context &context)
65 {
66  const module::option_map &vm= context.getOptions();
67 
68  ListenDrizzleProtocol *protocol=new ListenDrizzleProtocol("drizzle_protocol", vm["bind-address"].as<std::string>());
69  protocol->addCountersToTable();
70  context.add(protocol);
71  context.registerVariable(new sys_var_constrained_value_readonly<in_port_t>("port", port));
72  context.registerVariable(new sys_var_constrained_value_readonly<uint32_t>("connect_timeout", connect_timeout));
73  context.registerVariable(new sys_var_constrained_value_readonly<uint32_t>("read_timeout", read_timeout));
74  context.registerVariable(new sys_var_constrained_value_readonly<uint32_t>("write_timeout", write_timeout));
75  context.registerVariable(new sys_var_constrained_value_readonly<uint32_t>("retry_count", retry_count));
76  context.registerVariable(new sys_var_constrained_value_readonly<uint32_t>("buffer_length", buffer_length));
77  context.registerVariable(new sys_var_const_string_val("bind_address", vm["bind-address"].as<std::string>()));
78  context.registerVariable(new sys_var_uint32_t_ptr("max-connections", &ListenDrizzleProtocol::drizzle_counters.max_connections));
79 
80  return 0;
81 }
82 
83 
84 static void init_options(drizzled::module::option_context &context)
85 {
86  context("port",
87  po::value<port_constraint>(&port)->default_value(DRIZZLE_TCP_PORT),
88  N_("Port number to use for connection or 0 for default to with Drizzle/MySQL protocol."));
89  context("connect-timeout",
90  po::value<timeout_constraint>(&connect_timeout)->default_value(10),
91  N_("Connect Timeout."));
92  context("read-timeout",
93  po::value<timeout_constraint>(&read_timeout)->default_value(30),
94  N_("Read Timeout."));
95  context("write-timeout",
96  po::value<timeout_constraint>(&write_timeout)->default_value(60),
97  N_("Write Timeout."));
98  context("retry-count",
99  po::value<retry_constraint>(&retry_count)->default_value(10),
100  N_("Retry Count."));
101  context("buffer-length",
102  po::value<buffer_constraint>(&buffer_length)->default_value(16384),
103  N_("Buffer length."));
104  context("bind-address",
105  po::value<std::string>()->default_value("localhost"),
106  N_("Address to bind to."));
107  context("max-connections",
108  po::value<uint32_t>(&ListenDrizzleProtocol::drizzle_counters.max_connections)->default_value(1000),
109  N_("Maximum simultaneous connections."));
110 }
111 
112 } /* namespace drizzle_protocol */
113 } /* namespace drizzle_plugin */
114 
115 DRIZZLE_DECLARE_PLUGIN
116 {
117  DRIZZLE_VERSION_ID,
118  "drizzle_protocol",
119  "0.3",
120  "Brian Aker",
121  N_("Drizzle network protocol"),
122  PLUGIN_LICENSE_GPL,
123  drizzle_plugin::drizzle_protocol::init,
124  NULL,
125  drizzle_plugin::drizzle_protocol::init_options,
126 }
127 DRIZZLE_DECLARE_PLUGIN_END;
An Proxy Wrapper around boost::program_options::variables_map.