summaryrefslogtreecommitdiff
path: root/lib/drb
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-09-21 17:06:05 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-09-21 17:06:05 +0000
commit6a7d389ed0bae2083b6608072fad34e64b3901d7 ()
tree245f6f9d593a68823215e53a620ab8014e9633a0 /lib/drb
parent941b101e2200b0eabd738e40e7034d09109e0282 (diff)
* lib/drb/drb.rb: Support graceful shutdown.
(DRbTCPSocket#initialize): Create a pipe for shutdown notification. (DRbTCPSocket#close): Invoke close_shutdown_pipe. (DRbTCPSocket#close_shutdown_pipe): New private method. (DRbTCPSocket#accept): Use accept_or_shutdown. (DRbTCPSocket#accept_or_shutdown): New private method which returns nil on shutdown. (DRbServer#stop_service): Use shutdown instead of Thread#kill. (DRbServer#run): Break infinite loop when main_loop returns nil. (DRbServer#main_loop): @protocol.accept may return nil. * lib/drb/ssl.rb: Follow above change. * lib/drb/unix.rb: Ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47678 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--lib/drb/drb.rb45
-rw-r--r--lib/drb/ssl.rb3
-rw-r--r--lib/drb/unix.rb4
3 files changed, 45 insertions, 7 deletions
@@ -905,6 +905,7 @@ module DRb
@acl = config[:tcp_acl]
@msg = DRbMessage.new(config)
set_sockopt(@socket)
end
# Get the URI that we are connected to.
@@ -952,14 +953,28 @@ module DRb
@socket.close
@socket = nil
end
end
# On the server side, for an instance returned by #open_server,
# accept a client connection and return a new instance to handle
# the server's side of this client-server session.
def accept
while true
- s = @socket.accept
break if (@acl ? @acl.allow_socket?(s) : true)
s.close
end
@@ -971,6 +986,20 @@ module DRb
self.class.new(uri, s, @config)
end
# Check to see if this connection is alive.
def alive?
return false unless @socket
@@ -1438,7 +1467,12 @@ module DRb
if Thread.current['DRb'] && Thread.current['DRb']['server'] == self
Thread.current['DRb']['stop_service'] = true
else
- @thread.kill.join
end
end
@@ -1463,8 +1497,7 @@ module DRb
def run
Thread.start do
begin
- while true
- main_loop
end
ensure
@protocol.close if @protocol
@@ -1607,7 +1640,9 @@ module DRb
# returning responses, until the client closes the connection
# or a local method call fails.
def main_loop
- Thread.start(@protocol.accept) do |client|
@grp.add Thread.current
Thread.current['DRb'] = { 'client' => client ,
'server' => self }
@@ -322,7 +322,8 @@ module DRb
def accept # :nodoc:
begin
while true
- soc = @socket.accept
break if (@acl ? @acl.allow_socket?(soc) : true)
soc.close
end
@@ -98,10 +98,12 @@ module DRb
@socket.close
File.unlink(path) if @server_mode
@socket = nil
end
def accept
- s = @socket.accept
self.class.new(nil, s, @config)
end