main_loop()
private
The main loop performed by a DRbServer’s internal thread.
Accepts a connection from a client, and starts up its own thread to handle
it. This thread loops, receiving requests from the client, invoking them
on a local object, and returning responses, until the client closes the
connection or a local method call fails.
Show source
def main_loop
client0 = @protocol.accept
return nil if !client0
Thread.start(client0) do |client|
@grp.add Thread.current
Thread.current['DRb'] = { 'client' => client ,
'server' => self }
DRb.mutex.synchronize do
client_uri = client.uri
@exported_uri << client_uri unless @exported_uri.include?(client_uri)
end
loop do
begin
succ = false
invoke_method = InvokeMethod.new(self, client)
succ, result = invoke_method.perform
if !succ && verbose
p result
result.backtrace.each do |x|
puts x
end
end
client.send_reply(succ, result) rescue nil
ensure
client.close unless succ
if Thread.current['DRb']['stop_service']
Thread.new { stop_service }
end
break unless succ
end
end
end
end