Class: DRb::DRbMessage

Inherits:
Object
  • Object
show all
Defined in:
lib/VMwareWebService/DMiqVimSync.rb,
lib/VMwareWebService/MiqVimDrbDebug.rb

Overview

module DMiqVimSync

Constant Summary collapse

EXPECTED_MARSHAL_VERSION =
[Marshal::MAJOR_VERSION, Marshal::MINOR_VERSION].freeze

Instance Method Summary collapse

Instance Method Details

#dump(obj, error = false) ⇒ Object

This is the DRB half of the dupObj locking scheme. If we get a MiqDrbReturn object, we marshal the object it wraps and release the lock.



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/VMwareWebService/DMiqVimSync.rb', line 30

def dump(obj, error = false)
  #
  # Place a temp hold on the object until the client registers it.
  #
  obj.holdBrokerObj if obj.respond_to?(:holdBrokerObj)

  obj_to_dump = obj.kind_of?(MiqDrbReturn) ? obj.obj : obj

  result = dump_original(obj_to_dump, error)

  valid = true
  size = result[0..3].unpack("N")[0]
  if @load_limit < size
    $vim_log.error("DRb packet size too large: #{size}")
    valid = false
  end

  marshal_version = result[4, 2].unpack("C2")
  if marshal_version != EXPECTED_MARSHAL_VERSION
    $vim_log.error("Marshal version mismatch: expected: #{EXPECTED_MARSHAL_VERSION} got: #{marshal_version}")
    valid = false
  end

  unless valid
    $vim_log.error("object: #{obj.inspect}")
    $vim_log.error("buffer:\n#{result[0, 1024].hex_dump}")
    $vim_log.error("caller:\n#{caller.join("\n")}")
  end

  return result unless obj.kind_of?(MiqDrbReturn)

  begin
    return result
  ensure
    if obj.lock && obj.lock.sync_locked?
      $vim_log.debug "DRb::DRbMessage.dump: UNLOCKING [#{Thread.current.object_id}] <#{obj.obj.object_id}>" if $vim_log.debug?
      obj.lock.sync_unlock
    end
  end
end

#dump_originalObject



24
# File 'lib/VMwareWebService/DMiqVimSync.rb', line 24

alias_method :dump_original, :dump

#load(soc) ⇒ Object

:nodoc:

Raises:

  • (DRbConnError)


3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/VMwareWebService/MiqVimDrbDebug.rb', line 3

def load(soc)  # :nodoc:
  begin
    sz = soc.read(4)        # sizeof (N)
  rescue
    raise(DRbConnError, $!.message, $!.backtrace)
  end
  raise(DRbConnError, 'connection closed') if sz.nil?
  raise(DRbConnError, 'premature header') if sz.size < 4
  sz = sz.unpack('N')[0]
  raise(DRbConnError, "too large packet #{sz}") if @load_limit < sz
  begin
    str = soc.read(sz)
  rescue
    raise(DRbConnError, $!.message, $!.backtrace)
  end
  raise(DRbConnError, 'connection closed') if str.nil?
  raise(DRbConnError, 'premature marshal format(can\'t read)') if str.size < sz
  DRb.mutex.synchronize do
    begin
      save = Thread.current[:drb_untaint]
      Thread.current[:drb_untaint] = []
      Marshal::load(str)
    rescue NameError, ArgumentError
      DRbUnknown.new($!, str)
    rescue TypeError => err
      raise TypeError, "#{err}\n#{str.hex_dump}"
    ensure
      Thread.current[:drb_untaint].each do |x|
        x.untaint
      end
      Thread.current[:drb_untaint] = save
    end
  end
end