Class: NoSE::Proxy::MysqlProxy
- Defined in:
- lib/nose/proxy/mysql.rb
Overview
A proxy which speaks the MySQL protocol and executes queries
Instance Attribute Summary
Attributes inherited from ProxyBase
Instance Method Summary collapse
-
#handle_connection(socket) ⇒ Object
Authenticate the client and process queries.
-
#initialize(*args) ⇒ MysqlProxy
constructor
A new instance of MysqlProxy.
-
#remove_connection(socket) ⇒ Object
Remove the state of the socket.
Methods inherited from ProxyBase
Constructor Details
#initialize(*args) ⇒ MysqlProxy
Returns a new instance of MysqlProxy.
9 10 11 12 13 14 |
# File 'lib/nose/proxy/mysql.rb', line 9 def initialize(*args) super # Initialize a hash for the state of sockets @state = {} end |
Instance Method Details
#handle_connection(socket) ⇒ Object
Authenticate the client and process queries
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/nose/proxy/mysql.rb', line 17 def handle_connection(socket) return authenticate socket if @state[socket].nil? # Retrieve the saved state of the socket protocol = @state[socket] begin protocol.process_command(&method(:process_query)) rescue ::Mysql::ClientError::ServerGoneError # Ensure the socket is closed and remove the state remove_connection socket return false end # Keep this socket around true end |
#remove_connection(socket) ⇒ Object
Remove the state of the socket
36 37 38 39 |
# File 'lib/nose/proxy/mysql.rb', line 36 def remove_connection(socket) socket.close @state.delete socket end |