~ubuntu-branches/ubuntu/trusty/ruby1.9/trusty

« back to all changes in this revision

Viewing changes to lib/drb/drb.rb

  • Committer: Bazaar Package Importer
  • Author(s): Stephan Hermann
  • Date: 2008-01-24 11:42:29 UTC
  • mfrom: (1.1.9 upstream)
  • Revision ID: james.westby@ubuntu.com-20080124114229-jw2f87rdxlq6gp11
Tags: 1.9.0.0-2ubuntu1
* Merge from debian unstable, remaining changes:
  - Robustify check for target_os, fixing build failure on lpia.

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
# Copyright (c) 1999-2003 Masatoshi SEKI.  You can redistribute it and/or
7
7
# modify it under the same terms as Ruby.
8
8
#
9
 
# Author: Masatoshi SEKI
 
9
# Author:: Masatoshi SEKI
10
10
#
11
 
# Documentation: William Webber (william@williamwebber.com)
 
11
# Documentation:: William Webber (william@williamwebber.com)
12
12
#
13
13
# == Overview
14
14
#
578
578
      end
579
579
      raise(DRbConnError, 'connection closed') if str.nil?
580
580
      raise(DRbConnError, 'premature marshal format(can\'t read)') if str.size < sz
581
 
      # TODO: YARV doesn't have Thread.exclusive
582
 
      #Thread.exclusive do
 
581
      DRb.mutex.synchronize do
583
582
        begin
584
583
          save = Thread.current[:drb_untaint]
585
584
          Thread.current[:drb_untaint] = []
592
591
          end
593
592
          Thread.current[:drb_untaint] = save
594
593
        end
595
 
      #end
 
594
      end
596
595
    end
597
596
 
598
597
    def send_request(stream, ref, msg_id, arg, b) # :nodoc:
833
832
      begin
834
833
        Socket::gethostbyname(host)[0]
835
834
      rescue
836
 
        host
 
835
        'localhost'
837
836
      end
838
837
    end
839
838
 
859
858
    def self.open_server(uri, config)
860
859
      uri = 'druby://:0' unless uri
861
860
      host, port, opt = parse_uri(uri)
 
861
      config = {:tcp_original_host => host}.update(config)
862
862
      if host.size == 0
863
863
        host = getservername
864
864
        soc = open_server_inaddr_any(host, port)
866
866
        soc = TCPServer.open(host, port)
867
867
      end
868
868
      port = soc.addr[1] if port == 0
 
869
      config[:tcp_port] = port
869
870
      uri = "druby://#{host}:#{port}"
870
871
      self.new(uri, soc, config)
871
872
    end
946
947
        break if (@acl ? @acl.allow_socket?(s) : true) 
947
948
        s.close
948
949
      end
949
 
      self.class.new(nil, s, @config)
 
950
      if @config[:tcp_original_host].to_s.size == 0
 
951
        uri = "druby://#{s.addr[3]}:#{@config[:tcp_port]}"
 
952
      else
 
953
        uri = @uri
 
954
      end
 
955
      self.class.new(uri, s, @config)
950
956
    end
951
957
 
952
958
    # Check to see if this connection is alive.
973
979
    def initialize(option)
974
980
      @option = option.to_s
975
981
    end
976
 
    attr_reader :option
 
982
    attr :option
977
983
    def to_s; @option; end
978
984
    
979
985
    def ==(other)
1497
1503
        if $SAFE < @safe_level
1498
1504
          info = Thread.current['DRb']
1499
1505
          if @block
1500
 
            @result = Thread.new { 
 
1506
            @result = Thread.new {
1501
1507
              Thread.current['DRb'] = info
1502
1508
              $SAFE = @safe_level
1503
1509
              perform_with_block
1517
1523
          end
1518
1524
        end
1519
1525
        @succ = true
1520
 
        if @msg_id == :to_ary
 
1526
        if @msg_id == :to_ary && @result.class == Array
1521
1527
          @result = DRbArray.new(@result) 
1522
1528
        end
1523
1529
        return @succ, @result
1553
1559
          end
1554
1560
          ary.collect(&@obj)[0]
1555
1561
        else
1556
 
          @obj.send!(@msg_id, *@argv)
 
1562
          @obj.__send__(@msg_id, *@argv)
1557
1563
        end
1558
1564
      end
1559
1565
 
1667
1673
  #
1668
1674
  # This is the URI of the current server.  See #current_server.
1669
1675
  def uri
 
1676
    drb = Thread.current['DRb']
 
1677
    client = (drb && drb['client'])
 
1678
    if client
 
1679
      uri = client.uri
 
1680
      return uri if uri
 
1681
    end
1670
1682
    current_server.uri
1671
1683
  end
1672
1684
  module_function :uri
1739
1751
  end
1740
1752
  module_function :install_acl
1741
1753
 
 
1754
  @mutex = Mutex.new
 
1755
  def mutex
 
1756
    @mutex
 
1757
  end
 
1758
  module_function :mutex
 
1759
 
1742
1760
  @server = {}
1743
1761
  def regist_server(server)
1744
1762
    @server[server.uri] = server
1745
 
    # TODO: YARV doesn't have Thread.exclusive
1746
 
    #Thread.exclusive do
 
1763
    mutex.synchronize do
1747
1764
      @primary_server = server unless @primary_server
1748
 
    #end
 
1765
    end
1749
1766
  end
1750
1767
  module_function :regist_server
1751
1768