]> granicus.if.org Git - php/commitdiff
MNDR:
authorAndrey Hristov <andrey@php.net>
Fri, 30 Oct 2015 12:44:09 +0000 (13:44 +0100)
committerAndrey Hristov <andrey@php.net>
Thu, 12 Nov 2015 15:19:16 +0000 (16:19 +0100)
- make the connection state a class

ext/mysqlnd/mysqlnd.c
ext/mysqlnd/mysqlnd_driver.c
ext/mysqlnd/mysqlnd_priv.h
ext/mysqlnd/mysqlnd_structs.h

index 31a4e30a909f258ceb995877777678fb436cfe7f..92e85b5fff753a70f0e6be3f3aecae22870e9e32 100644 (file)
@@ -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),
index d0c2779d96364ee9509fa919ccf3716076d706f5..cda731b934f44f580c5733c3bfe7e110e3ba87e7 100644 (file)
@@ -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);
index 42a139ef0ba790b875f49192e5859caf85da668f..f5e05d41d406778f929ff644b0bc04830f356211 100644 (file)
@@ -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);
index 0367bb8ae7e7cd26a7b35337844d87ceb009a948..e099c1bea2210ab92820605387aaad86c0f2803f 100644 (file)
@@ -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;