class Polyphony::DebugServer

Attributes

thread[R]

Public Class Methods

new(socket_path) click to toggle source
# File lib/polyphony/debugger.rb, line 182
def initialize(socket_path)
  @socket_path = socket_path
  @fiber = Fiber.current
  start_server_thread
end

Public Instance Methods

get_command(info) click to toggle source
# File lib/polyphony/debugger.rb, line 213
def get_command(info)
  @client&.orig_write "#{info.inspect}\n"
  cmd = @client&.orig_gets&.chomp
  eval(cmd)
rescue SystemCallError
  nil
rescue => e
  trace "Error in interact_with_client: #{e.inspect}"
  e.backtrace[0..3].each { |l| trace l }
  @client = nil
end
handle_client(client) click to toggle source
# File lib/polyphony/debugger.rb, line 203
def handle_client(client)
  @client = client
end
start_server_thread() click to toggle source
# File lib/polyphony/debugger.rb, line 188
def start_server_thread
  @thread = Thread.new do
    puts("Listening on #{@socket_path}")
    FileUtils.rm(@socket_path) if File.exists?(@socket_path)
    socket = UNIXServer.new(@socket_path)
    loop do
      @client = socket.accept
    end
  end
end
stop() click to toggle source
# File lib/polyphony/debugger.rb, line 199
def stop
  @thread.kill
end
wait_for_client() click to toggle source
# File lib/polyphony/debugger.rb, line 207
def wait_for_client
  sleep 0.1 until @client
  msg = @client.gets
  @client.puts msg
end