class OneApm::Support::ForkedProcessChannel::Pipe
Constants
- NUM_LENGTH_BYTES
- READY_MARKER
Attributes
in[RW]
last_read[R]
out[RW]
parent_pid[R]
Public Class Methods
new()
click to toggle source
# File lib/one_apm/support/forked_process_channel.rb, line 30 def initialize @out, @in = IO.pipe if defined?(::Encoding::ASCII_8BIT) @in.set_encoding(::Encoding::ASCII_8BIT) end @last_read = Time.now @parent_pid = $$ end
Public Instance Methods
after_fork_in_child()
click to toggle source
# File lib/one_apm/support/forked_process_channel.rb, line 81 def after_fork_in_child @out.close unless @out.closed? write(READY_MARKER) end
after_fork_in_parent()
click to toggle source
# File lib/one_apm/support/forked_process_channel.rb, line 86 def after_fork_in_parent @in.close unless @in.closed? end
close()
click to toggle source
# File lib/one_apm/support/forked_process_channel.rb, line 39 def close @out.close unless @out.closed? @in.close unless @in.closed? end
closed?()
click to toggle source
# File lib/one_apm/support/forked_process_channel.rb, line 90 def closed? @out.closed? && @in.closed? end
deserialize_message_length(data)
click to toggle source
# File lib/one_apm/support/forked_process_channel.rb, line 48 def deserialize_message_length(data) data.unpack("L>").first end
eof?()
click to toggle source
# File lib/one_apm/support/forked_process_channel.rb, line 77 def eof? !@out.closed? && @out.eof? end
read()
click to toggle source
# File lib/one_apm/support/forked_process_channel.rb, line 58 def read @in.close unless @in.closed? @last_read = Time.now length_bytes = @out.read(NUM_LENGTH_BYTES) if length_bytes message_length = deserialize_message_length(length_bytes) if message_length @out.read(message_length) else length_hex = length_bytes.bytes.map { |b| b.to_s(16) }.join(' ') OneApm::Manager.logger.error("Failed to deserialize message length from pipe. Bytes: [#{length_hex}]") nil end else OneApm::Manager.logger.error("Failed to read bytes for length from pipe.") nil end end
serialize_message_length(data)
click to toggle source
# File lib/one_apm/support/forked_process_channel.rb, line 44 def serialize_message_length(data) [data.bytesize].pack("L>") end
write(data)
click to toggle source
# File lib/one_apm/support/forked_process_channel.rb, line 52 def write(data) @out.close unless @out.closed? @in << serialize_message_length(data) @in << data end