~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_connect.cc

  • Committer: Brian Aker
  • Date: 2009-03-25 18:24:15 UTC
  • mto: This revision was merged to the branch mainline in revision 963.
  • Revision ID: brian@tangent.org-20090325182415-opf2720c1hidtfgk
Cut down on shutdown loop of plugins (cutting stuff out in order to simplify
old lock system).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 */
 
19
 
 
20
 
 
21
/*
 
22
  Functions to autenticate and handle reqests for a connection
 
23
*/
 
24
#include <drizzled/server_includes.h>
 
25
 
 
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>
 
31
 
 
32
 
 
33
/*
 
34
  Initialize connection threads
 
35
*/
 
36
bool init_new_connection_handler_thread()
 
37
{
 
38
  if (my_thread_init())
 
39
    return 1;
 
40
  return 0;
 
41
}
 
42
 
 
43
/*
 
44
  Thread handler for a connection
 
45
 
 
46
  SYNOPSIS
 
47
    handle_one_connection()
 
48
    arg         Connection object (Session)
 
49
 
 
50
  IMPLEMENTATION
 
51
    This function (normally) does the following:
 
52
    - Initialize thread
 
53
    - Initialize Session to be used with this thread
 
54
    - Authenticate user
 
55
    - Execute all queries sent on the connection
 
56
    - Take connection down
 
57
    - End thread  / Handle next connection using thread from thread cache
 
58
*/
 
59
pthread_handler_t handle_one_connection(void *arg)
 
60
{
 
61
  Session *session= static_cast<Session*>(arg);
 
62
  uint32_t launch_time= (uint32_t) ((session->thr_create_utime= my_micro_time()) -
 
63
                              session->connect_utime);
 
64
 
 
65
  Scheduler &thread_scheduler= get_thread_scheduler();
 
66
  if (thread_scheduler.init_new_connection_thread())
 
67
  {
 
68
    session->disconnect(ER_OUT_OF_RESOURCES, true);
 
69
    statistic_increment(aborted_connects,&LOCK_status);
 
70
    thread_scheduler.end_thread(session,0);
 
71
    return 0;
 
72
  }
 
73
  if (launch_time >= slow_launch_time*1000000L)
 
74
    statistic_increment(slow_launch_threads,&LOCK_status);
 
75
 
 
76
  /*
 
77
    handle_one_connection() is normally the only way a thread would
 
78
    start and would always be on the very high end of the stack ,
 
79
    therefore, the thread stack always starts at the address of the
 
80
    first local variable of handle_one_connection, which is session. We
 
81
    need to know the start of the stack so that we could check for
 
82
    stack overruns.
 
83
  */
 
84
  session->thread_stack= (char*) &session;
 
85
  if (! session->initGlobals())
 
86
    return 0;
 
87
 
 
88
  for (;;)
 
89
  {
 
90
    NET *net= &session->net;
 
91
 
 
92
    if (! session->authenticate())
 
93
      goto end_thread;
 
94
 
 
95
    session->prepareForQueries();
 
96
 
 
97
    while (!net->error && net->vio != 0 &&
 
98
           !(session->killed == Session::KILL_CONNECTION))
 
99
    {
 
100
      if (! session->executeStatement())
 
101
              break;
 
102
    }
 
103
 
 
104
end_thread:
 
105
    session->disconnect(0, true);
 
106
    if (thread_scheduler.end_thread(session, 1))
 
107
      return 0;                                 // Probably no-threads
 
108
 
 
109
    /*
 
110
      If end_thread() returns, we are either running with
 
111
      thread-handler=no-threads or this thread has been schedule to
 
112
      handle the next connection.
 
113
    */
 
114
    session= current_session;
 
115
    session->thread_stack= (char*) &session;
 
116
  }
 
117
}