summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/drb/acl.rb2
-rw-r--r--lib/drb/drb.rb45
-rw-r--r--lib/drb/extservm.rb56
-rw-r--r--lib/drb/invokemethod.rb2
-rw-r--r--lib/drb/observer.rb21
-rw-r--r--lib/drb/ssl.rb1
-rw-r--r--lib/drb/unix.rb2
7 files changed, 69 insertions, 60 deletions
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