From 109dc08ffde2c9ec6e70f5d85f6ca057128a4135 Mon Sep 17 00:00:00 2001 From: Andrey Hristov Date: Fri, 30 Oct 2015 13:44:09 +0100 Subject: [PATCH] MNDR: - make the connection state a class --- ext/mysqlnd/mysqlnd.c | 70 ++++++++++++++++++++++------------- ext/mysqlnd/mysqlnd_driver.c | 4 +- ext/mysqlnd/mysqlnd_priv.h | 6 ++- ext/mysqlnd/mysqlnd_structs.h | 30 ++++++++++----- 4 files changed, 71 insertions(+), 39 deletions(-) diff --git a/ext/mysqlnd/mysqlnd.c b/ext/mysqlnd/mysqlnd.c index 31a4e30a90..92e85b5fff 100644 --- a/ext/mysqlnd/mysqlnd.c +++ b/ext/mysqlnd/mysqlnd.c @@ -152,7 +152,8 @@ MYSQLND_CLASS_METHODS_START(mysqlnd_error_info) MYSQLND_CLASS_METHODS_END; -/* {{{ mysqlnd_upsert_status_init */ + +/* {{{ mysqlnd_error_info_init */ enum_func_status mysqlnd_error_info_init(MYSQLND_ERROR_INFO * const info, zend_bool persistent) { @@ -170,6 +171,48 @@ mysqlnd_error_info_init(MYSQLND_ERROR_INFO * const info, zend_bool persistent) /* }}} */ + + +/* {{{ mysqlnd_connection_state::get */ +static enum mysqlnd_connection_state +MYSQLND_METHOD(mysqlnd_connection_state, get)(const struct st_mysqlnd_connection_state * const state_struct) +{ + DBG_ENTER("mysqlnd_connection_state::get") + DBG_RETURN(state_struct->state); +} +/* }}} */ + + +/* {{{ mysqlnd_connection_state::set */ +static void +MYSQLND_METHOD(mysqlnd_connection_state, set)(struct st_mysqlnd_connection_state * const state_struct, enum mysqlnd_connection_state state) +{ + DBG_ENTER("mysqlnd_connection_state::set") + DBG_INF_FMT("New state=%u", state); + state_struct->state = state; + DBG_VOID_RETURN; +} +/* }}} */ + + +MYSQLND_CLASS_METHODS_START(mysqlnd_connection_state) + MYSQLND_METHOD(mysqlnd_connection_state, get), + MYSQLND_METHOD(mysqlnd_connection_state, set), +MYSQLND_CLASS_METHODS_END; + + +/* {{{ mysqlnd_upsert_status_init */ +void +mysqlnd_connection_state_init(struct st_mysqlnd_connection_state * const state) +{ + DBG_ENTER("mysqlnd_error_info_init") + state->m = &MYSQLND_CLASS_METHOD_TABLE_NAME(mysqlnd_connection_state); + state->state = CONN_ALLOCED; + DBG_VOID_RETURN; +} +/* }}} */ + + /* {{{ mysqlnd_conn_data::free_options */ static void MYSQLND_METHOD(mysqlnd_conn_data, free_options)(MYSQLND_CONN_DATA * conn) @@ -1980,28 +2023,6 @@ MYSQLND_METHOD_PRIVATE(mysqlnd_conn_data, free_reference)(MYSQLND_CONN_DATA * co /* }}} */ -/* {{{ mysqlnd_conn_data::get_state */ -static enum mysqlnd_connection_state -MYSQLND_METHOD_PRIVATE(mysqlnd_conn_data, get_state)(const MYSQLND_CONN_DATA * const conn) -{ - DBG_ENTER("mysqlnd_conn_data::get_state"); - DBG_RETURN(conn->state); -} -/* }}} */ - - -/* {{{ mysqlnd_conn_data::set_state */ -static void -MYSQLND_METHOD_PRIVATE(mysqlnd_conn_data, set_state)(MYSQLND_CONN_DATA * const conn, enum mysqlnd_connection_state new_state) -{ - DBG_ENTER("mysqlnd_conn_data::set_state"); - DBG_INF_FMT("New state=%u", new_state); - conn->state = new_state; - DBG_VOID_RETURN; -} -/* }}} */ - - /* {{{ mysqlnd_conn_data::field_count */ static unsigned int MYSQLND_METHOD(mysqlnd_conn_data, field_count)(const MYSQLND_CONN_DATA * const conn) @@ -3029,10 +3050,7 @@ MYSQLND_CLASS_METHODS_START(mysqlnd_conn_data) MYSQLND_METHOD_PRIVATE(mysqlnd_conn_data, get_reference), MYSQLND_METHOD_PRIVATE(mysqlnd_conn_data, free_reference), - MYSQLND_METHOD_PRIVATE(mysqlnd_conn_data, get_state), - MYSQLND_METHOD_PRIVATE(mysqlnd_conn_data, set_state), -// MYSQLND_METHOD(mysqlnd_conn_data, send_command_do_request), MYSQLND_METHOD(mysqlnd_conn_data, send_command_handle_response), MYSQLND_METHOD(mysqlnd_conn_data, restart_psession), MYSQLND_METHOD(mysqlnd_conn_data, end_psession), diff --git a/ext/mysqlnd/mysqlnd_driver.c b/ext/mysqlnd/mysqlnd_driver.c index d0c2779d96..cda731b934 100644 --- a/ext/mysqlnd/mysqlnd_driver.c +++ b/ext/mysqlnd/mysqlnd_driver.c @@ -132,7 +132,9 @@ MYSQLND_METHOD(mysqlnd_object_factory, get_connection)(struct st_mysqlnd_object_ data->persistent = persistent; data->m = mysqlnd_conn_data_get_methods(); data->object_factory = *factory; - CONN_SET_STATE(data, CONN_ALLOCED); + + mysqlnd_connection_state_init(&data->state); + data->m->get_reference(data); mysqlnd_stats_init(&data->stats, STAT_LAST, persistent); diff --git a/ext/mysqlnd/mysqlnd_priv.h b/ext/mysqlnd/mysqlnd_priv.h index 42a139ef0b..f5e05d41d4 100644 --- a/ext/mysqlnd/mysqlnd_priv.h +++ b/ext/mysqlnd/mysqlnd_priv.h @@ -111,8 +111,10 @@ enum_func_status mysqlnd_error_info_init(MYSQLND_ERROR_INFO * const info, zend_b #define SET_OOM_ERROR(info) SET_CLIENT_ERROR((info), CR_OUT_OF_MEMORY, UNKNOWN_SQLSTATE, mysqlnd_out_of_memory) #define COPY_CLIENT_ERROR(dest, source) SET_CLIENT_ERROR((dest), (source).error_no, (source).sqlstate, (source).error) -#define CONN_GET_STATE(c) (c)->m->get_state((c)) -#define CONN_SET_STATE(c, s) (c)->m->set_state((c), (s)) +#define CONN_GET_STATE(c) (c)->state.m->get(&(c)->state) +#define CONN_SET_STATE(c, s) (c)->state.m->set(&(c)->state, (s)) + +void mysqlnd_connection_state_init(struct st_mysqlnd_connection_state * const state); /* PS stuff */ typedef void (*ps_field_fetch_func)(zval * zv, const MYSQLND_FIELD * const field, unsigned int pack_len, zend_uchar ** row); diff --git a/ext/mysqlnd/mysqlnd_structs.h b/ext/mysqlnd/mysqlnd_structs.h index 0367bb8ae7..e099c1bea2 100644 --- a/ext/mysqlnd/mysqlnd_structs.h +++ b/ext/mysqlnd/mysqlnd_structs.h @@ -500,8 +500,6 @@ typedef enum_func_status (*func_mysqlnd_conn_data__query_read_result_set_header) typedef MYSQLND_CONN_DATA * (*func_mysqlnd_conn_data__get_reference)(MYSQLND_CONN_DATA * const conn); typedef enum_func_status (*func_mysqlnd_conn_data__free_reference)(MYSQLND_CONN_DATA * const conn); -typedef enum mysqlnd_connection_state (*func_mysqlnd_conn_data__get_state)(const MYSQLND_CONN_DATA * const conn); -typedef void (*func_mysqlnd_conn_data__set_state)(MYSQLND_CONN_DATA * const conn, enum mysqlnd_connection_state new_state); typedef enum_func_status (*func_mysqlnd_conn_data__send_command_do_request)(MYSQLND_CONN_DATA * const conn, const enum php_mysqlnd_server_command command, const zend_uchar * const arg, const size_t arg_len, const zend_bool silent, const zend_bool ignore_upsert_status); typedef enum_func_status (*func_mysqlnd_conn_data__send_command_handle_response)(MYSQLND_CONN_DATA * const conn, const enum mysqlnd_packet_type ok_packet, const zend_bool silent, const enum php_mysqlnd_server_command command, const zend_bool ignore_upsert_status); @@ -595,10 +593,7 @@ MYSQLND_CLASS_METHODS_TYPE(mysqlnd_conn_data) func_mysqlnd_conn_data__get_reference get_reference; func_mysqlnd_conn_data__free_reference free_reference; - func_mysqlnd_conn_data__get_state get_state; - func_mysqlnd_conn_data__set_state set_state; -// func_mysqlnd_conn_data__send_command_do_request send_command_do_request; func_mysqlnd_conn_data__send_command_handle_response send_command_handle_response; func_mysqlnd_conn_data__restart_psession restart_psession; @@ -936,6 +931,25 @@ struct st_mysqlnd_protocol_command typedef struct st_mysqlnd_protocol_command * (*func_mysqlnd__command_factory)(enum php_mysqlnd_server_command command, ...); + +struct st_mysqlnd_connection_state; +typedef enum mysqlnd_connection_state (*func_mysqlnd_connection_state__get)(const struct st_mysqlnd_connection_state * const state_struct); +typedef void (*func_mysqlnd_connection_state__set)(struct st_mysqlnd_connection_state * const state_struct, enum mysqlnd_connection_state state); + + +MYSQLND_CLASS_METHODS_TYPE(mysqlnd_connection_state) +{ + func_mysqlnd_connection_state__get get; + func_mysqlnd_connection_state__set set; +}; + +struct st_mysqlnd_connection_state +{ + enum mysqlnd_connection_state state; + + MYSQLND_CLASS_METHODS_TYPE(mysqlnd_connection_state) *m; +}; + struct st_mysqlnd_connection_data { /* Operation related */ @@ -978,11 +992,7 @@ struct st_mysqlnd_connection_data MYSQLND_ERROR_INFO * error_info; MYSQLND_ERROR_INFO error_info_impl; - /* - To prevent queries during unbuffered fetches. Also to - mark the connection as destroyed for garbage collection. - */ - enum mysqlnd_connection_state state; + struct st_mysqlnd_connection_state state; enum_mysqlnd_query_type last_query_type; /* Temporary storage between query and (use|store)_result() call */ MYSQLND_RES *current_result; -- 2.40.0