1
/* Copyright (C) 2009 Sun Microsystems
3
This program is free software; you can redistribute it and/or modify
4
it under the terms of the GNU General Public License as published by
5
the Free Software Foundation; version 2 of the License.
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
12
You should have received a copy of the GNU General Public License
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
17
session_scheduler keeps the link between Session and events.
18
It's embedded in the Session class.
21
#include <drizzled/session.h>
22
#include <drizzled/gettext.h>
23
#include <drizzled/errmsg_print.h>
25
/* API for connecting, logging in to a drizzled server */
26
#include <drizzled/connect.h>
27
#include "session_scheduler.h"
30
void libevent_io_callback(int Fd, short Operation, void *ctx);
31
bool libevent_should_close_connection(Session* session);
32
void libevent_session_add(Session* session);
34
session_scheduler::session_scheduler()
35
: logged_in(false), io_event(NULL), thread_attached(false)
40
session_scheduler::~session_scheduler()
46
session_scheduler::session_scheduler(const session_scheduler&)
47
: logged_in(false), io_event(NULL), thread_attached(false)
50
void session_scheduler::operator=(const session_scheduler&)
53
bool session_scheduler::init(Session *parent_session)
55
io_event= new struct event;
59
errmsg_printf(ERRMSG_LVL_ERROR, _("Memory allocation error in session_scheduler::init\n"));
62
memset(io_event, 0, sizeof(*io_event));
64
event_set(io_event, net_get_sd(&(parent_session->net)), EV_READ,
65
libevent_io_callback, (void*)parent_session);
67
list.data= parent_session;
74
Attach/associate the connection with the OS thread, for command processing.
77
bool session_scheduler::thread_attach()
79
assert(!thread_attached);
80
Session* session = (Session*)list.data;
81
if (libevent_should_close_connection(session) ||
82
setup_connection_thread_globals(session))
87
session->mysys_var->abort= 0;
88
thread_attached= true;
95
Detach/disassociate the connection with the OS thread.
98
void session_scheduler::thread_detach()
102
Session* session = (Session*)list.data;
103
session->mysys_var= NULL;
104
thread_attached= false;