merged from ruby_1_8 branch.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13975 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
44b6b031ba
commit
6591e38016
24
ChangeLog
24
ChangeLog
@ -1,3 +1,27 @@
|
|||||||
|
Tue Nov 20 03:24:42 2007 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
|
||||||
|
|
||||||
|
* 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 <akr@fsij.org>
|
Tue Nov 20 00:52:46 2007 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
* test/fileutils/fileasserts.rb (assert_equal_time): show nsec if
|
* test/fileutils/fileasserts.rb (assert_equal_time): show nsec if
|
||||||
|
@ -13,6 +13,8 @@ class ACL
|
|||||||
def initialize(str)
|
def initialize(str)
|
||||||
if str == '*' or str == 'all'
|
if str == '*' or str == 'all'
|
||||||
@pat = [:all]
|
@pat = [:all]
|
||||||
|
elsif str.include?('*')
|
||||||
|
@pat = [:name, dot_pat(str)]
|
||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
@pat = [:ip, IPAddr.new(str)]
|
@pat = [:ip, IPAddr.new(str)]
|
||||||
|
@ -6,9 +6,9 @@
|
|||||||
# Copyright (c) 1999-2003 Masatoshi SEKI. You can redistribute it and/or
|
# Copyright (c) 1999-2003 Masatoshi SEKI. You can redistribute it and/or
|
||||||
# modify it under the same terms as Ruby.
|
# 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
|
# == Overview
|
||||||
#
|
#
|
||||||
@ -578,8 +578,7 @@ module DRb
|
|||||||
end
|
end
|
||||||
raise(DRbConnError, 'connection closed') if str.nil?
|
raise(DRbConnError, 'connection closed') if str.nil?
|
||||||
raise(DRbConnError, 'premature marshal format(can\'t read)') if str.size < sz
|
raise(DRbConnError, 'premature marshal format(can\'t read)') if str.size < sz
|
||||||
# TODO: YARV doesn't have Thread.exclusive
|
DRb.mutex.synchronize do
|
||||||
#Thread.exclusive do
|
|
||||||
begin
|
begin
|
||||||
save = Thread.current[:drb_untaint]
|
save = Thread.current[:drb_untaint]
|
||||||
Thread.current[:drb_untaint] = []
|
Thread.current[:drb_untaint] = []
|
||||||
@ -592,7 +591,7 @@ module DRb
|
|||||||
end
|
end
|
||||||
Thread.current[:drb_untaint] = save
|
Thread.current[:drb_untaint] = save
|
||||||
end
|
end
|
||||||
#end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def send_request(stream, ref, msg_id, arg, b) # :nodoc:
|
def send_request(stream, ref, msg_id, arg, b) # :nodoc:
|
||||||
@ -833,7 +832,7 @@ module DRb
|
|||||||
begin
|
begin
|
||||||
Socket::gethostbyname(host)[0]
|
Socket::gethostbyname(host)[0]
|
||||||
rescue
|
rescue
|
||||||
host
|
'localhost'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -859,6 +858,7 @@ module DRb
|
|||||||
def self.open_server(uri, config)
|
def self.open_server(uri, config)
|
||||||
uri = 'druby://:0' unless uri
|
uri = 'druby://:0' unless uri
|
||||||
host, port, opt = parse_uri(uri)
|
host, port, opt = parse_uri(uri)
|
||||||
|
config = {:tcp_original_host => host}.update(config)
|
||||||
if host.size == 0
|
if host.size == 0
|
||||||
host = getservername
|
host = getservername
|
||||||
soc = open_server_inaddr_any(host, port)
|
soc = open_server_inaddr_any(host, port)
|
||||||
@ -866,6 +866,7 @@ module DRb
|
|||||||
soc = TCPServer.open(host, port)
|
soc = TCPServer.open(host, port)
|
||||||
end
|
end
|
||||||
port = soc.addr[1] if port == 0
|
port = soc.addr[1] if port == 0
|
||||||
|
config[:tcp_port] = port
|
||||||
uri = "druby://#{host}:#{port}"
|
uri = "druby://#{host}:#{port}"
|
||||||
self.new(uri, soc, config)
|
self.new(uri, soc, config)
|
||||||
end
|
end
|
||||||
@ -946,7 +947,12 @@ module DRb
|
|||||||
break if (@acl ? @acl.allow_socket?(s) : true)
|
break if (@acl ? @acl.allow_socket?(s) : true)
|
||||||
s.close
|
s.close
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
# Check to see if this connection is alive.
|
# Check to see if this connection is alive.
|
||||||
@ -973,7 +979,7 @@ module DRb
|
|||||||
def initialize(option)
|
def initialize(option)
|
||||||
@option = option.to_s
|
@option = option.to_s
|
||||||
end
|
end
|
||||||
attr_reader :option
|
attr :option
|
||||||
def to_s; @option; end
|
def to_s; @option; end
|
||||||
|
|
||||||
def ==(other)
|
def ==(other)
|
||||||
@ -1497,7 +1503,7 @@ module DRb
|
|||||||
if $SAFE < @safe_level
|
if $SAFE < @safe_level
|
||||||
info = Thread.current['DRb']
|
info = Thread.current['DRb']
|
||||||
if @block
|
if @block
|
||||||
@result = Thread.new {
|
@result = Thread.new {
|
||||||
Thread.current['DRb'] = info
|
Thread.current['DRb'] = info
|
||||||
$SAFE = @safe_level
|
$SAFE = @safe_level
|
||||||
perform_with_block
|
perform_with_block
|
||||||
@ -1517,7 +1523,7 @@ module DRb
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
@succ = true
|
@succ = true
|
||||||
if @msg_id == :to_ary
|
if @msg_id == :to_ary && @result.class == Array
|
||||||
@result = DRbArray.new(@result)
|
@result = DRbArray.new(@result)
|
||||||
end
|
end
|
||||||
return @succ, @result
|
return @succ, @result
|
||||||
@ -1553,7 +1559,7 @@ module DRb
|
|||||||
end
|
end
|
||||||
ary.collect(&@obj)[0]
|
ary.collect(&@obj)[0]
|
||||||
else
|
else
|
||||||
@obj.send(@msg_id, *@argv)
|
@obj.__send__(@msg_id, *@argv)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -1667,6 +1673,12 @@ module DRb
|
|||||||
#
|
#
|
||||||
# This is the URI of the current server. See #current_server.
|
# This is the URI of the current server. See #current_server.
|
||||||
def uri
|
def uri
|
||||||
|
drb = Thread.current['DRb']
|
||||||
|
client = (drb && drb['client'])
|
||||||
|
if client
|
||||||
|
uri = client.uri
|
||||||
|
return uri if uri
|
||||||
|
end
|
||||||
current_server.uri
|
current_server.uri
|
||||||
end
|
end
|
||||||
module_function :uri
|
module_function :uri
|
||||||
@ -1739,13 +1751,18 @@ module DRb
|
|||||||
end
|
end
|
||||||
module_function :install_acl
|
module_function :install_acl
|
||||||
|
|
||||||
|
@mutex = Mutex.new
|
||||||
|
def mutex
|
||||||
|
@mutex
|
||||||
|
end
|
||||||
|
module_function :mutex
|
||||||
|
|
||||||
@server = {}
|
@server = {}
|
||||||
def regist_server(server)
|
def regist_server(server)
|
||||||
@server[server.uri] = server
|
@server[server.uri] = server
|
||||||
# TODO: YARV doesn't have Thread.exclusive
|
mutex.synchronize do
|
||||||
#Thread.exclusive do
|
|
||||||
@primary_server = server unless @primary_server
|
@primary_server = server unless @primary_server
|
||||||
#end
|
end
|
||||||
end
|
end
|
||||||
module_function :regist_server
|
module_function :regist_server
|
||||||
|
|
||||||
|
@ -5,10 +5,12 @@
|
|||||||
|
|
||||||
require 'drb/drb'
|
require 'drb/drb'
|
||||||
require 'thread'
|
require 'thread'
|
||||||
|
require 'monitor'
|
||||||
|
|
||||||
module DRb
|
module DRb
|
||||||
class ExtServManager
|
class ExtServManager
|
||||||
include DRbUndumped
|
include DRbUndumped
|
||||||
|
include MonitorMixin
|
||||||
|
|
||||||
@@command = {}
|
@@command = {}
|
||||||
|
|
||||||
@ -21,6 +23,8 @@ module DRb
|
|||||||
end
|
end
|
||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
|
super()
|
||||||
|
@cond = new_cond
|
||||||
@servers = {}
|
@servers = {}
|
||||||
@waiting = []
|
@waiting = []
|
||||||
@queue = Queue.new
|
@queue = Queue.new
|
||||||
@ -30,39 +34,28 @@ module DRb
|
|||||||
attr_accessor :uri
|
attr_accessor :uri
|
||||||
|
|
||||||
def service(name)
|
def service(name)
|
||||||
while true
|
synchronize do
|
||||||
server = nil
|
while true
|
||||||
# TODO: YARV doesn't have Thread.exclusive
|
server = @servers[name]
|
||||||
#Thread.exclusive do
|
return server if server && server.alive?
|
||||||
server = @servers[name] if @servers[name]
|
invoke_service(name)
|
||||||
#end
|
@cond.wait
|
||||||
return server if server && server.alive?
|
end
|
||||||
invoke_service(name)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def regist(name, ro)
|
def regist(name, ro)
|
||||||
ary = nil
|
synchronize do
|
||||||
# TODO: YARV doesn't have Thread.exclusive
|
@servers[name] = ro
|
||||||
#Thread.exclusive do
|
@cond.signal
|
||||||
@servers[name] = ro
|
|
||||||
ary = @waiting
|
|
||||||
@waiting = []
|
|
||||||
#end
|
|
||||||
ary.each do |th|
|
|
||||||
begin
|
|
||||||
th.run
|
|
||||||
rescue ThreadError
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
self
|
self
|
||||||
end
|
end
|
||||||
|
|
||||||
def unregist(name)
|
def unregist(name)
|
||||||
# TODO: YARV doesn't have Thread.exclusive
|
synchronize do
|
||||||
#Thread.exclusive do
|
|
||||||
@servers.delete(name)
|
@servers.delete(name)
|
||||||
#end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
@ -76,22 +69,21 @@ module DRb
|
|||||||
end
|
end
|
||||||
|
|
||||||
def invoke_service(name)
|
def invoke_service(name)
|
||||||
Thread.critical = true
|
@queue.push(name)
|
||||||
@waiting.push Thread.current
|
|
||||||
@queue.push name
|
|
||||||
Thread.stop
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def invoke_service_command(name, command)
|
def invoke_service_command(name, command)
|
||||||
raise "invalid command. name: #{name}" unless command
|
raise "invalid command. name: #{name}" unless command
|
||||||
# TODO: YARV doesn't have Thread.exclusive
|
synchronize do
|
||||||
#Thread.exclusive do
|
|
||||||
return if @servers.include?(name)
|
return if @servers.include?(name)
|
||||||
@servers[name] = false
|
@servers[name] = false
|
||||||
#end
|
end
|
||||||
uri = @uri || DRb.uri
|
uri = @uri || DRb.uri
|
||||||
Process.detach(Process.spawn("#{command} #{uri} #{name}"))
|
if RUBY_PLATFORM =~ /mswin32/ && /NT/ =~ ENV["OS"]
|
||||||
true
|
system(%Q'cmd /c start "ruby" /b #{command} #{uri} #{name}')
|
||||||
|
else
|
||||||
|
system("#{command} #{uri} #{name} &")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -9,7 +9,7 @@ module DRb
|
|||||||
end
|
end
|
||||||
block_value = @block.call(*x)
|
block_value = @block.call(*x)
|
||||||
end
|
end
|
||||||
|
|
||||||
def perform_with_block
|
def perform_with_block
|
||||||
@obj.__send__(@msg_id, *@argv) do |*x|
|
@obj.__send__(@msg_id, *@argv) do |*x|
|
||||||
jump_error = nil
|
jump_error = nil
|
||||||
|
@ -6,17 +6,16 @@ module DRb
|
|||||||
|
|
||||||
def notify_observers(*arg)
|
def notify_observers(*arg)
|
||||||
if defined? @observer_state and @observer_state
|
if defined? @observer_state and @observer_state
|
||||||
if defined? @observer_peers
|
if defined? @observer_peers
|
||||||
@observer_peers.delete_if do |k, v|
|
for i in @observer_peers.dup
|
||||||
begin
|
begin
|
||||||
k.send(v, *arg)
|
i.update(*arg)
|
||||||
false
|
rescue
|
||||||
rescue
|
delete_observer(i)
|
||||||
true
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
@observer_state = false
|
||||||
@observer_state = false
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -180,7 +180,6 @@ module DRb
|
|||||||
ssl = @config.accept(soc)
|
ssl = @config.accept(soc)
|
||||||
self.class.new(uri, ssl, @config, true)
|
self.class.new(uri, ssl, @config, true)
|
||||||
rescue OpenSSL::SSL::SSLError
|
rescue OpenSSL::SSL::SSLError
|
||||||
soc.close
|
|
||||||
warn("#{__FILE__}:#{__LINE__}: warning: #{$!.message} (#{$!.class})") if @config[:verbose]
|
warn("#{__FILE__}:#{__LINE__}: warning: #{$!.message} (#{$!.class})") if @config[:verbose]
|
||||||
retry
|
retry
|
||||||
end
|
end
|
||||||
|
@ -88,7 +88,7 @@ module DRb
|
|||||||
public
|
public
|
||||||
def close
|
def close
|
||||||
return unless @socket
|
return unless @socket
|
||||||
path = @socket.path
|
path = @socket.path if @server_mode
|
||||||
@socket.close
|
@socket.close
|
||||||
File.unlink(path) if @server_mode
|
File.unlink(path) if @server_mode
|
||||||
@socket = nil
|
@socket = nil
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
|
|
||||||
__END__
|
|
||||||
require 'test/unit'
|
require 'test/unit'
|
||||||
require 'drb/drb'
|
require 'drb/drb'
|
||||||
require 'drb/extservm'
|
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|
|
%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)
|
add_service_command(nm)
|
||||||
end
|
end
|
||||||
@server = @@server = DRb::DRbServer.new(nil, @@manager, {})
|
@server = @@server = DRb::DRbServer.new('druby://localhost:0', @@manager, {})
|
||||||
@@manager.uri = @@server.uri
|
@@manager.uri = @@server.uri
|
||||||
def self.manager
|
def self.manager
|
||||||
@@manager
|
@@manager
|
||||||
|
@ -1,17 +1,5 @@
|
|||||||
require 'drbtest'
|
require 'drbtest'
|
||||||
|
|
||||||
class TestDRbCore
|
|
||||||
def test_drb
|
|
||||||
flunk("YARV doesn't support drb")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
__END__
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
__END__
|
|
||||||
|
|
||||||
class TestDRbCore < Test::Unit::TestCase
|
class TestDRbCore < Test::Unit::TestCase
|
||||||
include DRbCore
|
include DRbCore
|
||||||
end
|
end
|
||||||
|
@ -5,14 +5,8 @@ begin
|
|||||||
rescue LoadError
|
rescue LoadError
|
||||||
end
|
end
|
||||||
|
|
||||||
class TestDRbSSLCore < Test::Unit::TestCase
|
if Object.const_defined?("OpenSSL")
|
||||||
def test_message
|
|
||||||
flunk("YARV doesn't support drb")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# TODO: YARV doesn't support drb
|
|
||||||
if false # Object.const_defined?("OpenSSL")
|
|
||||||
|
|
||||||
class DRbSSLService < DRbService
|
class DRbSSLService < DRbService
|
||||||
%w(ut_drb_drbssl.rb ut_array_drbssl.rb).each do |nm|
|
%w(ut_drb_drbssl.rb ut_array_drbssl.rb).each do |nm|
|
||||||
|
@ -1,6 +1,3 @@
|
|||||||
|
|
||||||
__END__
|
|
||||||
|
|
||||||
require 'drbtest'
|
require 'drbtest'
|
||||||
|
|
||||||
begin
|
begin
|
||||||
|
Loading…
x
Reference in New Issue
Block a user