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-1335 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 29 struct scheduler_functions; 30 31 class CONNECT : public ilink { 32 public: 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 CONNECT()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 59 class THD; 60 typedef struct user_conn USER_CONN; 61 62 void init_max_user_conn(void); 63 void init_global_user_stats(void); 64 void init_global_table_stats(void); 65 void init_global_index_stats(void); 66 void init_global_client_stats(void); 67 void free_max_user_conn(void); 68 void free_global_user_stats(void); 69 void free_global_table_stats(void); 70 void free_global_index_stats(void); 71 void free_global_client_stats(void); 72 73 pthread_handler_t handle_one_connection(void *arg); 74 void do_handle_one_connection(CONNECT *connect); 75 bool init_new_connection_handler_thread(); 76 void reset_mqh(LEX_USER *lu, bool get_them); 77 bool check_mqh(THD *thd, uint check_command); 78 void time_out_user_resource_limits(THD *thd, USER_CONN *uc); 79 #ifndef NO_EMBEDDED_ACCESS_CHECKS 80 void decrease_user_connections(USER_CONN *uc); 81 #else 82 #define decrease_user_connections(X) do { } while(0) /* nothing */ 83 #endif 84 bool thd_init_client_charset(THD *thd, uint cs_number); 85 bool setup_connection_thread_globals(THD *thd); 86 bool thd_prepare_connection(THD *thd); 87 bool thd_is_connection_alive(THD *thd); 88 int 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 93 bool login_connection(THD *thd); 94 void prepare_new_connection_state(THD* thd); 95 void end_connection(THD *thd); 96 void update_global_user_stats(THD* thd, bool create_user, time_t now); 97 int get_or_create_user_conn(THD *thd, const char *user, 98 const char *host, const USER_RESOURCES *mqh); 99 int check_for_max_user_connections(THD *thd, USER_CONN *uc); 100 101 extern HASH global_user_stats; 102 extern HASH global_client_stats; 103 extern HASH global_table_stats; 104 extern HASH global_index_stats; 105 106 extern mysql_mutex_t LOCK_global_user_client_stats; 107 extern mysql_mutex_t LOCK_global_table_stats; 108 extern mysql_mutex_t LOCK_global_index_stats; 109 extern mysql_mutex_t LOCK_stats; 110 111 #endif /* SQL_CONNECT_INCLUDED */ 112