1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
/* Copyright (C) 2009 Sun Microsystems
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
/*
session_scheduler keeps the link between Session and events.
It's embedded in the Session class.
*/
#include <drizzled/global.h>
#include <drizzled/session.h>
#include <drizzled/gettext.h>
#include <drizzled/errmsg_print.h>
#include <event.h>
/* API for connecting, logging in to a drizzled server */
#include <drizzled/connect.h>
#include "session_scheduler.h"
/* Prototype */
extern "C"
void libevent_io_callback(int Fd, short Operation, void *ctx);
bool libevent_should_close_connection(Session* session);
void libevent_session_add(Session* session);
session_scheduler::session_scheduler(Session *parent_session)
: logged_in(false), thread_attached(false)
{
memset(&io_event, 0, sizeof(struct event));
event_set(&io_event, parent_session->protocol->fileDescriptor(), EV_READ,
libevent_io_callback, (void*)parent_session);
session= parent_session;
}
/*
Attach/associate the connection with the OS thread, for command processing.
*/
bool session_scheduler::thread_attach()
{
assert(!thread_attached);
if (libevent_should_close_connection(session) ||
! session->initGlobals())
{
return true;
}
my_errno= 0;
session->mysys_var->abort= 0;
thread_attached= true;
return false;
}
/*
Detach/disassociate the connection with the OS thread.
*/
void session_scheduler::thread_detach()
{
if (thread_attached)
{
session->mysys_var= NULL;
thread_attached= false;
}
}
|