520.6.3
by Monty Taylor
Moved scheduler.h out of common_includes. |
1 |
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
|
2 |
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
|
|
3 |
*
|
|
4 |
* Copyright (C) 2008 Sun Microsystems
|
|
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; version 2 of the License.
|
|
9 |
*
|
|
10 |
* This program is distributed in the hope that it will be useful,
|
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13 |
* GNU General Public License for more details.
|
|
14 |
*
|
|
15 |
* You should have received a copy of the GNU General Public License
|
|
16 |
* along with this program; if not, write to the Free Software
|
|
17 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
18 |
*/
|
|
1
by brian
clean slate |
19 |
|
20 |
||
21 |
/*
|
|
22 |
Functions to autenticate and handle reqests for a connection
|
|
23 |
*/
|
|
243.1.17
by Jay Pipes
FINAL PHASE removal of mysql_priv.h (Bye, bye my friend.) |
24 |
#include <drizzled/server_includes.h> |
575.4.7
by Monty Taylor
More header cleanup. |
25 |
|
549
by Monty Taylor
Took gettext.h out of header files. |
26 |
#include <drizzled/error.h> |
575.4.7
by Monty Taylor
More header cleanup. |
27 |
#include <drizzled/sql_parse.h> |
960.1.1
by Monty Taylor
First pass at scheduler plugin. |
28 |
#include <drizzled/scheduling.h> |
584.1.15
by Monty Taylor
The mega-patch from hell. Renamed sql_class to session (since that's what it is) and removed it and field and table from common_includes. |
29 |
#include <drizzled/session.h> |
873.2.10
by Monty Taylor
Added include to pick up extern "C" from header. |
30 |
#include <drizzled/connect.h> |
1
by brian
clean slate |
31 |
|
520.6.3
by Monty Taylor
Moved scheduler.h out of common_includes. |
32 |
|
1
by brian
clean slate |
33 |
/*
|
34 |
Thread handler for a connection
|
|
35 |
||
36 |
SYNOPSIS
|
|
37 |
handle_one_connection()
|
|
520.1.21
by Brian Aker
THD -> Session rename |
38 |
arg Connection object (Session)
|
1
by brian
clean slate |
39 |
|
40 |
IMPLEMENTATION
|
|
41 |
This function (normally) does the following:
|
|
42 |
- Initialize thread
|
|
520.1.21
by Brian Aker
THD -> Session rename |
43 |
- Initialize Session to be used with this thread
|
1
by brian
clean slate |
44 |
- Authenticate user
|
45 |
- Execute all queries sent on the connection
|
|
46 |
- Take connection down
|
|
47 |
- End thread / Handle next connection using thread from thread cache
|
|
48 |
*/
|
|
49 |
pthread_handler_t handle_one_connection(void *arg) |
|
50 |
{
|
|
960.1.1
by Monty Taylor
First pass at scheduler plugin. |
51 |
Session *session= static_cast<Session*>(arg); |
1
by brian
clean slate |
52 |
|
960.1.4
by Monty Taylor
Changed get_thread_scheduler to returning a reference. |
53 |
Scheduler &thread_scheduler= get_thread_scheduler(); |
54 |
if (thread_scheduler.init_new_connection_thread()) |
|
1
by brian
clean slate |
55 |
{
|
934.2.6
by Jay Pipes
This changeset removes a few more C functions from sql_connect.cc/connect.h |
56 |
session->disconnect(ER_OUT_OF_RESOURCES, true); |
1
by brian
clean slate |
57 |
statistic_increment(aborted_connects,&LOCK_status); |
960.1.4
by Monty Taylor
Changed get_thread_scheduler to returning a reference. |
58 |
thread_scheduler.end_thread(session,0); |
1
by brian
clean slate |
59 |
return 0; |
60 |
}
|
|
61 |
||
62 |
/*
|
|
63 |
handle_one_connection() is normally the only way a thread would
|
|
64 |
start and would always be on the very high end of the stack ,
|
|
65 |
therefore, the thread stack always starts at the address of the
|
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
66 |
first local variable of handle_one_connection, which is session. We
|
1
by brian
clean slate |
67 |
need to know the start of the stack so that we could check for
|
68 |
stack overruns.
|
|
69 |
*/
|
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
70 |
session->thread_stack= (char*) &session; |
934.2.6
by Jay Pipes
This changeset removes a few more C functions from sql_connect.cc/connect.h |
71 |
if (! session->initGlobals()) |
1
by brian
clean slate |
72 |
return 0; |
73 |
||
74 |
for (;;) |
|
75 |
{
|
|
934.2.4
by Jay Pipes
This changeset pulls check_user(), check_connection(), and login_connection() out of sql_connect.cc and makes them member methods of Session, where they belong. Also, made sure that functions that return a bool return true when it succeeds, and not false... |
76 |
if (! session->authenticate()) |
1
by brian
clean slate |
77 |
goto end_thread; |
78 |
||
934.2.6
by Jay Pipes
This changeset removes a few more C functions from sql_connect.cc/connect.h |
79 |
session->prepareForQueries(); |
1
by brian
clean slate |
80 |
|
971.3.19
by Eric Day
Finished first pass at Protocol cleanup, still some things to remove but they are a bit more involved. |
81 |
while (!session->protocol->haveError() && |
520.1.22
by Brian Aker
Second pass of thd cleanup |
82 |
!(session->killed == Session::KILL_CONNECTION)) |
1
by brian
clean slate |
83 |
{
|
934.2.8
by Jay Pipes
Refactors the do_command() function out of the sql_parse.cc stuff and implements it as a member method, executeStatement() on the Session object. |
84 |
if (! session->executeStatement()) |
85 |
break; |
|
1
by brian
clean slate |
86 |
}
|
934.2.8
by Jay Pipes
Refactors the do_command() function out of the sql_parse.cc stuff and implements it as a member method, executeStatement() on the Session object. |
87 |
|
1
by brian
clean slate |
88 |
end_thread: |
934.2.6
by Jay Pipes
This changeset removes a few more C functions from sql_connect.cc/connect.h |
89 |
session->disconnect(0, true); |
960.1.4
by Monty Taylor
Changed get_thread_scheduler to returning a reference. |
90 |
if (thread_scheduler.end_thread(session, 1)) |
1
by brian
clean slate |
91 |
return 0; // Probably no-threads |
92 |
||
93 |
/*
|
|
94 |
If end_thread() returns, we are either running with
|
|
95 |
thread-handler=no-threads or this thread has been schedule to
|
|
96 |
handle the next connection.
|
|
97 |
*/
|
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
98 |
session= current_session; |
99 |
session->thread_stack= (char*) &session; |
|
1
by brian
clean slate |
100 |
}
|
101 |
}
|