class DEBUGGER__::UI_TcpServer

Public Class Methods

new(host: nil, port: nil) click to toggle source
Calls superclass method DEBUGGER__::UI_ServerBase::new
# File debug-1.4.0/lib/debug/server.rb, line 331
def initialize host: nil, port: nil
  @addr = nil
  @host = host || CONFIG[:host] || '127.0.0.1'
  @port = port || begin
    port_str = CONFIG[:port] || raise("Specify listening port by RUBY_DEBUG_PORT environment variable.")
    if /\A\d+\z/ !~ port_str
      raise "Specify digits for port number"
    else
      port_str.to_i
    end
  end

  super()
end

Public Instance Methods

accept() { |sock_for_fork = sock| ... } click to toggle source
Calls superclass method DEBUGGER__::UI_ServerBase#accept
# File debug-1.4.0/lib/debug/server.rb, line 359
    def accept
      retry_cnt = 0
      super # for fork

      begin
        Socket.tcp_server_sockets @host, @port do |socks|
          @addr = socks[0].local_address.inspect_sockaddr # Change this part if `socks` are multiple.
          rdbg = File.expand_path('../../exe/rdbg', __dir__)

          DEBUGGER__.warn "Debugger can attach via TCP/IP (#{@addr})"
          DEBUGGER__.info <<~EOS
          With rdbg, use the following command line:
          #
          #   #{rdbg} --attach #{@addr.split(':').join(' ')}
          #
          EOS

          chrome_setup if CONFIG[:open_frontend] == 'chrome'

          Socket.accept_loop(socks) do |sock, client|
            @client_addr = client
            yield @sock_for_fork = sock
          end
        end
      rescue Errno::EADDRINUSE
        if retry_cnt < 10
          retry_cnt += 1
          sleep 0.1
          retry
        else
          raise
        end
      rescue Terminate
        # OK
      rescue => e
        $stderr.puts e.inspect, e.message
        pp e.backtrace
        exit
      end
    ensure
      @sock_for_fork = nil
    end
chrome_setup() click to toggle source
# File debug-1.4.0/lib/debug/server.rb, line 346
    def chrome_setup
      require_relative 'server_cdp'

      unless @chrome_pid = UI_CDP.setup_chrome(@addr)
        DEBUGGER__.warn <<~EOS if CONFIG[:open_frontend] == 'chrome'
          With Chrome browser, type the following URL in the address-bar:
          
             devtools://devtools/bundled/inspector.html?ws=#{@addr}
          
          EOS
      end
    end