1/* Copyright (c) 2006, 2011, Oracle and/or its affiliates. All rights reserved.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; version 2 of the License.
6
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 GNU General Public License for more details.
11
12 You should have received a copy of the GNU General Public License
13 along with this program; if not, write to the Free Software
14 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
15
16#ifndef SQL_CONNECT_INCLUDED
17#define SQL_CONNECT_INCLUDED
18
19#include <my_sys.h> /* pthread_handler_t */
20#include "mysql_com.h" /* enum_server_command */
21#include "structs.h"
22#include <mysql/psi/mysql_socket.h>
23#include <hash.h>
24
25/*
26 Object to hold connect information to be given to the newly created thread
27*/
28
29struct scheduler_functions;
30
31class CONNECT : public ilink {
32public:
33 /* To be copied to THD */
34 Vio *vio; /* Copied to THD with my_net_init() */
35 const char *host;
36 scheduler_functions *scheduler;
37 my_thread_id thread_id;
38 pthread_t real_id;
39 bool extra_port;
40
41 /* Own variables */
42 bool thread_count_incremented;
43 ulonglong prior_thr_create_utime;
44
45 CONNECT()
46 :vio(0), host(0), scheduler(thread_scheduler), thread_id(0), real_id(0),
47 extra_port(0),
48 thread_count_incremented(0), prior_thr_create_utime(0)
49 {
50 };
51 ~CONNECT();
52 void close_and_delete();
53 void close_with_error(uint sql_errno,
54 const char *message, uint close_error);
55 THD *create_thd(THD *thd);
56};
57
58
59class THD;
60typedef struct user_conn USER_CONN;
61
62void init_max_user_conn(void);
63void init_global_user_stats(void);
64void init_global_table_stats(void);
65void init_global_index_stats(void);
66void init_global_client_stats(void);
67void free_max_user_conn(void);
68void free_global_user_stats(void);
69void free_global_table_stats(void);
70void free_global_index_stats(void);
71void free_global_client_stats(void);
72
73pthread_handler_t handle_one_connection(void *arg);
74void do_handle_one_connection(CONNECT *connect);
75bool init_new_connection_handler_thread();
76void reset_mqh(LEX_USER *lu, bool get_them);
77bool check_mqh(THD *thd, uint check_command);
78void time_out_user_resource_limits(THD *thd, USER_CONN *uc);
79#ifndef NO_EMBEDDED_ACCESS_CHECKS
80void decrease_user_connections(USER_CONN *uc);
81#else
82#define decrease_user_connections(X) do { } while(0) /* nothing */
83#endif
84bool thd_init_client_charset(THD *thd, uint cs_number);
85bool setup_connection_thread_globals(THD *thd);
86bool thd_prepare_connection(THD *thd);
87bool thd_is_connection_alive(THD *thd);
88int thd_set_peer_addr(THD *thd, sockaddr_storage *addr,
89 const char *ip, uint port,
90 bool check_proxy_networks,
91 uint *host_errors);
92
93bool login_connection(THD *thd);
94void prepare_new_connection_state(THD* thd);
95void end_connection(THD *thd);
96void update_global_user_stats(THD* thd, bool create_user, time_t now);
97int get_or_create_user_conn(THD *thd, const char *user,
98 const char *host, const USER_RESOURCES *mqh);
99int check_for_max_user_connections(THD *thd, USER_CONN *uc);
100
101extern HASH global_user_stats;
102extern HASH global_client_stats;
103extern HASH global_table_stats;
104extern HASH global_index_stats;
105
106extern mysql_mutex_t LOCK_global_user_client_stats;
107extern mysql_mutex_t LOCK_global_table_stats;
108extern mysql_mutex_t LOCK_global_index_stats;
109extern mysql_mutex_t LOCK_stats;
110
111#endif /* SQL_CONNECT_INCLUDED */
112