drizzle
C++ MySQL-protocol-compatible database server
Loading...
Searching...
No Matches
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
35namespace po= boost::program_options;
36using namespace drizzled;
37using namespace std;
38
39namespace drizzle_plugin {
40namespace drizzle_protocol {
41
42static port_constraint port;
43static timeout_constraint connect_timeout;
44static timeout_constraint read_timeout;
45static timeout_constraint write_timeout;
46static retry_constraint retry_count;
47static buffer_constraint buffer_length;
48
49static const uint32_t DRIZZLE_TCP_PORT= 4427;
50
51ProtocolCounters ListenDrizzleProtocol::drizzle_counters;
52
54{
55 return port;
56}
57
59{
60 int new_fd= acceptTcp(fd);
61 return new_fd == -1 ? NULL : new ClientMySQLProtocol(new_fd, getCounters());
62}
63
64static 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
84static 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("0.0.0.0"),
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
115DRIZZLE_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}
127DRIZZLE_DECLARE_PLUGIN_END;
TODO: Rename this file - func.h is stupid.
STL namespace.
An Proxy Wrapper around boost::program_options::variables_map.