Class: RSpec::Conductor::Protocol::Socket
- Inherits:
-
Object
- Object
- RSpec::Conductor::Protocol::Socket
- Defined in:
- lib/rspec/conductor/protocol.rb
Instance Attribute Summary collapse
-
#io ⇒ Object
readonly
Returns the value of attribute io.
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(io) ⇒ Socket
constructor
A new instance of Socket.
- #receive_message ⇒ Object
- #send_message(message) ⇒ Object
Constructor Details
#initialize(io) ⇒ Socket
Returns a new instance of Socket.
11 12 13 |
# File 'lib/rspec/conductor/protocol.rb', line 11 def initialize(io) @io = io end |
Instance Attribute Details
#io ⇒ Object (readonly)
Returns the value of attribute io.
9 10 11 |
# File 'lib/rspec/conductor/protocol.rb', line 9 def io @io end |
Instance Method Details
#close ⇒ Object
38 39 40 |
# File 'lib/rspec/conductor/protocol.rb', line 38 def close io.close unless io.closed? end |
#receive_message ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/rspec/conductor/protocol.rb', line 25 def length_bytes = io.read(4) return nil unless length_bytes&.bytesize == 4 length = length_bytes.unpack1("N") json = io.read(length) return nil unless json&.bytesize == length JSON.parse(json, symbolize_names: true) rescue Errno::ECONNRESET, IOError, JSON::ParserError nil end |
#send_message(message) ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/rspec/conductor/protocol.rb', line 15 def () json = JSON.generate() length = [json.bytesize].pack("N") io.write(length) io.write(json.b) io.flush rescue Errno::EPIPE, IOError nil end |