|
63 | 63 | #include "sql/mysqld.h" // global_system_variables ...
|
64 | 64 | #include "sql/mysqld_thd_manager.h" // Global_THD_manager
|
65 | 65 | #include "sql/parse_location.h"
|
| 66 | +#include "sql/protocol.h" |
| 67 | +#include "sql/protocol_classic.h" |
66 | 68 | #include "sql/psi_memory_key.h"
|
67 | 69 | #include "sql/query_result.h"
|
68 | 70 | #include "sql/rpl_rli.h" // Relay_log_info
|
@@ -364,6 +366,8 @@ THD::THD(bool enable_plugins)
|
364 | 366 | m_current_query_partial_plans(0),
|
365 | 367 | m_main_security_ctx(this),
|
366 | 368 | m_security_ctx(&m_main_security_ctx),
|
| 369 | + protocol_text(new Protocol_text), |
| 370 | + protocol_binary(new Protocol_binary), |
367 | 371 | query_plan(this),
|
368 | 372 | m_current_stage_key(0),
|
369 | 373 | current_mutex(NULL),
|
@@ -519,10 +523,10 @@ THD::THD(bool enable_plugins)
|
519 | 523 | sp_func_cache = NULL;
|
520 | 524 |
|
521 | 525 | /* Protocol */
|
522 |
| - m_protocol = &protocol_text; // Default protocol |
523 |
| - protocol_text.init(this); |
524 |
| - protocol_binary.init(this); |
525 |
| - protocol_text.set_client_capabilities(0); // minimalistic client |
| 526 | + m_protocol = protocol_text.get(); // Default protocol |
| 527 | + protocol_text->init(this); |
| 528 | + protocol_binary->init(this); |
| 529 | + protocol_text->set_client_capabilities(0); // minimalistic client |
526 | 530 |
|
527 | 531 | /*
|
528 | 532 | Make sure thr_lock_info_init() is called for threads which do not get
|
@@ -2759,3 +2763,36 @@ void THD::cleanup_after_parse_error() {
|
2759 | 2763 | }
|
2760 | 2764 | }
|
2761 | 2765 | }
|
| 2766 | + |
| 2767 | +bool THD::is_classic_protocol() const { |
| 2768 | + return get_protocol()->type() == Protocol::PROTOCOL_BINARY || |
| 2769 | + get_protocol()->type() == Protocol::PROTOCOL_TEXT; |
| 2770 | +} |
| 2771 | + |
| 2772 | +bool THD::is_connected() { |
| 2773 | + /* |
| 2774 | + All system threads (e.g., the slave IO thread) are connected but |
| 2775 | + not using vio. So this function always returns true for all |
| 2776 | + system threads. |
| 2777 | + */ |
| 2778 | + if (system_thread) return true; |
| 2779 | + |
| 2780 | + if (is_classic_protocol()) |
| 2781 | + return get_protocol()->connection_alive() && |
| 2782 | + vio_is_connected(get_protocol_classic()->get_vio()); |
| 2783 | + |
| 2784 | + return get_protocol()->connection_alive(); |
| 2785 | +} |
| 2786 | + |
| 2787 | +void THD::push_protocol(Protocol *protocol) { |
| 2788 | + DBUG_ASSERT(m_protocol != nullptr); |
| 2789 | + DBUG_ASSERT(protocol != nullptr); |
| 2790 | + m_protocol->push_protocol(protocol); |
| 2791 | + m_protocol = protocol; |
| 2792 | +} |
| 2793 | + |
| 2794 | +void THD::pop_protocol() { |
| 2795 | + DBUG_ASSERT(m_protocol != nullptr); |
| 2796 | + m_protocol = m_protocol->pop_protocol(); |
| 2797 | + DBUG_ASSERT(m_protocol != nullptr); |
| 2798 | +} |
0 commit comments