Class: DEBUGGER__::UI_UnixDomainServer

Inherits:
UI_ServerBase show all
Defined in:
lib/debug/server.rb

Instance Attribute Summary

Attributes inherited from UI_ServerBase

#reader_thread

Instance Method Summary collapse

Methods inherited from UI_ServerBase

#activate, #after_fork_parent, #ask, #check_cookie, #cleanup_reader, #deactivate, #greeting, #parse_option, #pause, #process, #puts, #quit, #readline, #remote?, #setup_interrupt, #sigurg_overridden?, #sock, #vscode_setup, #width

Methods inherited from UI_Base

#event, #flush, #ignore_output_on_suspend?

Constructor Details

#initialize(sock_dir: nil, sock_path: nil) ⇒ UI_UnixDomainServer

Returns a new instance of UI_UnixDomainServer.



479
480
481
482
483
484
485
# File 'lib/debug/server.rb', line 479

def initialize sock_dir: nil, sock_path: nil
  @sock_path = sock_path
  @sock_dir = sock_dir || DEBUGGER__.unix_domain_socket_dir
  @sock_for_fork = nil

  super()
end

Instance Method Details

#acceptObject



487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
# File 'lib/debug/server.rb', line 487

def accept
  super # for fork

  case
  when @sock_path
  when sp = CONFIG[:sock_path]
    @sock_path = sp
  else
    @sock_path = DEBUGGER__.create_unix_domain_socket_name(@sock_dir)
  end

  ::DEBUGGER__.warn "Debugger can attach via UNIX domain socket (#{@sock_path})"
  vscode_setup @sock_path if CONFIG[:open] == 'vscode'

  begin
    Socket.unix_server_loop @sock_path do |sock, client|
      @sock_for_fork = sock
      @client_addr = client

      yield sock
    ensure
      sock.close
      @sock_for_fork = nil
    end
  rescue Errno::ECONNREFUSED => _e
    ::DEBUGGER__.warn "#{_e.message} (socket path: #{@sock_path})"

    if @sock_path.start_with? Config.unix_domain_socket_tmpdir
      # try on homedir
      @sock_path = Config.create_unix_domain_socket_name(unix_domain_socket_homedir)
      ::DEBUGGER__.warn "retry with #{@sock_path}"
      retry
    else
      raise
    end
  end
end