class Eye::Client
Constants
- SIGN
Attributes
socket_path[R]
Public Class Methods
new(socket_path, type = :old)
click to toggle source
# File lib/eye/client.rb, line 8 def initialize(socket_path, type = :old) @socket_path = socket_path @type = type end
Public Instance Methods
execute(h = {})
click to toggle source
# File lib/eye/client.rb, line 15 def execute(h = {}) payload = if @type == :old Marshal.dump([h[:command], *h[:args]]) # TODO: remove in 1.0 else payload = Marshal.dump(h) [SIGN, payload.length].pack('N*') + payload end timeout = h[:timeout] || Eye::Local.client_timeout attempt_command(payload, timeout) end
Private Instance Methods
attempt_command(payload, timeout)
click to toggle source
# File lib/eye/client.rb, line 28 def attempt_command(payload, timeout) Timeout.timeout(timeout) { send_request(payload) } rescue Timeout::Error, EOFError :timeouted end
send_request(pack)
click to toggle source
# File lib/eye/client.rb, line 34 def send_request(pack) UNIXSocket.open(@socket_path) do |socket| socket.write(pack) data = socket.read Marshal.load(data) rescue :corrupted_data end end