@@ -74,16 +74,22 @@ def interrupt_last
7474 end
7575
7676 def start_server ( host = nil , port = 1234 , notify_dispatcher = false )
77- return if started?
78- start
79- start_control ( host , port , notify_dispatcher )
77+ _start_server_common ( host , port , nil , notify_dispatcher )
78+ end
79+
80+ def start_server_unix ( socket_path , notify_dispatcher = false )
81+ _start_server_common ( nil , 0 , socket_path , notify_dispatcher )
8082 end
8183
8284 def prepare_debugger ( options )
8385 @mutex = Mutex . new
8486 @proceed = ConditionVariable . new
8587
86- start_server ( options . host , options . port , options . notify_dispatcher )
88+ if options . socket_path . nil?
89+ start_server ( options . host , options . port , options . notify_dispatcher )
90+ else
91+ start_server_unix ( options . socket_path , options . notify_dispatcher )
92+ end
8793
8894 raise "Control thread did not start (#{ @control_thread } }" unless @control_thread && @control_thread . alive?
8995
@@ -112,24 +118,53 @@ def run_prog_script
112118 end
113119
114120 def start_control ( host , port , notify_dispatcher )
121+ _start_control_common ( host , port , nil , notify_dispatcher )
122+ end
123+
124+ def start_control_unix ( socket_path , notify_dispatcher )
125+ _start_control_common ( nil , 0 , socket_path , notify_dispatcher )
126+ end
127+
128+ private
129+
130+ def _start_server_common ( host , port , socket_path , notify_dispatcher )
131+ return if started?
132+ start
133+ _start_control_common ( host , port , socket_path , notify_dispatcher )
134+ end
135+
136+ def _start_control_common ( host , port , socket_path , notify_dispatcher )
115137 raise "Debugger is not started" unless started?
116138 return if @control_thread
117139 @control_thread = DebugThread . new do
118140 begin
119- # 127.0.0.1 seemingly works with all systems and with IPv6 as well.
120- # "localhost" and nil have problems on some systems.
121- host ||= '127.0.0.1'
122-
123- server = notify_dispatcher_if_needed ( host , port , notify_dispatcher ) do |real_port , port_changed |
124- s = TCPServer . new ( host , real_port )
125- print_greeting_msg $stderr, host , real_port , port_changed ? "Subprocess" : "Fast" if defined? IDE_VERSION
126- s
141+ if socket_path . nil?
142+ # 127.0.0.1 seemingly works with all systems and with IPv6 as well.
143+ # "localhost" and nil have problems on some systems.
144+ host ||= '127.0.0.1'
145+
146+ server = notify_dispatcher_if_needed ( host , port , notify_dispatcher ) do |real_port , port_changed |
147+ s = TCPServer . new ( host , real_port )
148+ print_greeting_msg $stderr, host , real_port , port_changed ? "Subprocess" : "Fast" if defined? IDE_VERSION
149+ s
150+ end
151+ else
152+ raise "Cannot specify host and socket_file at the same time" if host
153+ File . delete ( socket_path ) if File . exist? ( socket_path )
154+ server = UNIXServer . new ( socket_path )
155+ print_greeting_msg $stderr, nil , nil , "Fast" , socket_path if defined? IDE_VERSION
127156 end
128157
129158 return unless server
130159
131160 while ( session = server . accept )
132- $stderr. puts "Connected from #{ session . peeraddr [ 2 ] } " if Debugger . cli_debug
161+ if Debugger . cli_debug
162+ if session . peeraddr == 'AF_INET'
163+ $stderr. puts "Connected from #{ session . peeraddr [ 2 ] } "
164+ else
165+ $stderr. puts "Connected from local client"
166+ end
167+ end
133168 dispatcher = ENV [ 'IDE_PROCESS_DISPATCHER' ]
134169 if dispatcher
135170 ENV [ 'IDE_PROCESS_DISPATCHER' ] = "#{ session . peeraddr [ 2 ] } :#{ dispatcher } " unless dispatcher . include? ( ":" )
@@ -153,8 +188,6 @@ def start_control(host, port, notify_dispatcher)
153188 end
154189 end
155190
156- private
157-
158191 def notify_dispatcher_if_needed ( host , port , need_notify )
159192 return yield port unless need_notify
160193
0 commit comments