~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/session.cc

  • Committer: Jay Pipes
  • Date: 2009-03-16 02:52:26 UTC
  • mto: This revision was merged to the branch mainline in revision 941.
  • Revision ID: jpipes@serialcoder-20090316025226-bs0fprh0cxony7z9
This changeset removes a few more  C functions from sql_connect.cc/connect.h
and houses them as member methods of the session object.  Added documentation
where I could and cleaned up the code style.

Show diffs side-by-side

added added

removed removed

Lines of Context:
855
855
  Remember the location of thread info, the structure needed for
856
856
  sql_alloc() and the structure for the net buffer
857
857
*/
858
 
 
859
858
bool Session::store_globals()
860
859
{
861
860
  /*
883
882
  return 0;
884
883
}
885
884
 
 
885
void Session::prepareForQueries()
 
886
{
 
887
  if (variables.max_join_size == HA_POS_ERROR)
 
888
    options |= OPTION_BIG_SELECTS;
 
889
  if (client_capabilities & CLIENT_COMPRESS)
 
890
    net.compress= true;
 
891
 
 
892
  version= refresh_version;
 
893
  set_proc_info(0);
 
894
  command= COM_SLEEP;
 
895
  set_time();
 
896
  init_for_queries();
 
897
 
 
898
  /* In the past this would only run of the user did not have SUPER_ACL */
 
899
  if (sys_init_connect.value_length)
 
900
  {
 
901
    execute_init_command(this, &sys_init_connect, &LOCK_sys_init_connect);
 
902
    if (is_error())
 
903
    {
 
904
      Security_context *sctx= &security_ctx;
 
905
      killed= Session::KILL_CONNECTION;
 
906
      errmsg_printf(ERRMSG_LVL_WARN
 
907
                  , ER(ER_NEW_ABORTING_CONNECTION)
 
908
                  , thread_id
 
909
                  , (db ? db : "unconnected")
 
910
                  , sctx->user.empty() == false ? sctx->user.c_str() : "unauthenticated"
 
911
                  , sctx->ip.c_str(), "init_connect command failed");
 
912
      errmsg_printf(ERRMSG_LVL_WARN, "%s", main_da.message());
 
913
    }
 
914
    set_proc_info(0);
 
915
    set_time();
 
916
    init_for_queries();
 
917
  }
 
918
}
 
919
 
 
920
bool Session::initGlobals()
 
921
{
 
922
  if (store_globals())
 
923
  {
 
924
    disconnect(ER_OUT_OF_RESOURCES, true);
 
925
    statistic_increment(aborted_connects, &LOCK_status);
 
926
    thread_scheduler.end_thread(this, 0);
 
927
    return false;
 
928
  }
 
929
  return true;
 
930
}
 
931
 
886
932
bool Session::authenticate()
887
933
{
888
934
  /* Use "connect_timeout" value during connection phase */
2125
2171
{
2126
2172
  Session *session=current_session;
2127
2173
  if (likely(session != 0))
2128
 
  { /* current_session==0 when close_connection() calls net_send_error() */
 
2174
  { /* current_session==0 when disconnect() calls net_send_error() */
2129
2175
    session->status_var.bytes_sent+= length;
2130
2176
  }
2131
2177
}
2484
2530
  };
2485
2531
}
2486
2532
 
2487
 
/**
2488
 
  Close a connection.
2489
 
 
2490
 
  @param session                Thread handle
2491
 
  @param errcode        Error code to print to console
2492
 
  @param should_lock 1 if we have have to lock LOCK_thread_count
2493
 
 
2494
 
  @note
2495
 
    For the connection that is doing shutdown, this is called twice
2496
 
*/
2497
 
void Session::close_connection(uint32_t errcode, bool should_lock)
 
2533
void Session::disconnect(uint32_t errcode, bool should_lock)
2498
2534
{
 
2535
  /* Allow any plugins to cleanup their session variables */
 
2536
  plugin_sessionvar_cleanup(this);
 
2537
 
 
2538
  /* If necessary, log any aborted or unauthorized connections */
 
2539
  if (killed || (net.error && net.vio != 0))
 
2540
    statistic_increment(aborted_threads, &LOCK_status);
 
2541
 
 
2542
  if (net.error && net.vio != 0)
 
2543
  {
 
2544
    if (! killed && variables.log_warnings > 1)
 
2545
    {
 
2546
      Security_context *sctx= &security_ctx;
 
2547
 
 
2548
      errmsg_printf(ERRMSG_LVL_WARN, ER(ER_NEW_ABORTING_CONNECTION)
 
2549
                  , thread_id
 
2550
                  , (db ? db : "unconnected")
 
2551
                  , sctx->user.empty() == false ? sctx->user.c_str() : "unauthenticated"
 
2552
                  , sctx->ip.c_str()
 
2553
                  , (main_da.is_error() ? main_da.message() : ER(ER_UNKNOWN_ERROR)));
 
2554
    }
 
2555
  }
 
2556
 
 
2557
  /* Close out our connection to the client */
2499
2558
  st_vio *vio;
2500
2559
  if (should_lock)
2501
2560
    (void) pthread_mutex_lock(&LOCK_thread_count);
2510
2569
    (void) pthread_mutex_unlock(&LOCK_thread_count);
2511
2570
}
2512
2571
 
2513
 
 
2514
 
 
2515
2572
/**
2516
2573
 Reset Session part responsible for command processing state.
2517
2574