Class: Net::TNS::Client
- Inherits:
-
Object
- Object
- Net::TNS::Client
- Defined in:
- lib/net/tns/client.rb
Class Method Summary collapse
- .get_status(opts = {}) ⇒ Object
- .get_version(opts = {}) ⇒ Object
-
.parse_vsnnum(vsnnum_string) ⇒ Object
Parse the “VSNNUM” component of certain TNS listener responses, which contains an encoded form of the version number.
- .ping?(opts = {}) ⇒ Boolean
Class Method Details
.get_status(opts = {}) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/net/tns/client.rb', line 46 def self.get_status(opts={}) begin conn = Connection.new(opts) conn.open_socket() request = ConnectPacket.new(:data => "(CONNECT_DATA=(COMMAND=STATUS)(VERSION=186647552))") status_response_raw = "" begin response = conn.send_and_receive( request ) rescue EOFError # The first packet sent is an Accept with an unknown structure. # Attempting to parse it as an Accept results in an EOFError, due to # a data length that is greater than the available data. end response = conn.send_and_receive(ResendPacket.new()) status_response_raw += response.data # Successful responses are typically spread across multiple Data packets. while ( response = conn.receive_tns_packet() ) break unless response.is_a?(DataPacket) break if response.flags == 0x0040 status_response_raw += response.data end return status_response_raw ensure conn.close_socket() unless conn.nil? end end |
.get_version(opts = {}) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/net/tns/client.rb', line 20 def self.get_version(opts={}) begin conn = Connection.new(opts) conn.open_socket() request = ConnectPacket.new(:data => "(CONNECT_DATA=(COMMAND=VERSION))") response = conn.send_and_receive( request ) raise Exceptions::ProtocolException.new("Expected AcceptPacket in response (got #{response.class})") unless response.is_a?(AcceptPacket) version_data = response.data rescue Exceptions::RefuseMessageReceived => refuse_err version_data = refuse_err. ensure conn.close_socket() unless conn.nil? end return nil if version_data.nil? if ( version_match = version_data.match( /Version ((?:\d+.)+\d+)/ ) ) then return version_match[1] # If that didn't work, see if we got an encoded version number elsif ( version_match = version_data.match( /\(VSNNUM=(\d+)\)/ ) ) then return parse_vsnnum(version_match[1]) end end |
.parse_vsnnum(vsnnum_string) ⇒ Object
Parse the “VSNNUM” component of certain TNS listener responses, which contains an encoded form of the version number.
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/net/tns/client.rb', line 77 def self.parse_vsnnum(vsnnum_string) # The VSNNUM is a really insane way of encoding the version number. It # is a decimal number (e.g. 169869568) that, in hex (e.g. A200100), # is a weird representation of the dotted version # (e.g. 169869568 -> A200100 -> A.2.0.01.00 -> A.2.0.1.0 -> 10.2.0.1.0). raise ArgumentError unless vsnnum_string.is_a?(String) vsnnum_decimal = vsnnum_string.to_i version_components = [] version_components << (( vsnnum_decimal >> 24 ) & 0xF) version_components << (( vsnnum_decimal >> 20 ) & 0xF) version_components << (( vsnnum_decimal >> 16 ) & 0xF) version_components << (( vsnnum_decimal >> 8 ) & 0xFF) version_components << (( vsnnum_decimal >> 0 ) & 0xFF) return version_components.join('.') end |
.ping?(opts = {}) ⇒ Boolean
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/net/tns/client.rb', line 4 def self.ping?(opts={}) begin conn = Connection.new(opts) conn.open_socket() request = ConnectPacket.new(:data => "(CONNECT_DATA=(COMMAND=ping))") conn.send_and_receive( request ) return true rescue Exceptions::ConnectionClosed return false rescue Exceptions::TNSException return true ensure conn.close_socket() unless conn.nil? end end |