Class: Byebug::Remote::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/byebug/remote/server.rb

Overview

Server for remote debugging

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(wait_connection:, &block) ⇒ Server

Returns a new instance of Server.



13
14
15
16
17
# File 'lib/byebug/remote/server.rb', line 13

def initialize(wait_connection:, &block)
  @thread = nil
  @wait_connection = wait_connection
  @main_loop = block
end

Instance Attribute Details

#actual_portObject (readonly)

Returns the value of attribute actual_port.



11
12
13
# File 'lib/byebug/remote/server.rb', line 11

def actual_port
  @actual_port
end

#wait_connectionObject (readonly)

Returns the value of attribute wait_connection.



11
12
13
# File 'lib/byebug/remote/server.rb', line 11

def wait_connection
  @wait_connection
end

Instance Method Details

#start(host, port) ⇒ Object

Start the remote debugging server



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/byebug/remote/server.rb', line 22

def start(host, port)
  return if @thread

  if wait_connection
    mutex = Mutex.new
    proceed = ConditionVariable.new
  end

  server = TCPServer.new(host, port)
  @actual_port = server.addr[1]

  yield if block_given?

  @thread = DebugThread.new do
    while (session = server.accept)
      @main_loop.call(session)

      mutex.synchronize { proceed.signal } if wait_connection
    end
  end

  mutex.synchronize { proceed.wait(mutex) } if wait_connection
end