1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008 Sun Microsystems
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.
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.
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
22
Functions to autenticate and handle reqests for a connection
24
#include <drizzled/server_includes.h>
26
#include <drizzled/error.h>
27
#include <drizzled/sql_parse.h>
28
#include <drizzled/scheduling.h>
29
#include <drizzled/session.h>
30
#include <drizzled/connect.h>
34
Thread handler for a connection
37
handle_one_connection()
38
arg Connection object (Session)
41
This function (normally) does the following:
43
- Initialize Session to be used with this thread
45
- Execute all queries sent on the connection
46
- Take connection down
47
- End thread / Handle next connection using thread from thread cache
49
pthread_handler_t handle_one_connection(void *arg)
51
Session *session= static_cast<Session*>(arg);
53
Scheduler &thread_scheduler= get_thread_scheduler();
54
if (thread_scheduler.init_new_connection_thread())
56
session->disconnect(ER_OUT_OF_RESOURCES, true);
57
statistic_increment(aborted_connects,&LOCK_status);
58
thread_scheduler.end_thread(session,0);
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
66
first local variable of handle_one_connection, which is session. We
67
need to know the start of the stack so that we could check for
70
session->thread_stack= (char*) &session;
71
if (! session->initGlobals())
76
if (! session->authenticate())
79
session->prepareForQueries();
81
while (!session->protocol->haveError() &&
82
!(session->killed == Session::KILL_CONNECTION))
84
if (! session->executeStatement())
89
session->disconnect(0, true);
90
if (thread_scheduler.end_thread(session, 1))
91
return 0; // Probably no-threads
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.
98
session= current_session;
99
session->thread_stack= (char*) &session;