Skip to content

create sockets with SO_REUSEPORT option #164

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions lib/ruby-debug-ide.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -186,6 +184,8 @@ def notify_dispatcher_if_needed(host, port, need_notify)
sleep 0.3
end unless connected
end

nil
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/ruby-debug-ide/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 3 additions & 6 deletions lib/ruby-debug-ide/multiprocess/pre_child.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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

Expand Down