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
error_print(result) if !succ && verbose
client.send_reply(succ, result)
rescue Exception => e
error_print(e) if verbose
ensure
client.close unless succ
if Thread.current['DRb']['stop_service']
shutdown
break
end
break unless succ
end
end
end
end