Class: Klay::Client::Ipc

Inherits:
Klay::Client show all
Defined in:
lib/klay/client/ipc.rb

Overview

Provides an IPC-RPC client.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Ipc

Constructor for the IPC Client. Should not be used; use Klay::Client.create intead.

Parameters:

  • path (String)

    an URI pointing to an IPC RPC-API.



30
31
32
33
# File 'lib/klay/client/ipc.rb', line 30

def initialize(path)
  super
  @path = path
end

Instance Attribute Details

#pathObject

The path of the IPC socket.



24
25
26
# File 'lib/klay/client/ipc.rb', line 24

def path
  @path
end

Instance Method Details

#send(payload) ⇒ String

Sends an RPC request to the connected IPC socket.

Parameters:

  • payload (Hash)

    the RPC request parameters.

Returns:

  • (String)

    a JSON-encoded response.



39
40
41
42
43
44
45
# File 'lib/klay/client/ipc.rb', line 39

def send(payload)
  socket = UNIXSocket.new(@path)
  socket.puts(payload)
  read = socket.recvmsg(nil)[0]
  socket.close
  return read
end