Class: PhusionPassenger::MessageClient
- Includes:
- Utils
- Defined in:
- lib/phusion_passenger/message_client.rb
Overview
A convenience class for communicating with MessageServer servers, for example the ApplicationPool server.
Instance Method Summary collapse
-
#backtraces ⇒ Object
BacktracesServer methods ###.
- #check_security_response ⇒ Object
- #close ⇒ Object
- #connected? ⇒ Boolean
-
#detach(detach_key) ⇒ Object
ApplicationPool::Server methods ###.
-
#initialize(username, password, address = "unix:#{Utils.passenger_tmpdir}/socket") ⇒ MessageClient
constructor
Connect to the given server.
-
#read ⇒ Object
Low level I/O methods ###.
- #read_scalar ⇒ Object
- #recv_io(klass = IO, negotiate = true) ⇒ Object
- #status ⇒ Object
- #write(*args) ⇒ Object
- #write_scalar(*args) ⇒ Object
- #xml ⇒ Object
Methods included from Utils
Constructor Details
#initialize(username, password, address = "unix:#{Utils.passenger_tmpdir}/socket") ⇒ MessageClient
Connect to the given server. By default it connects to the current generation’s helper server.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/phusion_passenger/message_client.rb', line 39 def initialize(username, password, address = "unix:#{Utils.passenger_tmpdir}/socket") @socket = connect_to_server(address) begin @channel = MessageChannel.new(@socket) result = @channel.read if result.nil? raise EOFError elsif result.size != 2 || result[0] != "version" raise IOError, "The message server didn't sent a valid version identifier" elsif result[1] != "1" raise IOError, "Unsupported message server protocol version #{result[1]}" end @channel.write_scalar(username) @channel.write_scalar(password) result = @channel.read if result.nil? raise EOFError elsif result[0] != "ok" raise SecurityError, result[0] end rescue Exception @socket.close raise end end |
Instance Method Details
#backtraces ⇒ Object
BacktracesServer methods ###
107 108 109 110 111 |
# File 'lib/phusion_passenger/message_client.rb', line 107 def backtraces write("backtraces") check_security_response return read_scalar end |
#check_security_response ⇒ Object
150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/phusion_passenger/message_client.rb', line 150 def check_security_response begin result = @channel.read rescue auto_disconnect raise end if result.nil? raise EOFError elsif result[0] != "Passed security" raise SecurityError, result[0] end end |
#close ⇒ Object
68 69 70 71 |
# File 'lib/phusion_passenger/message_client.rb', line 68 def close @socket.close if @socket @channel = @socket = nil end |
#connected? ⇒ Boolean
73 74 75 |
# File 'lib/phusion_passenger/message_client.rb', line 73 def connected? return !!@channel end |
#detach(detach_key) ⇒ Object
ApplicationPool::Server methods ###
79 80 81 82 83 84 85 86 87 88 |
# File 'lib/phusion_passenger/message_client.rb', line 79 def detach(detach_key) write("detach", detach_key) check_security_response result = read if result.nil? raise EOFError else return result.first == "true" end end |
#read ⇒ Object
Low level I/O methods ###
115 116 117 118 119 120 |
# File 'lib/phusion_passenger/message_client.rb', line 115 def read return @channel.read rescue auto_disconnect raise end |
#read_scalar ⇒ Object
136 137 138 139 140 141 |
# File 'lib/phusion_passenger/message_client.rb', line 136 def read_scalar return @channel.read_scalar rescue auto_disconnect raise end |
#recv_io(klass = IO, negotiate = true) ⇒ Object
143 144 145 146 147 148 |
# File 'lib/phusion_passenger/message_client.rb', line 143 def recv_io(klass = IO, negotiate = true) return @channel.recv_io(klass, negotiate) rescue auto_disconnect raise end |
#status ⇒ Object
90 91 92 93 94 95 96 97 |
# File 'lib/phusion_passenger/message_client.rb', line 90 def status write("inspect") check_security_response return read_scalar rescue auto_disconnect raise end |
#write(*args) ⇒ Object
122 123 124 125 126 127 |
# File 'lib/phusion_passenger/message_client.rb', line 122 def write(*args) @channel.write(*args) rescue auto_disconnect raise end |
#write_scalar(*args) ⇒ Object
129 130 131 132 133 134 |
# File 'lib/phusion_passenger/message_client.rb', line 129 def write_scalar(*args) @channel.write_scalar(*args) rescue auto_disconnect raise end |
#xml ⇒ Object
99 100 101 102 103 |
# File 'lib/phusion_passenger/message_client.rb', line 99 def xml write("toXml", true) check_security_response return read_scalar end |