From 6591e380169e85e7764150e3a93722ca990ee05d Mon Sep 17 00:00:00 2001 From: seki Date: Mon, 19 Nov 2007 18:30:18 +0000 Subject: [PATCH] merged from ruby_1_8 branch. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13975 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 24 +++++++++++++++++ lib/drb/acl.rb | 2 ++ lib/drb/drb.rb | 45 ++++++++++++++++++++++---------- lib/drb/extservm.rb | 56 +++++++++++++++++----------------------- lib/drb/invokemethod.rb | 2 +- lib/drb/observer.rb | 21 +++++++-------- lib/drb/ssl.rb | 1 - lib/drb/unix.rb | 2 +- test/drb/drbtest.rb | 4 +-- test/drb/test_drb.rb | 12 --------- test/drb/test_drbssl.rb | 8 +----- test/drb/test_drbunix.rb | 3 --- 12 files changed, 95 insertions(+), 85 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0dfce85f4a..1cba2fe57c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,27 @@ +Tue Nov 20 03:24:42 2007 Masatoshi SEKI + + * lib/drb/extservm.rb: merged from ruby_1_8 branch. + + * lib/drb/acl.rb: ditto. + + * lib/drb/ssl.rb: ditto. + + * lib/drb/unix.rb: ditto. + + * lib/drb/drb.rb: ditto. + + * lib/drb/observer.rb: ditto. + + * lib/drb/invokemethod.rb: ditto. + + * test/drb/test_drbssl.rb: ditto. + + * test/drb/test_drb.rb: ditto. + + * test/drb/drbtest.rb: ditto. + + * test/drb/test_drbunix.rb: ditto. + Tue Nov 20 00:52:46 2007 Tanaka Akira * test/fileutils/fileasserts.rb (assert_equal_time): show nsec if diff --git a/lib/drb/acl.rb b/lib/drb/acl.rb index aa86dbe70f..861c8a514d 100644 --- a/lib/drb/acl.rb +++ b/lib/drb/acl.rb @@ -13,6 +13,8 @@ class ACL def initialize(str) if str == '*' or str == 'all' @pat = [:all] + elsif str.include?('*') + @pat = [:name, dot_pat(str)] else begin @pat = [:ip, IPAddr.new(str)] diff --git a/lib/drb/drb.rb b/lib/drb/drb.rb index a3e0ed927f..20e658e611 100644 --- a/lib/drb/drb.rb +++ b/lib/drb/drb.rb @@ -6,9 +6,9 @@ # Copyright (c) 1999-2003 Masatoshi SEKI. You can redistribute it and/or # modify it under the same terms as Ruby. # -# Author: Masatoshi SEKI +# Author:: Masatoshi SEKI # -# Documentation: William Webber (william@williamwebber.com) +# Documentation:: William Webber (william@williamwebber.com) # # == Overview # @@ -578,8 +578,7 @@ module DRb end raise(DRbConnError, 'connection closed') if str.nil? raise(DRbConnError, 'premature marshal format(can\'t read)') if str.size < sz - # TODO: YARV doesn't have Thread.exclusive - #Thread.exclusive do + DRb.mutex.synchronize do begin save = Thread.current[:drb_untaint] Thread.current[:drb_untaint] = [] @@ -592,7 +591,7 @@ module DRb end Thread.current[:drb_untaint] = save end - #end + end end def send_request(stream, ref, msg_id, arg, b) # :nodoc: @@ -833,7 +832,7 @@ module DRb begin Socket::gethostbyname(host)[0] rescue - host + 'localhost' end end @@ -859,6 +858,7 @@ module DRb def self.open_server(uri, config) uri = 'druby://:0' unless uri host, port, opt = parse_uri(uri) + config = {:tcp_original_host => host}.update(config) if host.size == 0 host = getservername soc = open_server_inaddr_any(host, port) @@ -866,6 +866,7 @@ module DRb soc = TCPServer.open(host, port) end port = soc.addr[1] if port == 0 + config[:tcp_port] = port uri = "druby://#{host}:#{port}" self.new(uri, soc, config) end @@ -946,7 +947,12 @@ module DRb break if (@acl ? @acl.allow_socket?(s) : true) s.close end - self.class.new(nil, s, @config) + if @config[:tcp_original_host].to_s.size == 0 + uri = "druby://#{s.addr[3]}:#{@config[:tcp_port]}" + else + uri = @uri + end + self.class.new(uri, s, @config) end # Check to see if this connection is alive. @@ -973,7 +979,7 @@ module DRb def initialize(option) @option = option.to_s end - attr_reader :option + attr :option def to_s; @option; end def ==(other) @@ -1497,7 +1503,7 @@ module DRb if $SAFE < @safe_level info = Thread.current['DRb'] if @block - @result = Thread.new { + @result = Thread.new { Thread.current['DRb'] = info $SAFE = @safe_level perform_with_block @@ -1517,7 +1523,7 @@ module DRb end end @succ = true - if @msg_id == :to_ary + if @msg_id == :to_ary && @result.class == Array @result = DRbArray.new(@result) end return @succ, @result @@ -1553,7 +1559,7 @@ module DRb end ary.collect(&@obj)[0] else - @obj.send(@msg_id, *@argv) + @obj.__send__(@msg_id, *@argv) end end @@ -1667,6 +1673,12 @@ module DRb # # This is the URI of the current server. See #current_server. def uri + drb = Thread.current['DRb'] + client = (drb && drb['client']) + if client + uri = client.uri + return uri if uri + end current_server.uri end module_function :uri @@ -1739,13 +1751,18 @@ module DRb end module_function :install_acl + @mutex = Mutex.new + def mutex + @mutex + end + module_function :mutex + @server = {} def regist_server(server) @server[server.uri] = server - # TODO: YARV doesn't have Thread.exclusive - #Thread.exclusive do + mutex.synchronize do @primary_server = server unless @primary_server - #end + end end module_function :regist_server diff --git a/lib/drb/extservm.rb b/lib/drb/extservm.rb index 1ede7d6d16..be40aea9f5 100644 --- a/lib/drb/extservm.rb +++ b/lib/drb/extservm.rb @@ -5,10 +5,12 @@ require 'drb/drb' require 'thread' +require 'monitor' module DRb class ExtServManager include DRbUndumped + include MonitorMixin @@command = {} @@ -21,6 +23,8 @@ module DRb end def initialize + super() + @cond = new_cond @servers = {} @waiting = [] @queue = Queue.new @@ -30,39 +34,28 @@ module DRb attr_accessor :uri def service(name) - while true - server = nil - # TODO: YARV doesn't have Thread.exclusive - #Thread.exclusive do - server = @servers[name] if @servers[name] - #end - return server if server && server.alive? - invoke_service(name) + synchronize do + while true + server = @servers[name] + return server if server && server.alive? + invoke_service(name) + @cond.wait + end end end def regist(name, ro) - ary = nil - # TODO: YARV doesn't have Thread.exclusive - #Thread.exclusive do - @servers[name] = ro - ary = @waiting - @waiting = [] - #end - ary.each do |th| - begin - th.run - rescue ThreadError - end + synchronize do + @servers[name] = ro + @cond.signal end self end def unregist(name) - # TODO: YARV doesn't have Thread.exclusive - #Thread.exclusive do + synchronize do @servers.delete(name) - #end + end end private @@ -76,22 +69,21 @@ module DRb end def invoke_service(name) - Thread.critical = true - @waiting.push Thread.current - @queue.push name - Thread.stop + @queue.push(name) end def invoke_service_command(name, command) raise "invalid command. name: #{name}" unless command - # TODO: YARV doesn't have Thread.exclusive - #Thread.exclusive do + synchronize do return if @servers.include?(name) @servers[name] = false - #end + end uri = @uri || DRb.uri - Process.detach(Process.spawn("#{command} #{uri} #{name}")) - true + if RUBY_PLATFORM =~ /mswin32/ && /NT/ =~ ENV["OS"] + system(%Q'cmd /c start "ruby" /b #{command} #{uri} #{name}') + else + system("#{command} #{uri} #{name} &") + end end end end diff --git a/lib/drb/invokemethod.rb b/lib/drb/invokemethod.rb index 2bcd12f5f5..412b2ab9b5 100644 --- a/lib/drb/invokemethod.rb +++ b/lib/drb/invokemethod.rb @@ -9,7 +9,7 @@ module DRb end block_value = @block.call(*x) end - + def perform_with_block @obj.__send__(@msg_id, *@argv) do |*x| jump_error = nil diff --git a/lib/drb/observer.rb b/lib/drb/observer.rb index f2c3455e57..e7f1668c52 100644 --- a/lib/drb/observer.rb +++ b/lib/drb/observer.rb @@ -6,17 +6,16 @@ module DRb def notify_observers(*arg) if defined? @observer_state and @observer_state - if defined? @observer_peers - @observer_peers.delete_if do |k, v| - begin - k.send(v, *arg) - false - rescue - true - end - end - end - @observer_state = false + if defined? @observer_peers + for i in @observer_peers.dup + begin + i.update(*arg) + rescue + delete_observer(i) + end + end + end + @observer_state = false end end end diff --git a/lib/drb/ssl.rb b/lib/drb/ssl.rb index 1a0ac92960..58d6b7d1e0 100644 --- a/lib/drb/ssl.rb +++ b/lib/drb/ssl.rb @@ -180,7 +180,6 @@ module DRb ssl = @config.accept(soc) self.class.new(uri, ssl, @config, true) rescue OpenSSL::SSL::SSLError - soc.close warn("#{__FILE__}:#{__LINE__}: warning: #{$!.message} (#{$!.class})") if @config[:verbose] retry end diff --git a/lib/drb/unix.rb b/lib/drb/unix.rb index 989ec57eed..57feed8301 100644 --- a/lib/drb/unix.rb +++ b/lib/drb/unix.rb @@ -88,7 +88,7 @@ module DRb public def close return unless @socket - path = @socket.path + path = @socket.path if @server_mode @socket.close File.unlink(path) if @server_mode @socket = nil diff --git a/test/drb/drbtest.rb b/test/drb/drbtest.rb index 40f71c307a..bc16ab1ca2 100644 --- a/test/drb/drbtest.rb +++ b/test/drb/drbtest.rb @@ -1,5 +1,3 @@ - -__END__ require 'test/unit' require 'drb/drb' require 'drb/extservm' @@ -24,7 +22,7 @@ class DRbService %w(ut_drb.rb ut_array.rb ut_port.rb ut_large.rb ut_safe1.rb ut_eval.rb).each do |nm| add_service_command(nm) end - @server = @@server = DRb::DRbServer.new(nil, @@manager, {}) + @server = @@server = DRb::DRbServer.new('druby://localhost:0', @@manager, {}) @@manager.uri = @@server.uri def self.manager @@manager diff --git a/test/drb/test_drb.rb b/test/drb/test_drb.rb index a03210eb98..5719f60b80 100644 --- a/test/drb/test_drb.rb +++ b/test/drb/test_drb.rb @@ -1,17 +1,5 @@ require 'drbtest' -class TestDRbCore - def test_drb - flunk("YARV doesn't support drb") - end -end - -__END__ - -end - -__END__ - class TestDRbCore < Test::Unit::TestCase include DRbCore end diff --git a/test/drb/test_drbssl.rb b/test/drb/test_drbssl.rb index 4c87201362..cfb3bc36a4 100644 --- a/test/drb/test_drbssl.rb +++ b/test/drb/test_drbssl.rb @@ -5,14 +5,8 @@ begin rescue LoadError end -class TestDRbSSLCore < Test::Unit::TestCase - def test_message - flunk("YARV doesn't support drb") - end -end +if Object.const_defined?("OpenSSL") -# TODO: YARV doesn't support drb -if false # Object.const_defined?("OpenSSL") class DRbSSLService < DRbService %w(ut_drb_drbssl.rb ut_array_drbssl.rb).each do |nm| diff --git a/test/drb/test_drbunix.rb b/test/drb/test_drbunix.rb index c2d7dea68c..e1a17edd3d 100644 --- a/test/drb/test_drbunix.rb +++ b/test/drb/test_drbunix.rb @@ -1,6 +1,3 @@ - -__END__ - require 'drbtest' begin