1
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2010 Brian Aker
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.
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.
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
23
#include <drizzled/gettext.h>
24
#include <drizzled/error.h>
25
#include <drizzled/query_id.h>
26
#include <drizzled/sql_state.h>
27
#include <drizzled/session.h>
28
#include "drizzled/internal/my_sys.h"
29
#include "drizzled/internal/m_string.h"
32
#include <boost/program_options.hpp>
33
#include <drizzled/module/option_map.h>
37
#include "plugin/mysql_unix_socket_protocol/protocol.h"
39
#define DRIZZLE_UNIX_SOCKET_PATH "/tmp/mysql.socket"
41
static std::string unix_socket_path(DRIZZLE_UNIX_SOCKET_PATH);
43
namespace po= boost::program_options;
44
using namespace drizzled;
47
namespace mysql_unix_socket_protocol
54
const char* Protocol::getHost(void) const
56
return DRIZZLE_UNIX_SOCKET_PATH;
59
in_port_t Protocol::getPort(void) const
64
static int init(drizzled::module::Context &context)
66
const module::option_map &vm= context.getOptions();
70
unix_socket_path.clear();
71
unix_socket_path.append(vm["path"].as<string>());
74
context.add(new Protocol("mysql_unix_socket_protocol", true));
79
bool Protocol::getFileDescriptors(std::vector<int> &fds)
81
struct sockaddr_un servAddr;
84
if ((unix_sock= socket(AF_UNIX, SOCK_STREAM, 0)) < 0)
86
std::cerr << "Can't start server : UNIX Socket";
90
memset(&servAddr, 0, sizeof(servAddr));
92
servAddr.sun_family= AF_UNIX;
93
strcpy(servAddr.sun_path, unix_socket_path.c_str());
94
(void) unlink(unix_socket_path.c_str());
98
(void) setsockopt(unix_sock, SOL_SOCKET, SO_REUSEADDR, (char*)&arg, sizeof(arg));
100
if (bind(unix_sock, reinterpret_cast<struct sockaddr *>(&servAddr), sizeof(servAddr)) < 0)
102
std::cerr << "Can't start server : Bind on unix socket\n";
103
std::cerr << "Do you already have another of drizzled or mysqld running on socket: " << "/tmp/mysql.socket" << "?\n";
104
std::cerr << "Can't start server : UNIX Socket";
109
if (listen(unix_sock,(int) 1000) < 0)
111
std::cerr << "listen() on Unix socket failed with error " << errno << "\n";
115
std::cerr << "Listening on " << unix_socket_path.c_str() << "\n";
118
fds.push_back(unix_sock);
124
static void init_options(drizzled::module::option_context &context)
127
po::value<string>()->default_value(unix_socket_path),
128
N_("Path used for MySQL UNIX Socket Protocol."));
131
static drizzle_sys_var* sys_variables[]= {
135
} /* namespace mysql_unix_socket_protocol */
137
DRIZZLE_PLUGIN(mysql_unix_socket_protocol::init, mysql_unix_socket_protocol::sys_variables, mysql_unix_socket_protocol::init_options);