Class: ReservedNames::Win32::Handle

Inherits:
Object
  • Object
show all
Extended by:
Chef::ReservedNames::Win32::API::Process
Defined in:
lib/chef/win32/handle.rb

Constant Summary collapse

CURRENT_PROCESS_HANDLE =

See http://msdn.microsoft.com/en-us/library/windows/desktop/ms683179(v=vs.85).aspx The handle value returned by the GetCurrentProcess function is the pseudo handle (HANDLE)-1 (which is 0xFFFFFFFF)

4294967295

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(handle) ⇒ Handle

Returns a new instance of Handle


33
34
35
36
# File 'lib/chef/win32/handle.rb', line 33

def initialize(handle)
  @handle = handle
  ObjectSpace.define_finalizer(self, Handle.close_handle_finalizer(handle))
end

Instance Attribute Details

#handleObject (readonly)

Returns the value of attribute handle


38
39
40
# File 'lib/chef/win32/handle.rb', line 38

def handle
  @handle
end

Class Method Details

.close_handle(handle) ⇒ Object


47
48
49
50
51
# File 'lib/chef/win32/handle.rb', line 47

def self.close_handle(handle)
  unless CloseHandle(handle)
    Chef::ReservedNames::Win32::Error.raise!
  end
end

.close_handle_finalizer(handle) ⇒ Object


40
41
42
43
44
45
# File 'lib/chef/win32/handle.rb', line 40

def self.close_handle_finalizer(handle)
  # According to http://msdn.microsoft.com/en-us/library/windows/desktop/ms683179(v=vs.85).aspx, it is not necessary
  # to close the pseudo handle returned by the GetCurrentProcess function.  The docs also say that it doesn't hurt to call
  # CloseHandle on it. However, doing so from inside of Ruby always seems to produce an invalid handle error.
  proc { close_handle(handle) unless handle == CURRENT_PROCESS_HANDLE }
end