Class: Specwrk::IPC
- Inherits:
-
Object
- Object
- Specwrk::IPC
- Defined in:
- lib/specwrk/ipc.rb
Instance Attribute Summary collapse
-
#child_socket ⇒ Object
readonly
Returns the value of attribute child_socket.
-
#parent_socket ⇒ Object
readonly
Returns the value of attribute parent_socket.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(parent_pid: Process.pid, parent_socket: nil, child_socket: nil) ⇒ IPC
constructor
A new instance of IPC.
- #read ⇒ Object
- #write(msg) ⇒ Object
Constructor Details
#initialize(parent_pid: Process.pid, parent_socket: nil, child_socket: nil) ⇒ IPC
Returns a new instance of IPC.
14 15 16 17 18 19 |
# File 'lib/specwrk/ipc.rb', line 14 def initialize(parent_pid: Process.pid, parent_socket: nil, child_socket: nil) @parent_pid = parent_pid @parent_socket, @child_socket = parent_socket, child_socket @parent_socket, @child_socket = UNIXSocket.pair if @parent_socket.nil? && @child_socket.nil? end |
Instance Attribute Details
#child_socket ⇒ Object (readonly)
Returns the value of attribute child_socket.
5 6 7 |
# File 'lib/specwrk/ipc.rb', line 5 def child_socket @child_socket end |
#parent_socket ⇒ Object (readonly)
Returns the value of attribute parent_socket.
5 6 7 |
# File 'lib/specwrk/ipc.rb', line 5 def parent_socket @parent_socket end |
Class Method Details
.from_child_fd(fd, parent_pid:) ⇒ Object
7 8 9 10 11 12 |
# File 'lib/specwrk/ipc.rb', line 7 def self.from_child_fd(fd, parent_pid:) new( parent_pid: parent_pid, child_socket: UNIXSocket.for_fd(fd) ) end |
Instance Method Details
#read ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/specwrk/ipc.rb', line 25 def read IO.select([socket]) data = socket.gets&.chomp return if data.nil? || data.length.zero? || data == "INT" data end |
#write(msg) ⇒ Object
21 22 23 |
# File 'lib/specwrk/ipc.rb', line 21 def write(msg) socket.puts msg.to_s end |