diff --git a/lib/ruby-debug-ide.rb b/lib/ruby-debug-ide.rb index 10f70f4..c1ca2b9 100644 --- a/lib/ruby-debug-ide.rb +++ b/lib/ruby-debug-ide.rb @@ -18,11 +18,8 @@ module Debugger class << self - def find_free_port(host) - server = TCPServer.open(host, 0) - port = server.addr[1] - server.close - port + def is_windows + RbConfig::CONFIG['host_os'] =~ /mswin|msys|mingw|cygwin|bccwin|wince|emc/ end # Prints to the stderr using printf(*args) if debug logging flag (-d) is on. @@ -122,18 +119,22 @@ def start_control(host, port, notify_dispatcher) server = notify_dispatcher_if_needed(host, port, notify_dispatcher) do |real_port, port_changed| s = TCPServer.new(host, real_port) + s.setsockopt(:SOCKET, :REUSEADDR, 2) print_greeting_msg $stderr, host, real_port, port_changed ? "Subprocess" : "Fast" if defined? IDE_VERSION + puts "#{s.getsockopt(:SOCKET, :REUSEADDR).bool}" s end return unless server while (session = server.accept) + server.close $stderr.puts "Connected from #{session.peeraddr[2]}" if Debugger.cli_debug dispatcher = ENV['IDE_PROCESS_DISPATCHER'] if dispatcher ENV['IDE_PROCESS_DISPATCHER'] = "#{session.peeraddr[2]}:#{dispatcher}" unless dispatcher.include?(":") ENV['DEBUGGER_HOST'] = host + ENV['DEBUGGER_PORT'] = port.to_s end begin @interface = RemoteInterface.new(session) @@ -165,13 +166,10 @@ def notify_dispatcher_if_needed(host, port, need_notify) 3.times do |i| begin + $stderr.puts "#{Process.pid}: go create dispatcher socket #{acceptor_host} #{acceptor_port}" s = TCPSocket.open(acceptor_host, acceptor_port) dispatcher_answer = s.gets.chomp - if dispatcher_answer == "true" - port = Debugger.find_free_port(host) - end - server = yield port, dispatcher_answer == "true" s.print(port) @@ -186,6 +184,8 @@ def notify_dispatcher_if_needed(host, port, need_notify) sleep 0.3 end unless connected end + + nil end end diff --git a/lib/ruby-debug-ide/command.rb b/lib/ruby-debug-ide/command.rb index ecbd2ba..7aad807 100644 --- a/lib/ruby-debug-ide/command.rb +++ b/lib/ruby-debug-ide/command.rb @@ -173,7 +173,7 @@ def realpath(filename) if filename.index(File::SEPARATOR) || File::ALT_SEPARATOR && filename.index(File::ALT_SEPARATOR) filename = File.expand_path(filename) end - if (RUBY_VERSION < '1.9') || (RbConfig::CONFIG['host_os'] =~ /mswin/) + if (RUBY_VERSION < '1.9') || Debugger.is_windows filename else filename = File.realpath(filename) rescue filename diff --git a/lib/ruby-debug-ide/multiprocess/pre_child.rb b/lib/ruby-debug-ide/multiprocess/pre_child.rb index b707fc4..ccb23d7 100644 --- a/lib/ruby-debug-ide/multiprocess/pre_child.rb +++ b/lib/ruby-debug-ide/multiprocess/pre_child.rb @@ -5,13 +5,11 @@ def pre_child(options = nil) require 'socket' require 'ostruct' - host = ENV['DEBUGGER_HOST'] - options ||= OpenStruct.new( 'frame_bind' => false, - 'host' => host, + 'host' => ENV['DEBUGGER_HOST'], 'load_mode' => false, - 'port' => Debugger.find_free_port(host), + 'port' => ENV['DEBUGGER_PORT'], 'stop' => false, 'tracing' => false, 'int_handler' => true, @@ -23,8 +21,7 @@ def pre_child(options = nil) 'inspect_time_limit' => 100 ) - if(options.ignore_port) - options.port = Debugger.find_free_port(options.host) + if options.ignore_port options.notify_dispatcher = true end